Write a program to find the sum of first n odd numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1,sum=0;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
do
{
sum=sum+i;
i=i+2;
}while(i<=n);
printf("Sum=%d",sum);
getch();
}
Output:
Enter the number: 10
Sum=25
No comments: