PROGRAM TO PRINT SUM OF FIRST N ODD NATURAL NUMBERS

/*PROGRAM TO PRINT SUM OF FIRST N ODD NATURAL NUMBERS*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf(“Enter the number: “);
scanf(“%d”,&n);
printf(“\nFirst %d odd natural numbers are: \n”,n);
for(i=1;i<=(2*n);i=i+2)
{
printf(“%d\t”,i);
sum=sum+i;
}
printf(“\n”);
printf(“\nSum of these numbers is: %d”,sum);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *