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
Explain the use of bit fieild.
Write a program in c to replace any vowel in a string with z?
Is fortran still used in 2018?
int i=10; printf("%d %d %d", i, i=20, i);
What does 4d mean in c?
Is there any data type in c with variable size?
Explain c preprocessor?
can anyone suggest some site name..where i can get some good data structure puzzles???
What is the difference between %d and %i?
Explain is it valid to address one element beyond the end of an array?
What is c language and why we use it?
Write a program for Overriding.
Why pointers are used?
Describe the difference between = and == symbols in c programming?
What are terms in math?