Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Examples:

Sure, here's a simple C program that takes two numbers as input from the user, calculates their sum, and then prints the result:

#include <stdio.h>

int main() {
// Declare variables to store the two numbers
int num1, num2;

// Prompt the user to enter the first number
printf("Enter the first number: ");

// Read the first number from the user
scanf("%d", &num1);

// Prompt the user to enter the second number
printf("Enter the second number: ");

// Read the second number from the user
scanf("%d", &num2);

// Calculate the sum of the two numbers
int sum = num1 + num2;

// Print the result
printf("The sum of %d and %d is %d\n", num1, num2, sum);

return 0;
}

In this example

When you run this program, it will prompt you to enter two numbers, calculate their sum, and then print the result. For example:

Enter the first number: 10
Enter the second number: 20
The sum of 10 and 20 is 30

This is a basic example to demonstrate how to take input from the user, perform a calculation, and print the result in C.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java