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 does do in c?

696


Describe the steps to insert data into a singly linked list.

721


Can variables be declared anywhere in c?

717


Difference between goto, long jmp() and setjmp()?

822


write a program to copy the string using switch case?

2483






Why void is used in c?

666


What are the uses of null pointers?

675


Does * p ++ increment p or what it points to?

731


What are the types of functions in c?

657


What is difference between array and pointer in c?

629


Why isn't it being handled properly?

731


What is a loop?

667


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

845


What do you mean by command line argument?

722


What is c language used for?

642