Home>

Receives 1234 as a character string, divides it into 1 2 3 4 and stores each in a variable,
I want to write a program that calculates and outputs the sum of 1 and 4 and the sum of 2 and 3.

The program below didn't work, so I'd like to know the solution.

Corresponding source code
#include<stdio.h>
int main (void) {
    char str [1000];
    fgets (str, sizeof (str), stdin);
    char a, b, c, d;
    a = str [0];
    b = str [1];
    c = str [2];
    d = str [3];
    printf ("% d", a + d);
    printf ("% d \ n", b + c);
}
c