top of page

Updated: Jan 22, 2023


#include <stdio.h>

void main() {

int num1, num2,

float avg;

printf("Enter the first number: ");

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

printf("Enter the second number: ");

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

avg = (num1 + num2)/2; // Calculate the avg

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

Here's a brief explanation of the code:

  • The first line #include <stdio.h> is a preprocessor directive that tells the compiler to include the standard input/output library. This library contains functions like printf and scanf that are used to read input and print output.

  • int main() is the main function where the program starts executing.

  • int num1, num2, avg; declares three variables: num1 and num2 to store the two numbers and avg to store the result.

  • printf("Enter the first number: "); prints the message "Enter the first number: " on the screen, asking the user to enter the first number.

  • scanf("%d", &num1); reads an integer from the user and stores it in the variable num1. The & operator is used to pass the address of the variable to the function, so that it can store the input in that location.

  • The same steps are repeated for the second number.

  • avg = (num1 + num2)/2; calculates the average of num1 and num2 and stores it in the variable avg.

  • printf("The average of %d and %d is %d\n", num1, num2, avg); prints the result on the screen. The %d, %f is a placeholder for an integer and float.

You can run this program on a C compiler.

5 views0 comments

Updated: Jan 22, 2023


#include <stdio.h>

void main() {

int num1, num2, div;

printf("Enter the first number: ");

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

printf("Enter the second number: ");

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

div = num1 / num2; // Calculate the div

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

Here's a brief explanation of the code:

  • The first line #include <stdio.h> is a preprocessor directive that tells the compiler to include the standard input/output library. This library contains functions like printf and scanf that are used to read input and print output.

  • int main() is the main function where the program starts executing.

  • int num1, num2, sum; declares three variables: num1 and num2 to store the two numbers and div to store the result.

  • printf("Enter the first number: "); prints the message "Enter the first number: " on the screen, asking the user to enter the first number.

  • scanf("%d", &num1); reads an integer from the user and stores it in the variable num1. The & operator is used to pass the address of the variable to the function, so that it can store the input in that location.

  • The same steps are repeated for the second number.

  • div = num1 / num2; calculates the division of num1 and num2 and stores it in the variable div.

  • printf("The division of %d and %d is %d\n", num1, num2, div); prints the result on the screen. The %d is a placeholder for an integer.

You can run this program on a C compiler.


7 views0 comments

Updated: Jan 22, 2023


#include <stdio.h>

void main() {

int num1, num2, mul;

printf("Enter the first number: ");

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

printf("Enter the second number: ");

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

mul = num1 * num2; // Calculate the mul

printf("The multiplication of %d and %d is %d\n", num1, num2, mul);//Result

}

Here's a brief explanation of the code:

  • The first line #include <stdio.h> is a preprocessor directive that tells the compiler to include the standard input/output library. This library contains functions like printf and scanf that are used to read input and print output.

  • int main() is the main function where the program starts executing.

  • int num1, num2, mul; declares three variables: num1 and num2 to store the two numbers and mul to store the result.

  • printf("Enter the first number: "); prints the message "Enter the first number: " on the screen, asking the user to enter the first number.

  • scanf("%d", &num1); reads an integer from the user and stores it in the variable num1. The & operator is used to pass the address of the variable to the function, so that it can store the input in that location.

  • The same steps are repeated for the second number.

  • mul = num1 * num2; calculates the multiplication of num1 and num2 and stores it in the variable mul.

  • printf("The multiplication of %d and %d is %d\n", num1, num2, mul); prints the result on the screen. The %d is a placeholder for an integer.

You can run this program on a C compiler.


28 views0 comments
bottom of page