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 |
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
hi , please send me NIC written test papers to sbabavalli@gmail.com
What are the types of i/o functions?
What is restrict keyword in c?
WAP to accept rollno,course name & marks of a student & display grade if total marks is above 200?
Find occurence of a character in a sting.
What would the following code segment printint k = 8;docout << "k = " << k << " ";while k++ < 5; a) 13 b) 5 c) 8 d) pointers
What is #define used for in c?
What are the key features in c programming language?
What is character constants?
Why ordinary variable store only one value
Explain what’s a signal? Explain what do I use signals for?