C Programming Code Examples C > For Loops and While Loops Code Examples Program to find sum of first and last digit without using loop Program to find sum of first and last digit without using loop Write a C program to input a number and find sum of first and last digit of the number using for loop. How to find sum of first and last digit of a number in C programming using loop. Logic to find sum of first and last digit of a number without using loop in C program. /* C program to find sum of first and last digit of a number */ #include <stdio.h> #include <math.h> int main() { int j, sum, digits, firstDigit, lastDigit; sum = 0; /* Input a number from user */ printf("Enter any number to find sum of first and last digit: "); scanf("%d", &j); /* Find last digit */ lastDigit = j % 10; /* Find total number of digits - 1 */ digits = (int) log10(j); /* Find first digit */ firstDigit = (int) (j / pow(10, digits)); /* Calculate the sum */ sum = firstDigit + lastDigit; printf("Sum of first and last digit = %d", sum); return 0; }