SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to calculate sum of first and last digit
C program to calculate sum of first and last digit
Output:
Enter the number to find sum of first & last digit of the number: 1234
The sum of first & last digits in 1234 is 5
Implementation:
#include
int main(void) { int n; int sum=0; int flag=1; int last=0; int copy; printf("Enter the number to find sum of first & last digit of the number:\n"); scanf("%d",&n); copy=n; while(n) { if(flag) { sum += (n%10); flag=0; } else { last=(n%10); } n/=10; } printf("The sum of first & last digits in %d is %d",copy,(sum+last)); return 0; }
PREVIOUS
NEXT
HOME