WAP to print sum of all even number and odd number from 1 to n
Find the sum of odd
numbers and sum of even numbers from 1 to N
#include
<stdio.h>
#include <conio.h>
#include <conio.h>
void
main()
{
int i, N, oddSum = 0, evenSum = 0;
{
int i, N, oddSum = 0, evenSum = 0;
clrscr();
printf("Enter
the value of N\n");
scanf ("%d", &N);
scanf ("%d", &N);
for
(i=1; i <=N; i++)
{
if (i % 2 == 0)
evenSum = evenSum + i;
else
oddSum = oddSum + i;
}
{
if (i % 2 == 0)
evenSum = evenSum + i;
else
oddSum = oddSum + i;
}
printf
("Sum of all odd numbers = %d\n", oddSum);
printf ("Sum of all even numbers = %d\n", evenSum);
}
/*-----------------------------
printf ("Sum of all even numbers = %d\n", evenSum);
}
/*-----------------------------
Output
RUN1
RUN1
Enter
the value of N
10
Sum of all odd numbers = 25
Sum of all even numbers = 30
10
Sum of all odd numbers = 25
Sum of all even numbers = 30
RUN2
Enter the value of N
50
Sum of all odd numbers = 625
Sum of all even numbers = 650
Enter the value of N
50
Sum of all odd numbers = 625
Sum of all even numbers = 650
------------------------------*/
Comments
Post a Comment