• Language

    C

  • Description

    It prompts the user to enter a 4-digit number and the program calculates the sum of the four numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int a_4_digit_number, sum;
    printf ("Enter the value of a 4 digit number: ");
    scanf ("%d", &a_4_digit_number);
    (void) getchar ();
    sum=(a_4_digit_number%10000-a_4_digit_number%1000)/1000+(a_4_digit_number%1000-a_4_digit_number%100)/100+(a_4_digit_number%100-a_4_digit_number%10)/10+a_4_digit_number%10;
    printf ("Value of sum: %d\n", sum);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}