If
a four digit integer number is input through the keyboard then write a c program to find the
sum of first and before last digit.
#include<stdio.h>
main()
{
int i,j,num,first,sum=0,beforelast,temp=0;
printf("Enter the number:");
scanf("%d",&num);
for(i=1;i<=2;i++)
{
for(j=1;j<=i;j++)
first=num%10;
num/=10;
}
while(num!=0)
{
beforelast=num;
num=num/10;
}
sum=first+beforelast;
printf("\nSum of first digit and before last digit is:%d\n",sum);
}
#include<stdio.h>
main()
{
int i,j,num,first,sum=0,beforelast,temp=0;
printf("Enter the number:");
scanf("%d",&num);
for(i=1;i<=2;i++)
{
for(j=1;j<=i;j++)
first=num%10;
num/=10;
}
while(num!=0)
{
beforelast=num;
num=num/10;
}
sum=first+beforelast;
printf("\nSum of first digit and before last digit is:%d\n",sum);
}
No comments:
Post a Comment