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 d'n in c?
"%u" unsigned integer print the a) address of variable b) value of variable c) name of a variable d) none of the above
What are the advantages of using linked list for tree construction?
In C, What is the #line used for?
What is array within structure?
What is pragma c?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What is pointer in c?
What is file in c language?
What does stand for?
What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }
What is the difference between array and structure in c?
What Is The Difference Between Null And Void Pointer?
Why is c still so popular?