السلام عليكم
هذا السؤال
Write a C-Program that swaps the elements of 1-D array (10 elements) :
Example:
If the given array is:
5 8 9 2 3 1 11 17 43 6
The new array will be:
6 43 17 11 1 3 2 9 8 5
Your program should consist of the following functions:
1. Function READ to read the elements of the array
2. Function Display to print the elements of the new array
3. Function SWAP to swap the elements of the array
4. main function to call the previous functions
Note: in swap function, do not use an intermediate array for swapping, i.e. do not
declare a new array and fill it with the elements of the original array starting from the
last element. The swap operation should be done on one array
في البداية حليت السؤال بدون Function
#include<stdio.h>
main( )
{
int i,n,j;
float arr[5], arr_new[5] ;
int temp;
for (i=0; i<5; ++i)
{
printf ("Enter the %dth element of array :", i);
scanf ( "%f", &arr );
}
for (i=0; i<5; ++i)
{
printf ("the value of element #%d is %f \n", i,arr);
}
for( i = 0, j = 4; i<5; i++,j--)
{
temp = arr;
arr = arr_new[j];
arr_new[j] = temp;
}
for (i=0; i<5; ++i)
{
printf ("the new array value of element #%d is %f \n", i,arr_new);
}
}بس لما حاولت احله بال fuction
ما عرفت وهذا اللي قدرت عليه
#include<stdio.h>
void read(float arr[],int n)
{
int i;
for (i=0; i<n; ++i)
{
printf ("Enter the %dth element of array :", i);
scanf ( "%f", &arr );
}
void swp(float arr[],float arr_new[],int n)
{
int i,j, temp;
for( i = 0, j = n-1; i<n; i++,j--)
{
temp = arr;
arr = arr_new[j];
arr_new[j] = temp;
}
}
void display(float arr_new[])
{
int i;
for (i=0; i<n; ++i)
{
printf ("the new array value of element #%d is %f \n", i,arr_new);
}
}
void main()
{
float a[],b[], c[];
int m;
printf ("Enter the size of array :");
scanf("%d",&m);
read(a,m);
swap(a,b,m);
display(c);
}
ارجو المساعدة
لازم اسلم لحل بكره