Skip to main content

Posts

Showing posts with the label C program

C program | Simple C program - Example of a C program that takes two numbers as input adds them and then prints the result

C program: Here's a simple example of a C program that takes two numbers as input, adds them, and then prints the result: c #include <stdio.h> int main() {     // Declare variables to store user input and the result     double num1, num2, sum;     // Prompt the user to enter the first number     printf("Enter the first number: ");     scanf("%lf", &num1);     // Prompt the user to enter the second number     printf("Enter the second number: ");     scanf("%lf", &num2);     // Calculate the sum of the two numbers     sum = num1 + num2;     // Display the result     printf("The sum of %.2lf and %.2lf is %.2lf\n", num1, num2, sum);     return 0; } C programming language This program uses the `printf` and `scanf` functions from the `<stdio.h>` library to interact with the user. The program declares variables `num1`, `num2`, and `sum` to s...