Sum of first and last digit of the number in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main(){ | |
int n; | |
int temp=0; | |
int res=0; | |
printf("Enter number"); | |
scanf("%d",&n); | |
temp=n%10; | |
n=n/10; | |
res+=temp; | |
while(n>0){ | |
if(n/10==0){ | |
res+=n%10; | |
} | |
n=n/10; | |
} | |
printf("%d",res); | |
return 0; | |
} |
Comments
Post a Comment