Illustrate it
summing the series 2+4+6+......to n terms using
(i) while loop (ii) do-while loop
Answer Posted / raju kalyadapu
i). using while-loop
int main()
{
int sum=0,n,i=0,j=2;
printf("Enter 2+4+6+...n upto nth term:");
scanf("%d",&n);
while(i++<n)
{
j=2*i;
sum=sum+i*2;
}
getch();
return 0;
}
ii). using do-while loop
int main()
{
int sum=0,n,i=0,j=2;
printf("Enter 2+4+6+...n upto nth term:");
scanf("%d",&n);
do
{
j=2*i;
sum=sum+i*2;
} while(i++<n);
printf("
Sum of the Series 2+4+6+----%d is:%d",j,sum);
}
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is wrong in this statement?
while initialization of array why we use a[][2] why not a[2][]...?
What does d mean?
what is bit rate & baud rate? plz give wave forms
What is malloc() function?
i have a written test for microland please give me test pattern
Explain how to reverse singly link list.
What is difference between union All statement and Union?
What is #line?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
What is typedef example?
Explain how can I write functions that take a variable number of arguments?
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
How does struct work in c?
What is masking?