Friday, July 31, 2009

Write a C program to calculate and display the sum of the 2 largest nos in an array of 10 nos?

write a C program to calculate and display the sum of the 2 largest nos in an array of 10 nos and to also find the sum of the 2 smallest, and sort the numbers in ascending order.

Write a C program to calculate and display the sum of the 2 largest nos in an array of 10 nos?
I will not write the code for you here, but its a simple thing to do.





The program is all about sorting, and as the array is pretty small, you can put almost any algorithm to work. The simpler the better.





Summing up the numbers is the last thing.
Reply:#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


int i,n[10],t;


printf("Enter the list of 10 nos==%26gt;");


for(i=0;i%26lt;10;i++)


scanf("%d",%26amp;n[i]);


for (i=0;i%26lt;10;i++)


{


for (j=0;j%26lt;10;j++)


{


if(n[i]%26gt;n[j])


{


t=n[i];


n[i]=n[j];


n[j]=t;


}


}


}


suml=n[0]+n[1];


sums=n[8]+n[9];


printf("suml,sums",%26amp;suml%26amp;sums);


}





i dont remember the exact syntax but somehow it will sort ascending or descending order


No comments:

Post a Comment