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 heap and queue.
Explain the term printf() and scanf() used in c language?
what is the format specifier for printing a pointer value?
What does %c mean in c?
Why main is not a keyword in c?
What are the types of data types and explain?
Differentiate between a structure and a union.
What is NULL pointer?
What does c mean in basketball?
What is bash c?
State two uses of pointers in C?
Can a program have two main functions?
Why & is used in c?
Why do we use & in c?
What are header files and explain what are its uses in c programming?