C Programming


Solved Question – 1 (SQ-C-1)

Question –

Read the two integers from the user and output their values and their sum


Solution Details:

Programming Language Used: C

Code in C

#include <stdio.h>

using namespace std;

 int main()
 
  { 
 
  // variable declaration of integer type..
 
   int num1, num2, total_sum;
 
  // printing the message to the console...  

    printf("Enter the values two integers: ");

 //  reading the variable values from the user....

    scanf("%d %d", &num1, &num2);
    
 //	Adding up the variables and storing them in total_sum variable... 
    
    total_sum = num1 + num2;
    
 // Printing all the values...	
 
    printf("Value of Integer 1 is = %d\n", num1);
    
    printf("Value of Integer 2 is = %d\n", num2);
    
    printf("Total Sum of %d + %d = %d", num1, num2, total_sum);
    
    
    return 0;
    
    }

 


Output:

Enter the values of two integers: 10 20

Value of Integer 1 is = 10

Value of Integer 2 is = 20

Total Sum of 10 + 20 = 30


Explanation:

  •  Declare Variables of integer type – num1, num2, and total_sum (For storing the user’s input values and sum result)
  • Sum – total_sum = num1 + num2;
  • Print all the values num1, num2, total_sum.

 


 

 

Leave a Reply

Your email address will not be published. Required fields are marked *