- تاريخ التسجيل
- 3 يوليو 2007
- المشاركات
- 4,299
- المجموعة
- أنثى
- الدفعة الدراسية
- معلومة خاصة
- الكلية
- كلية العلوم
- التخصص
- .
بغيت مساعدة في هالاسايمنت
Part (A)
Write a function named FirstOdd that takes as parameters a pointer to an array of int, and the array size. The function should return a pointer that point to the first occurrence of odd number in the array. If no odd numbers are found, the function should return NULL. The prototype of the function is:
int * FirstOdd (int arr[], int size);
Part (B)
Write a main function to include the following
1. Write a statement(s) to declare a dynamic array of 10 integers named Arr.
2. Write a statement(s) to declare a pointer of type int named Ptr.
3. Write a statement(s) to prompt the user to enter the data of Arr.
4. Write a statement(s) to call the function FirstOdd (Arr, 10); and store the returned value in Ptr.
5. Write a statement(s) to print the value pointed by Ptr if Ptr is not NULL; otherwise output an appropriate message.
هذا حلي اليه
وطلعت عندي الشاشة السودا لكن بعد فيه ايرور في الـ null
وهذا هو الح ـــل
#include <iostream>
using namespace std;
int FirstOdd (int arr[], int size){
for (int i=0; i<size; i++)
{if(arr/2==1)
return arr;
break;
}
return NULL;
}
int main ()
{
int Arr[10];
int *Ptr;
cout<<"Enter data";
for (int i=0; i<10; i++)
cin>>Arr;
int F = FirstOdd (Arr, 10);
if (F == NULL)
cout<<"Not found odd number";
else
cout<<F;
return 0;
}
Write a statement(s) to call the function FirstOdd (Arr, 10); and store the returned value in Ptr.
يبون تنادين الفنكشن والقيمة تخزنينها في الفاريبل اللي عرفتينه كبوينتر
لاحظي الفنكشن في تعريفها في السؤال ترجع لج بوينتر
داخل الفنكشن , لازم تقولين له ريترن بوينتر وليس القيمة اللي داخل الارري
في المين لما ترجع لج الفنكشن قيمة البوينتر , انتي عقب بتقولين له اطبع لي هالقيمة هذي
