If a four-digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number.
void main()
{
float a,d,t;
int a1,d1,t1,u;
printf("\nInput a 4 digit number");
scanf("%f",&t);
a=t/1000.0;
u=t;
a1=a;
d=u%10;
d1=d;
t1=a1+d1;
printf("\nThe Sum f %d",t1);
}
Subscribe to:
Post Comments (Atom)
yeah! man
ReplyDeletei searching it from many days
now i find it
cool site
Get easy code for C programming
DeleteVisit my BLog
the algorithm is, you first input a number eg> 5869 and divide by 1000 to separate the character part from mantissa thus 5.869. when you assign 5.869 to a integer type variable, the mantissa part(0.869) is not considered hence the value of first digit is "5" which we found.
ReplyDeleteto find the last digit, we use 10th power to see the remainder using modulo operator, thus 5869 mod 10 or remainder of 5869/10 is 4 which we found. then with first and last number added along with %d gives the output.
What are the different types of file formats you must know??
ReplyDeleteGet full information here ����
https://techychefs.blogspot.com/2020/08/different-types-of-file-formats-you.html