C - A2P1 - Sum of odd and even number






/* Write a Programe to find the sum of odd and even Numbers */

#include<stdio.h>
#include<conio.h>
void main()
{
    int sumodd=0,sumeve=0,a=1,num;
    clrscr();
    printf("Enter Number -> ");
    scanf("%d",&num);

    while(a!=num+1)
    {
        if(a%2==0)
        {
            sumeve+=a;
        }
        else
        {
            sumodd+=a;
        }
        a++;
    }
    printf("\n\nSum of Odd Numbers  -> %d",sumodd);
    printf("\n\nSum of Even Numbers -> %d",sumeve);
    getch();
}

Post a Comment