Illustrate it 
 summing the series 2+4+6+......to n terms using 
(i) while loop (ii) do-while loop

Answers were Sorted based on User's Feedback



 Illustrate it   summing the series 2+4+6+......to n terms using  (i) while lo..

Answer / 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

 Illustrate it   summing the series 2+4+6+......to n terms using  (i) while lo..

Answer / srujitha

// while loop
int main()
{
int n = 3,sum = 0,i = 2, count = 0;

while(n > count)
{
sum = sum + i;
i = i+2;
count++;
}
printf("SUM = %d ",sum);
}

// do while loop

int main()
{
int n = 3,sum = 0,i = 2, count = 0;


do
{
sum = sum + i;
i = i+2;
count++;
}
while(n > count);
printf("SUM = %d ",sum);
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Can we initialize extern variable in c?

0 Answers  


the output will be #include<stdio.h> int main () { int i; i = 9/2; printf("%i",i); return 0; }

4 Answers   CMC, TCS,


What is sizeof array in c?

0 Answers  


int i=10; printf("%d %d %d", i, i=20, i);

0 Answers  


Why doesnt the call scanf work?

0 Answers  






What is a loop?

0 Answers  


What are the storage classes in C?

0 Answers  


How the C program can be compiled?

11 Answers   HP,


Just came across this question, felt worth sharing, so here it is I want you to make a C/C++ program that for any positive integer n will print all the positive integers from 1 up to it and then back again! Let's say n=5 I want the program to print: 1 2 3 4 5 4 3 2 1. Too easy you say? Okay then... You can ONLY USE: 1 for loop 1 printf/cout statement 2 integers( i and n) and as many operations you want. NO if statements, NO ternary operators, NO tables, NO pointers, NO functions!

1 Answers  


write a function to swap an array a[5] elements like a[0] as a[5],a[1] as a[4],....a[5] as a[0].without using more than one loop and use one array not to use temp array?

1 Answers   Zensar,


Why do u use # before include in a C Progam?

9 Answers   IBM,


What are the types of i/o functions?

0 Answers  


Categories