You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
346 B
C

/*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