C Examples
Powerful, efficient, and the foundation of modern systems programming.
Example 1: Adding two Numbers
Code
#include
int main() {
int a, b, sum;
// Taking input from user
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
// Calculating sum
sum = a + b;
// Displaying output
printf("Sum is: %d\n", sum);
return 0;
}
Input
Enter first number: 10 Enter second number: 8
Output
Sum is: 18
Code Explanation
scanf() takes input and stores it in variables a and b. sum = a + b performs addition. printf() prints the result using %d for integers.