Write a function that return sum of all the odd digits of a given positive no entered through keyboard
#include<stdio.h>
#include<conio.h>
int sumodd(int num)
{
int sum=0,i;
for(i=0;i<=num;i++)
{
if(i%2!=0)
{
sum=sum+i;
printf("%d,",i);
}
}
return sum;
}
void main()
{
int n,sum;
printf("enter a number\n");
scanf("%d",&n);
sum=sumodd(n);
printf("\n sum of odd number is %d",sum);
getch();
}
No comments:
Post a Comment