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


Please Help Members By Posting Answers For Below Questions

What is wrong in this statement?

822


while initialization of array why we use a[][2] why not a[2][]...?

2105


What does d mean?

794


what is bit rate & baud rate? plz give wave forms

1729


What is malloc() function?

847


i have a written test for microland please give me test pattern

2484


Explain how to reverse singly link list.

847


What is difference between union All statement and Union?

883


What is #line?

830


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1732


What is typedef example?

856


Explain how can I write functions that take a variable number of arguments?

814


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

843


How does struct work in c?

826


What is masking?

912