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

find largest of 3 no

8 Answers  


What is header file in c?

0 Answers  


write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language

18 Answers   IT Park, TCS,


What is difference between function overloading and operator overloading?

0 Answers  


Write a C++ program to give the number of days in each month according to what the user entered. example: the user enters June the program must count number of days from January up to June

0 Answers  






How do I read the arrow keys? What about function keys?

0 Answers  


What is #include called?

0 Answers  


Why c is known as a mother language?

0 Answers  


what is a function pointer and how all to declare ,define and implement it ???

4 Answers   Honeywell,


What is anagram in c?

0 Answers  


What is a const pointer, and how does it differ from a pointer to a const?

2 Answers  


Concat two string with most overlapped substring has to removeĀ  "abcd"+ "cdef" = "abcdef

6 Answers  


Categories