Sum of Digit & Reverse of a Number - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    int r=0,n,sum=0,d;
    printf("Enter the number:");
    scanf("%d",&n);
    while(n>0)
    {
      d=n%10;
      sum=sum+d;
      r=(r*10)+d;
      n=n/10;
    }
    printf("\n sum of digits= %d",sum);
    printf("\n Reverse=%d",r);
    printf("\n");
//getch();
}

Output:
nn@linuxmint ~ $ gcc c24.c
nn@linuxmint ~ $ ./a.out
Enter the number:15

 sum of digits= 6
 Reverse=51
nn@linuxmint ~ $

3 comments:

Related Posts Plugin for WordPress, Blogger...