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 does do in c?
Describe the steps to insert data into a singly linked list.
Can variables be declared anywhere in c?
Difference between goto, long jmp() and setjmp()?
write a program to copy the string using switch case?
Why void is used in c?
What are the uses of null pointers?
Does * p ++ increment p or what it points to?
What are the types of functions in c?
What is difference between array and pointer in c?
Why isn't it being handled properly?
What is a loop?
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
What do you mean by command line argument?
What is c language used for?