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

Explain the use of bit fieild.

918


Write a program in c to replace any vowel in a string with z?

885


Is fortran still used in 2018?

800


int i=10; printf("%d %d %d", i, i=20, i);

1300


What does 4d mean in c?

1228


Is there any data type in c with variable size?

856


Explain c preprocessor?

875


can anyone suggest some site name..where i can get some good data structure puzzles???

1852


What is the difference between %d and %i?

822


Explain is it valid to address one element beyond the end of an array?

955


What is c language and why we use it?

810


Write a program for Overriding.

915


Why pointers are used?

832


Describe the difference between = and == symbols in c programming?

1017


What are terms in math?

797