Friday, August 16, 2019

WAP to find the sum of digits of entered number.

//Program

#include<stdio.h>
void main()
{
     int n,i,r;
     int s=0;
     clrscr();
     printf("Enter any number:");
     scanf("%d",&n);
     while(n!=0)
     {
          r=n%10;
          s=s+r;
          n=n/10;
     }
     printf("Sum of digits=%d",s);
     getch();
}

Sample Input/Output:

Enter any number:1234
Sum of digits=10

No comments:

Post a Comment

Write a program to find gcd of two numbers using recursion.

About:  The process in which a function calls itself is called recursion and the corresponding function is called as recursive function. ...