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 ~ $

4 comments:

  1. C++ Program to Reverse a Number

    Reverse of number means reverse the position of all digits of any number. For example reverse of 536 is 635

    ReplyDelete
  2. Enrich your knowledge in web development with our Best Mern Stack Course In South Delhi , where we provide a comprehensive understanding of the MERN technology, empowering you for success.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...