-->

Facebook

Jasper Roberts - Blog

Tuesday, October 7, 2014

Write a program to find sum of first N odd numbers.

#include<stdio.h>
#include<conio.h>

void main()
{
     int i, num, odd=0, even=0;
clrscr();
    
printf(“Enter the number:”);
scanf(“%d”,&num);

for(i=1;i<=num,i++)

{                                          
     if(i%2==0)
     {
even = even+i;
          }
          ilse
          {
odd = odd + i;
          }
}
printf(“\n Sum of all odd numbers: %d”,odd);
getch();
}

Output:
Enter the number: 5

Sum of all odd numbers: 9



DOWNLOAD          DOWNLOAD
download nested if else statement           download nested if else statement

No comments:

Post a Comment