c program for sum of all even numbers
bhattacharyyabi:
c or c++
Answers
Answered by
1
/*
* C program to find the sum of even numbers from 1 to N
*/
#include <stdio.h>
void main()
{
int i, num, odd_sum=0, even_sum=0;
printf ("Enter the value of num\n");
scanf (%d, &num);
for(i=1; i<=num; i++)
{
(if i % 2 ==0)
even_sum = even_sum + 1 ;
else
odd_sum = odd_sum + 1;
}
printf ("Sum of odd numbers = %d\n, odd_sum);
printf ("Sum of even numbers = %d\n, even_sum);
}
* C program to find the sum of even numbers from 1 to N
*/
#include <stdio.h>
void main()
{
int i, num, odd_sum=0, even_sum=0;
printf ("Enter the value of num\n");
scanf (%d, &num);
for(i=1; i<=num; i++)
{
(if i % 2 ==0)
even_sum = even_sum + 1 ;
else
odd_sum = odd_sum + 1;
}
printf ("Sum of odd numbers = %d\n, odd_sum);
printf ("Sum of even numbers = %d\n, even_sum);
}
Similar questions
Political Science,
8 months ago
Math,
1 year ago
Science,
1 year ago
Math,
1 year ago
English,
1 year ago