Thursday, July 9, 2009

Turbo c "ARRAY" statement?

Write a program using one dimensional array that calculates the sum and average of the five input values from the keyboard and prints the calculated sum and average.





This is what i've done the problem is i dont know how to combo it with a loop that will say "would you like you try for another one answer yes or no" can you help me..thanks in advance.





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


main()


{


int i, sum, n[5];


float ave;


sum = 0;


clrscr();


prinf(“\n Enter five numbers: \n”);


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


{


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


}


ave=sum/5;


printf(“\n The sum is : %d “, sum);


printf(“\n The ave is : %0.2f”, ave);


getch();


}

Turbo c "ARRAY" statement?
Not sure what you want to achieve, exactly, but I'm assuming that you need to invite the user to go for another set of 5 numbers?





This being the case, you need to make a while loop that contains the code that is to be repeated : i.e. everything except the initialization of the program itself.





The while loop should test for the user entering 'yes' or 'no' using scanf to retrieve their answer, and probably converting from lower to upper case, just in case they're feeling sneaky, and type in 'YeS', for example. Either that, or use stricmp from the string.h library (it is the case insensitive version of strcmp).





I've put a few pointers to some relevant articles for you, in the sources below.





Have fun, and good luck!


No comments:

Post a Comment