Calculate Sum of Odd numbers upto n-terms


#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,sum=0;
clrscr();
printf("enter the end term of series");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
         if(i%2==0)
         {
           sum=sum+0;
          }
         else
         {
           sum=sum+i;
          }
}
printf("\nthe sum of the series is %d",sum);
getch();
return 0;
}

0 comments:

Post a Comment