C program to find sum of even digits and sum of odd digits in integer

Program to find the Sum of Odd digits and the sum of even digits present in the given Integer :

Even number can be divided by 2. The remainder after dividing an even number by 2 is zero. Odd number can not be divided by 2. The remainder after dividing an Odd number by 2 is one. For example . . . Sum of Even digits of number 6547 is 10 and Sum of Odd digits of number 6547 is 12. The below given C program is used to find the Sum of odd digits and Sum of even digits present in the given Integer number using if statement. Kindly check out to find the Sum of odd digits and Sum of even digits present in the given Integer number.


Sum of even digits and Sum of odd digits program


#include<stdio.h> 

int main(){

               int num,rem,odd=0,even=0,digit,input;

               printf("  Enter an integer number: ");

               scanf("%d",&num);

               input = num;

               num = abs(num);

               while(num>0){

               digit = num % 10;

               num = num / 10;

               rem = digit % 2;

               if(rem != 0)

               odd=odd+digit;

               else

               even=even+digit;

               }

    printf("\n  The sum of Odd digits present in %d is %d.",input,odd); 

    printf("\n  The sum of even digits present in %d is %d.",input,even); 

    getch();

    return 0; 

    } 

 


Sample outputs:

  Enter an integer number: 2563

  The sum of Odd digits present in 2563 is 8

  The sum of even  digits present in 2563 is 8

  Enter an integer number: 7568

  The sum of Odd digits present in 7568 is 12

  The sum of even  digits present in 7568 is 14

  • Questions and answers
  • Download Pdf
  • Download
  • Answers

  • Pdf
  • Free Downloads
  • Antiviruses
  • Armstrong
  • Questions and answers
  • Download Pdf
  • Answers
  • Interviews
  • Solved
  • And College
  • Antivirus Program

Most Related Even or Odd Programs in C


* C program to check even or odd using Bitwise Operator

* C program to find Sum of Odd Digits of a Number

C program to find Sum of Even Digits of a Number

* C program to find Sum of Even and Odd Digits of a Number

* C program to print Odd Digits of a Number

* C program to print Even Digits of a Number

* C program to display Odd numbers from the given N numbers

* C program to display Even numbers from the given N numbers

* C program to check whether a number is odd or even

* C program to check odd or even using if else
* C program to check odd or even using switch case
* C program to check odd or even using function
* C program to check odd or even using Ternary Operator

Bookmark and Share