//Write a C program to find sum of all odd numbers between 1 to n.
#include "stdio.h"
int main (){
int num,i,sum;
printf ("Enter the value of number :\n");
scanf ("%i",&num);
i=1;
while(i<=num){
sum=sum+i;
i=i+2;
}
printf ("The sum of all odd numbers between 1 to n is %i",sum);
return 0;
}
output output output output
Enter the value of number :
10
The sum of all odd numbers between 1 to n is 25
No comments:
Post a Comment