Our Blog Contain Detail about Some Technical Aspect like Programming, Blogger, Tools and Tip, Suggestion, Motivational, Health, Program in C and Java, Html

Write a function that return sum of all the odd digits of a given positive no entered through keyboard

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();
}

Share:

No comments:

Post a Comment

Translate

Followers

Email Subscription

Enter your email address:

Delivered by FeedBurner

Recent Posts

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.