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
What is methods in c?
Is there a way to compare two structure variables?
Explain how can I open a file so that other programs can update it at the same time?
Why do we use static in c?
What is modifier & how many types of modifiers available in c?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
What is calloc() function?
How do I convert a string to all upper or lower case?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
How to define structures? ·
differentiate built-in functions and user – defined functions.
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
If errno contains a nonzero number, is there an error?
how we can make 3d venturing graphics on outer interface
What does 2n 4c mean?