Tuesday, May 15, 2012

Test Programming with C Problem 6

/* Problem 6: If a 4 digit number is input through the keyboard, write a program to obtain the sum of the first and last digit of this number. */

#include<stdio.h>
#include<conio.h>

int main()
{
    int num, res1st, res2nd;
   
    printf("Please enter a 4 digit number.\n");
    scanf("%d", &num);
   
    res1st = num % 10;
    res2nd = num / 1000;
   
    printf("The sum of first and last digit of that number is %d\n", (res1st+res2nd));
   
    getch();
    return 0;
}

No comments:

Post a Comment

No Spamming Please.