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
how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?
what do you mean by inline function in C?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
Explain the difference between structs and unions in c?
What is the best way to comment out a section of code that contains comments?
Explain what are bus errors, memory faults, and core dumps?
Why doesn't C support function overloading?
How can you convert integers to binary or hexadecimal?
Why c language?
What are header files? What are their uses?
What is a far pointer in c?
What is getche() function?
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
Is flag a keyword in c?
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..