GTU PPS Program - 20
20. Write a program to find out sum of first and last digit of a given number.
#include<stdio.h> #include<conio.h> int main() { int num,fd,ld,sum; printf("\nenter number : "); scanf("%d",&num); ld=num%10; while(num!=0) { if(num == ld) { fd=0; break; } else { fd=num%10; num=num/10; } } sum=fd+ld; printf("\nSum of first and last digit of given number is %d",sum); getch(); return 0; }
Comments