A C language program

A C language program
Write a complete program to do the following specification Using Functions :
1. Pickup 10 numbers and store it in an array using function fillArray.
2. Print the content of array with the message “Array not sorted” using printArray function.
3. Copy array a into array b using copyArray(a,b,10) function.
4. Sort array b in ascending order using sortArray(b,10) function.
5. Print array b with message “sorted array” using printArray
6. Pickup 10 numbers and store it in array c.
7. Find largest, smallest, and median values of array c and print them.
8. Print largest number of two arrays a,c and specify which array contains it.
9. Your program should ask for a number and print “YES” if the number is in array a, otherwise print “not found”
bluetooth_ayang 1年前 已收到3个回答 举报

因春而感动 幼苗

共回答了23个问题采纳率:95.7% 举报

#include
#include
#include
#include
#include
void fillRandom(int * x , int n);
void printArray(int * x, int n, int k);
void doSort(int ** x, int n);
void copyArray (int * a,int * b,int n);
int main ()
{
int a[10];int i;int b[10];int c[10];int rn=0;
srand(time(NULL));

fillRandom(a,10);
printf("This is Array a:n");
printArray(a,10,10);
printf("Array not sortedn");
copyArray(a,b,10);
printf("nThis is Array b(copy from Array a):n");
printArray(b,10,10);
doSort(b,10);
printf("nArray b is sorted now:n");
for(i=0 ; i< 10 ; i++)
{ printf("%d ", b[i]);
}
fillRandom(c,10);
printf("nnThis is Array c:n");
printArray(c,10,10);


doSort(c,10);

printf("nThe Largest in Array c is: %dn",c[0]);


printf("The smallest in Array c is: %dn",c[9]);
printf("The middle values of Array c are %d and %dn",c[5],c[4]);

doSort(a,10);

printf("n%d is the largest in Array an",a[0]);
printf("%d is the largest in Array cn",c[0]);


printf("nenter a number to see if it is in Array a:");scanf("%d",&rn);
if ((rn==a[0])||(rn==a[1])||(rn==a[2])||(rn==a[3])||(rn==a[4])||(rn==a[5])||(rn==a[6])||(rn==a[7])||(rn==a[8])||(rn==a[9]))
printf("Yes!n");
else
printf("Not foundn");
getch ();

return 0;
}
void fillRandom(int * x , int n)
{
int i=0;
for(i=0; i < n; i++)
x[i]= (rand()%(99-10+1) + 10);
}

void printArray(int * x, int n, int k)
{ int i;
for(i=0; i < n ; i++)
{ printf("%d ",x[i]);
if((i+1)%k==0)
printf("n");
}
}

void copyArray (int * a,int * b, int n)
{ int i;
for (i=0; i

1年前

7

只有人治没有ii 幼苗

共回答了23个问题采纳率:91.3% 举报

#include
#include
int i;
main()
{
void copyArray(int *,int *,int),sortArray(int *,int),
printArray(int *,int);
int a[10],b[10],c[10],d[10],l,guess,flag=0;
char s;
printf("Enter array a:");
for(i=0;i

1年前

1

左左左a 幼苗

共回答了20个问题采纳率:85% 举报

什么啊?

1年前

0
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 18 q. 0.031 s. - webmaster@yulucn.com