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
to find the closest pair
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
What does main () mean in c?
What is the difference between array_name and &array_name?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What is a lookup table in c?
Here is a neat trick for checking whether two strings are equal
what is reason of your company position's in india no. 1.
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
Can you tell me how to check whether a linked list is circular?
Why is c called a mid-level programming language?
What is #line in c?
Are the outer parentheses in return statements really optional?
What is the difference between int main and void main in c?
Explain the advantages of using macro in c language?