If four-digit number is input through the keyboard, write a program to obtain the sum of the first and the last digit of this number.


#include

main ()
{
int number, last_digit, first_digit, total;
printf ("Enter the number which is to be Work out: ");

scanf ("%d", &number);


last_digit = number % 10;

total = last_digit;

first_digit = (number / 1000) % 10;

total = total + first_digit;

printf ("The total of the first and the last digit of the entered number is: %d", total);

}


1 comment:

  1. If four-digit number is input through the keyboard, write a program to obtain the sum of the first and the last digit of this number.
    //Author::Mudasir Yaqoob.....

    #include
    #include

    int main()
    {

    long number,t;
    int i=0;
    long temp[5];
    printf("Enter the five digit number:\n\n");
    scanf("%ld",&number);
    while(i<=4)
    {

    t=number%10+1;
    temp[i]=t;
    number=number/10;
    i++;

    }
    printf("Reverse number\n\n\n\n");
    for(i=4;i>=0;i--)
    {
    printf("%ld",temp[i]);
    }
    getch();
    }

    ReplyDelete