Write a loop that calculate sum of the n elements of the series 5m Dec2008

By | April 16, 2016

Write a loop that calculate sum of the n elements of the series 5m Dec2008

Write a loop that calculate sum of the n elements of the series: 5

1+ 7 +13 +19 + 25 + ā€¦ā€¦.

Write the loop in 3 different ways:

(i) using while loop

(ii) using do-while loop

 

#include<stdio.h>
void main()
{
int i,X,SUM=0;
clrscr();
printf(“\nGENERATED SERIES IS :- \n”);
i=1;
while(i<11)
{
X=i+(5*(i-1));
printf(” %d “,X);
SUM=SUM+X;
i++;
}
printf(“\n\nSUM OF GENERATED SERIES IS :- \t %d \n”,SUM);
getch();
}

code:-

#include<stdio.h>
void main()
{
int i,X,SUM=0;
clrscr();
printf("\nGENERATED SERIES IS :- \n");
i=1;
while(i<11)
{
X=i+(5*(i-1));
printf(" %d ",X);
SUM=SUM+X;
i++;
}
printf("\n\nSUM OF GENERATED SERIES IS :- \t %d \n",SUM);
getch();
}

Screenshot:-

C_program_Series01

 

C_program_Series02

C_program_Series03

C_program_Series_Output