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


Please Help Members By Posting Answers For Below Questions

What is methods in c?

847


Is there a way to compare two structure variables?

878


Explain how can I open a file so that other programs can update it at the same time?

890


Why do we use static in c?

852


What is modifier & how many types of modifiers available in c?

835


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?

2303


What is calloc() function?

880


How do I convert a string to all upper or lower case?

891


what is a NULL Pointer? Whether it is same as an uninitialized pointer?

1051


‎How to define structures? · ‎

856


differentiate built-in functions and user – defined functions.

888


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)

2110


If errno contains a nonzero number, is there an error?

1067


how we can make 3d venturing graphics on outer interface

4408


What does 2n 4c mean?

998