Saturday, January 30, 2010

CHAP 1[H]i Sum of first and last digit

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);
}

4 comments:

  1. yeah! man
    i searching it from many days
    now i find it
    cool site

    ReplyDelete
  2. 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.
    to 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.

    ReplyDelete
  3. What are the different types of file formats you must know??

    Get full information here ����
    https://techychefs.blogspot.com/2020/08/different-types-of-file-formats-you.html

    ReplyDelete