#include<conio.h>
#include<stdio.h>
void main()
{
int n,i,cnt;
cnt=0;
//Accept number
printf("Enter the number:");
scanf("%d",&n);
//To display all odd numbers
printf("All odd numbers :");
for(i=1;i<=n;i++)
{
if(i%2!=0)
{
printf("%d\t",i);
cnt=cnt+i;
}
}
// To display total sum of odd numbers
printf("\nTotal sum: %d",cnt);
getch();
}
0 Comments