programming-examples/c/Series_Programs/C Program to find Series and find sum of 1+3+5+...c

19 lines
346 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*Series and find sum of 1+3+5+...+n */
#include<stdio.h>
void main()
{
int n,i,sum=0;
printf("Enter any no: ");
scanf("%d",&n);
for(i=1; i<n; i=i+2)
{
printf("%d+",i);
sum=sum+i;
}
printf("%d",n);
printf("\nsum=%d",sum+n);
}
Output:
Enter any no: 7
1+3+5+7
Sum=16