Showing posts with label integer. Show all posts
Showing posts with label integer. Show all posts

C and C++ Programs to Find Sum of Digits of a Given Number

The following are C and C++ programs to find sum of digits of any given integer.

C Program

#include<stdio.h>
#include<conio.h>
void main()
{

C and C++ Program to Check Whether a Given Number is Even or Odd

C and C++ programs to check whether a given number is Odd or even

C Program

#include<stdio.h>
void main()
{
int n;
printf("Enter an integer\n");
scanf("%d",&n);
if ( n%2 == 0 )
printf("Even");
else
printf("Odd");
}

C++ Program

#include<iostream.h>
void main()
{
int n;
cout<<"Enter an integer\n";
cin>>n;
if ( n%2 == 0 )
cout<<"\nEven";
else
cout <<"\nOdd";
}