#include <stdio.h>
int main()
{
int num1, num2, sum;
// Step 1: Ask the user to enter the first number
printf("\nEnter the first number: ");
scanf("%d", &num1);
// Step 2: Ask the user to enter the second number
printf("\nEnter the second number: ");
scanf("%d", &num2);
// Step 3: Add the two numbers using the '+' operator
sum = num1 + num2;
// Step 4: Display the result
printf("The sum of %d and %d is %d\n", num1, num2, sum);
return 0;
}
Output:
Enter the first number:35
Enter the second number:40
The sum of 35 and 40 is 75
Explanation:
1. We include the necessary header file 'stdio.h' for input and output operations.
2. In the 'main' function, we declare three integer variables 'num1', 'num2', and 'sum' to store the two numbers and their sum.
3. We prompt the user to enter the first number using 'printf' and read the input using 'scanf'.
4. Similarly, we prompt the user to enter the second number and read the input.
5. We add the two numbers using the '+' operator and store the result in the 'sum' variable.
6. Finally, we display the result using 'printf' by formatting the output to show the numbers and their sum.
2.Write a program in C to subtract two numbers using the '-' operator.
3.Write a program in C to multiply two numbers using the '*' operator.
4.Write a program to divide two numbers using the '/' operator.
5.Write a program in C to find the remainder of two numbers using the '%' operator.
6.Implement a program in C to perform bitwise AND on two numbers using the '&' operator.
7.Write a program in C to perform bitwise OR on two numbers using the '|' operator.
8.Write a program to perform bitwise XOR on two numbers using the '^' operator.
9.Write a program in C to perform bitwise left shift on a number using the '<<' operator.
10.Implement a program in C to perform bitwise right shift on a number using the '>>' operator.
11.Write a program to in C check if a number is even or odd using the bitwise AND operator.
12.Write a program in C to swap two numbers without using a temporary variable.
13.Write a program in C to find the minimum of two numbers without using the 'if' statement.
14. Write a program in C to check if a number is negative without using the 'if' statement.
15. Write a program in C to toggle a particular bit in a number using bitwise XOR.
Other Topic:-->>Basic Assignments. || conditional statements Assignments in C.