Write a programs for odd,even and also sum of odd digits and even digits.
Programe code:
#include<stdio.h>
#include<conio.h>
void main()
{
int
i,no,d,odd=0,even=0,cnt=0,tmp=0;
clrscr();
printf("\n
enter value ");
scanf("%d",&no);
while
(no!=0)
{
d=no%10;
if
(d%2==0)
{
cnt++;
even=even+d;
}
else
{
tmp++;
odd=odd+d;
}
no=no/10;
}
printf("\n
sum odd number=%d",odd);
printf("\n
sum even number=%d",even);
printf("\n
total even digits=%d",cnt);
printf("\n
total odd digits=%d",tmp);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int
i,no,d,odd=0,even=0,cnt=0,tmp=0;
clrscr();
printf("\n
enter value ");
scanf("%d",&no);
while
(no!=0)
{
d=no%10;
if
(d%2==0)
{
cnt++;
even=even+d;
}
else
{
tmp++;
odd=odd+d;
}
no=no/10;
}
printf("\n
sum odd number=%d",odd);
printf("\n
sum even number=%d",even);
printf("\n
total even digits=%d",cnt);
printf("\n
total odd digits=%d",tmp);
getch();
}
No comments:
Post a Comment