Skip to content

Instantly share code, notes, and snippets.

@raydvard
Created September 9, 2014 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raydvard/718e60cfae0f6bb56990 to your computer and use it in GitHub Desktop.
Save raydvard/718e60cfae0f6bb56990 to your computer and use it in GitHub Desktop.
C++
//###################### Prac-2 ########################## //
// Input an integer number and output the individual digits of the given number and sum of the individual digits //
// ####################################################### //
#include <stdio.h>
int main()
{
int num;
int fd, sd, td;
int sum;
printf("Please input an integer number: ");
scanf("%d", &num);
td = num % 10; // Logic to output last digit of any integer number is to find out the reminder !!
num = num / 10; // then i have divide by 10 that given number to make that number 10 place downward !!
sd = num % 10; // then again find out the reminder of that new number to output last digit of that new number !!
num = num / 10; // and so on
fd = num % 10;
sum = fd + sd + td; // To output the sum of those individual digits of the given number !!
printf("\nThe First digit of the given number is: %d", fd);
printf("\nThe Second digit of the given number is: %d", sd);
printf("\nThe Last digit of the given number is: %d", td);
printf("\nThe Total Sum of the digits of the given number is: %d", sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment