Search This Blog

Labels

c codes (6) c++ codes (1)

Saturday, February 06, 2016

c program to print sum of the digits of the given number



c program to print sum of the digits of the given number

 In this program we have to given input a number and we have to find the sum of the digits of the given number and show the result in the output screen. This program is basically used for basic concept who are not known in the c programming.   

program code:-
#include<stdio.h>
int main()
 {
  int n,r,sum,m;
  printf("Enter a number :\n");
  scanf("%d",&n);
  m=n;
  sum=0;
  while(n>0)
    {
      r=n%10;
      sum=sum+r;
      n=n/10;
    }
printf("\n sum of digits of %d is %d ",m,sum);
return 0;
}

Output:-
cse@ubuntu:~$gcc sumdig.c - o sumdig
cse@ubuntu:~$./sumdig
Enter a number : 356

sum of digits of 356 is 14


In this program coding is done in the ubuntu software .It is basically used for student to use linux type operating system.Programmers can learn linux type operating system through this programs.  

No comments:

Post a Comment

Pages

Powered By Blogger