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
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 |
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 |
find largest of 3 no
What is header file in c?
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
What is difference between function overloading and operator overloading?
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
How do I read the arrow keys? What about function keys?
What is #include called?
Why c is known as a mother language?
what is a function pointer and how all to declare ,define and implement it ???
What is anagram in c?
What is a const pointer, and how does it differ from a pointer to a const?
Concat two string with most overlapped substring has to removeĀ "abcd"+ "cdef" = "abcdef