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

to find the closest pair

2107


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1693


What does main () mean in c?

893


What is the difference between array_name and &array_name?

1035


Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?

912


What is a lookup table in c?

863


Here is a neat trick for checking whether two strings are equal

824


what is reason of your company position's in india no. 1.

2008


WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER

1659


Can you tell me how to check whether a linked list is circular?

1120


Why is c called a mid-level programming language?

994


What is #line in c?

797


Are the outer parentheses in return statements really optional?

880


What is the difference between int main and void main in c?

866


Explain the advantages of using macro in c language?

796