recent

Program to display series and find sum of 1+3+5+……..+n

Write a Program to display series and find sum of 1+3+5+……..+n:-

#include<stdio.h>
void main()
{
int n,i,sum=0;
printf("Enter any no: \n");
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);
}
Powered by Blogger.