Thursday, February 7, 2019

Sum Of Digits of Given Positive Integer - using "C-Language" in Ubuntu.

File Name : sumdigits.c
void main()
{
 int n,s=0,d;
 printf("Enter Any Positive Number(Integer): ");         
 scanf("%d",&n);               
 while(n!=0)
 {
  d=n%10;       
  s=s+d;       
  n=n/10;       
 }
 printf("The sum of the digits of given Number is %d\n",s);
}

Output1:
Enter Any Positive Number(Integer):145
The sum of the digits of given Number is 10
Output2:
Enter Any Positive Number(Integer):34567
The sum of the digits of given Number is 25

No comments:

Post a Comment

Hadoop Commands

HADOOP COMMANDS OS : Ubuntu Environment Author : Bottu Gurunadha Rao Created: 31-Jan-2022 Updated: 31-Jan-2022 Release  : 1.0.1 Purpose: To ...

Search This Blog