Computer Science, asked by kkatiyar71, 10 months ago

Write a program to print sum of even numbers and sum of odd numbers from first 50 natural
numbers using a for( ) loop.​

Answers

Answered by subhanshuuu
6

Answer:

#include <stdio.h>

void main()

{

int i, num, odd_sum = 0, even_sum = 0;

printf("First 50 natural number \n");

for (i = 1; i <= 50; i++)

{

if (i % 2 == 0)

even_sum = even_sum + i;

else

odd_sum = odd_sum + i;

}

printf("Sum of all odd numbers = %d\n", odd_sum);

printf("Sum of all even numbers = %d\n", even_sum);

}

Explanation:

This code is written in C language

Mark as "brainliest" please

Similar questions