20. Write a program to find out sum of first and last digit of a given number.
#include<stdio.h>
#include<conio.h>
void main()
{
int fd,ld,sum,num;
printf("Enter your number:");
scanf("%d",&num);
if(num>9)
{
ld=num%10;
while(num>9)
{
num=num/10;
}
fd=num;
sum=fd+ld;
printf("Sum of first digit and last digit is %d",sum);
}
else
{
printf("You entered one digit no %d",num);
}
getch();
}
#OUTPUT:
#include<conio.h>
void main()
{
int fd,ld,sum,num;
printf("Enter your number:");
scanf("%d",&num);
if(num>9)
{
ld=num%10;
while(num>9)
{
num=num/10;
}
fd=num;
sum=fd+ld;
printf("Sum of first digit and last digit is %d",sum);
}
else
{
printf("You entered one digit no %d",num);
}
getch();
}
#OUTPUT:
Comments
Post a Comment