Illustrate it
summing the series 2+4+6+......to n terms using
(i) while loop (ii) do-while loop
Answer Posted / srujitha
// while loop
int main()
{
int n = 3,sum = 0,i = 2, count = 0;
while(n > count)
{
sum = sum + i;
i = i+2;
count++;
}
printf("SUM = %d ",sum);
}
// do while loop
int main()
{
int n = 3,sum = 0,i = 2, count = 0;
do
{
sum = sum + i;
i = i+2;
count++;
}
while(n > count);
printf("SUM = %d ",sum);
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
In a switch statement, explain what will happen if a break statement is omitted?
What is huge pointer in c?
What is uint8 in c?
Why c is a procedural language?
Does c have function or method?
What are different storage class specifiers in c?
Why is c called "mother" language?
Why do some versions of toupper act strangely if given an upper-case letter?
What is the purpose of main() function?
What is a structural principle?
What is the difference between declaring a variable by constant keyword and #define ing that variable?
What do you mean by invalid pointer arithmetic?
which type of aspect you want from the student.
What is meant by errors and debugging?
A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile