How to get last digit of a number in c
#include <stdio.h> /** * C program to find last digit of a number */ int main() { int n, lastDigit; /* Input number from user */ printf("Enter any number: "); scanf("%d", &n); /* Get the last digit */ lastDigit = n % 10; printf("Last digit = %d", lastDigit); return (0); }
How to find the first and last digit of an integer in C
#include <stdio.h> int main() { int n, sum=0, firstDigit, lastDigit; printf("Enter number = "); scanf("%d", &n); // Find last digit of a number lastDigit = n % 10; //Find the first digit by dividing n by 10 until n greater then 10 while(n >= 10) { n = n / 10; } firstDigit = n; printf("first digit = %d and last digit = %d\n\n", firstDigit,lastDigit); return 0; }
Source: aticleworld.com