Showing posts with label Sum of digits program in C. Show all posts
Showing posts with label Sum of digits program in C. Show all posts
reverse number Program in C

reverse number Program in C

C Program to reverse number

In this Program we will using loop and arithmetic operators and make a Program to reverse Integer Numbers. First, we will getting number as input from the user and reversing that number.

Lets Understand Program Steps

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int n, reverse=0, rem;  
  6. clrscr();  
  7. printf("Enter a number: ");  
  8.   scanf("%d", &n);  
  9.   while(n!=0)  
  10.   {  
  11.      rem=n%10;  
  12.      reverse=reverse*10+rem;  
  13.      n/=10;  
  14.   }  
  15.   printf("Reversed Number: %d",reverse);  
  16. getch();  
  17. }  
Output:
Enter a number: 123
Reversed Number: 321
Sum of digits program in C

Sum of digits program in C

Sum of digits program in C With Example

C program to sum each digit: Let's Make a program in C language to the sum of digits program with the help of loop and mathematical operation.

Steps to design algorithm sum of Integers

To get sum of each digits by c program, use the following algorithm:
  • Step 1: Take number by user as Input
  • Step 2: Get the modulus/remainder of the number
  • Step 3: sum the remainder of the number
  • Step 4: Divide the number by 10
  • Step 5: Repeat the step 2 while number is greater than 0.
Let's see the sum of digits program in C.

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. void main()  
  4. {  
  5. int n,sum=0,m;  
  6. clrscr();  
  7. printf("Enter a number:");  
  8. scanf("%d",&n);  
  9. while(n>0)  
  10. {  
  11. m=n%10;  
  12. sum=sum+m;  
  13. n=n/10;  
  14. }  
  15. printf("Sum is=%d",sum);  
  16. getch();  
  17. }     

Output:

Enter a number:654
Sum is=15

Enter a number:123
Sum is=6

Popular Posts