Computer Science, asked by priyasasi696, 1 year ago

c program for sum of all even numbers


bhattacharyyabi: c or c++

Answers

Answered by writersparadise
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);
}

Similar questions