Data types:
- Data Type defines what Type of value you can store in a Variable.
- Primary Data Types: int ,float and char.
Float:
- Format Specifier = %f
- Keyword = float
- Space = 4 byte
- Range = 3.4 * 10^(38) to -3.4 * 10^(38)
- Decimal values are allowed.
#include<conio.h>
void main()
{
int i, N ;
oddsum=0;
evensum=0;
clrscr();
printf(" Enter the value of N\n");
scanf("%d" , &N);
for( i=1 ; i<=N ; i++ )
{
if(i%2 ==0)
{
evensum=evensum+ i;
}
else
{
oddsum=oddsum+i;
}
}
printf(" Sum of Odd Numbers = %d" , oddsum);
printf(" Sum of Even Numbers = %d" , evensum);
getch()
}
Output:
Enter the value of N
10
Sum of Odd Numbers = 25
Sum of Even Numbers = 30
0 Response to "Write a C Program to Find the Sum of Odd Numbers and Even Numbers from 1 to N by using if and for Statement"
Post a Comment