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 the difference between procedural and functional programming?
What is wild pointer in c?
What is a nested loop?
What does c in a circle mean?
What is a structure in c language. how to initialise a structure in c?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Explain the difference between call by value and call by reference in c language?
Which is better between malloc and calloc?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
Difference between exit() and _exit() function?
Explain the priority queues?
What is linear search?
Why ca not I do something like this?
what is recursion in C
Can you please explain the difference between malloc() and calloc() function?