C URI Solution 1001 – Extremely Basic

Problem statement

In this program, simply we will take two numbers (integers) from the keyboard and then we will print their sum as the formatted output. Numbers can be either negative or positive.

Sample InputSample Output
10
9
X = 19
-10
4
X  = -6
15
-7
X  =  8

Required Skill

  • C basic syntax
  • Variables in C
  • printf() and scanf() function

Logic to solve

First, we will declare two different variables for holding the two integer values from the keyboard. Let define it as A and B. Then after reading the values and keeping them in A and B, then you will sum it by C summation operator.

But we have to keep the sum value somewhere in the memory. To do that, declaring another variable is only one way for basic understanding. So we will declare another variable let say ‘sum‘. After keeping the value of the sum in the ‘sum’ variable, we will print it out as below.

C URI Solution 1001 – Extremely basic

/* Sum of two integer numbers */

#include <stdio.h>
int main() {
    int A, B, sum;

    scanf("%d", &A);
    scanf("%d", &B);

    sum = A + B;

    printf("X = %d\n", sum);

    return 0;
}

Note: You can use any name for any variable. Means, in the above code the variable could be X and Y instead of A and B. Moreover, you can name it by following the variable naming syntax in C.