
ممكن تساعدوني انا حليت البرنامج بس مو راضي يطلع الحل صح
ابغا اعرف الخطا فين
Write a program that reads integers from the user until she enters Zero (0), then reverse the elements
Finally, print the array values after reversing.
Using the following functions implement the program:
Int read(int arr[ ]);
// to read integers from the user until Zero is entered then returns the //No. of elements.
Void reverse( int arr[ ], int n_elem);
//to change elements position in the array.
Void print( int arr[ ], int n_elem);
// prints the array elements after reversing .
ذا السؤال
وجوابي:
#include<iostream.h>
#include<conio.h>
int read(int arr[]);
void reverse(int arr[],int);
void print(int arr[],int);
void main()
{
int x;
int arr[20];
x=read(arr);
reverse(arr,x);
print(arr,x);
getch();
}
int read(int arr[])
{
int count=0;
for(int i=0;i<20;i++)
{
cin>>arr[i];
if(arr[i]!=0)
count++;
else
break;
}
return count;
}
void reverse(int arr[],int n)
{
int temp;
for(int i=0,j=n-1;i<n/2;i++,j--)
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
void print(int arr[],int n)
{
for(int i=0;i<n;i++)
cout<<arr[i];
}