Saturday, June 13, 2015

series(1+3+5+7+9+...........+n)

#include<stdio.h>
///odd number series:
int main ()
{
    int i,num,sum=0;
    printf("Please enter any number:");
    scanf("%d",&num);

    for(i=1;i<=num;i=i+2)
    {
      printf("%d ",i);
      sum=sum+i;
    }

    printf("\nThe sum of the odd number series is:%d",sum);

    return 0;
}

No comments:

Post a Comment