top of page

DIVISION OF TWO NUMBERS

Writer's picture: Code CrazeCode Craze

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

Recent Posts

See All

Stack Using Queue

A stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...

Queue Using Stack

A queue can be implemented using two stacks in C. The basic idea is to use one stack for enqueue operations and another for dequeue...

Queue Using Array

#include <stdio.h> #include<stdlib.h> #include<math.h> #define size 5 int queue[size]; int front = -1; int rear = -1; void enque(void);...

Commentaires


bottom of page