Help. i dont know how to solve this loop program...using turbo c?
using turbo c
the output should be like this
Loop Program
--------------------
enter 1st integer:
enter 2nd integer:
enter 3rd integer:
enter 4th integer:
enter 5th integer:
enter 6th integer:
enter 7th integer:
enter 8th integer:
enter 9th integer:
enter 10th integer:
=====RESULTS======
sum=
average=
smallest=
largest=
no. of odd=
no. of even=
thank you... please consider this as a challenge.. even though im just
a beginner.
:Dty.
Help turbo c challeng or maybe a problem.......?
"DO YOUR WORK YOURSELF, THE SUCCESS IS WILL KNOCK YOUR DOOR"
SOME HINTS:
USE AN ARRAY OF INTEGERS TO STORE THE NUMBER ENTERED BY THE USER.
RUN A LOOP TO ENTER ALL 10 NUMBERS WITH STATEMENT
for(i = 1; i %26lt;= 10; i++)
{
if(I == 1)
printf("\n Enter %dst number:",i);
else if(i == 2)
printf("\n Enter %dnd number:",i);
else if(i == 3)
printf("\n Enter %drd number:",i);
else
printf("\n Enter %dth number:",i);
scanf("%d",%26amp;array[i]);// array of integers.
}
// Now calculate the desired result from that array.
Reply:So where is the code? You only showed the output! No, I will not do your homework for you!
Reply:What exactly is your question? Just use an array of ten integers and loop...
Reply:the part where your program request to input 10 integers can be placed inside a for loop you will need an array of int that will hold the 10 elements to get all 10. Here is a partial code
for (i=0; i%26lt;10; i++) {
printf("Enter number: ");
scanf("%d",%26amp;tmp);
array[i] = tmp;
}
to get the sum all you need is to accumulate the number. Here is a hint: you will use the following statement inside a loop
total = total + array[i];
or
total = total + tmp;
the average part is simply dividing the total by 10
for the smallest and largest you will need to sort the array and get the first and last element of the array after sorting
for count of odd and even all you need to do is to test if it is even or odd. Here is a partial code
if (tmp % 2 == 0) {
evenCount = evenCount + 1;
} else {
oddCount = oddCount + 1;
}
daylily
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment