Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Contributor: Ravishankar ChavareWrite a c program to print even numbers and odd number between 10 and find their sum
#1
Write a c program to print even numbers and odd number between 10 and find their sum

Code:
#include<stdio.h>


void main()
{
    int i,odd,even,todd=0,teven=0,total=0;

    for(int i=0;i<10;i++)
    {
        if(i%2==0)
        {
            even=i;
            printf("\neven:%d",i);
            teven=even+teven;
        }
        else
        {
            odd=i;
            printf("\nodd:%d",i);
            todd=odd+todd;
        }
        total=total+i;
    }

    printf("\nodd sum : %d",todd);
    printf("\neven sum : %d",teven);
    printf("\nsum : %d",total);

}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)