Write a Program that checks whether the two (2)numbers entered by the user are equal or not in C. content

equal or not in C

Concept

the concept for checking whether two numbers are equal or not in C:

  1. Declare two integer variables to store the user-entered numbers, let’s call them num1 and num2.
  2. Use scanf function to read the first number from the user and store it in num1.
  3. Use scanf function again to read the second number from the user and store it in num2.
  4. Use an if statement to compare the values of num1 and num2.
  5. In the if statement condition, use the equality operator == to check if num1 is equal to num2.
  6. If the condition is true, execute a code block indicating that the numbers are equal. For example, you can print a message like “The numbers are equal.”
  7. If the condition is false, execute a different code block indicating that the numbers are not equal. For example, you can print a message like “The numbers are not equal.”

the concept for checking whether two numbers are equal or not in C++:

  1. Declare two variables to store the user-entered numbers, let’s call them num1 and num2.
  2. Use std::cin to read the first number from the user and store it in num1.
  3. Use std::cin again to read the second number from the user and store it in num2.
  4. Use an if statement to compare the values of num1 and num2.
  5. In the if statement condition, use the equality operator == to check if num1 is equal to num2.
  6. If the condition is true, execute a code block indicating that the numbers are equal. For example, you can use std::cout to print a message like “The numbers are equal.”.
  7. If the condition is false, execute a different code block indicating that the numbers are not equal. For example, you can use std::cout to print a message like “The numbers are not equal.”.

the concept for checking whether two numbers are equal or not in Java:

  1. Declare two variables to store the user-entered numbers, let’s call them num1 and num2.
  2. Use the Scanner class to read the first number from the user and store it in num1.
  3. Use the Scanner class again to read the second number from the user and store it in num2.
  4. Use an if statement to compare the values of num1 and num2.
  5. In the if statement condition, use the equality operator == to check if num1 is equal to num2.
  6. If the condition is true, execute a code block indicating that the numbers are equal. For example, you can use System.out.println() to print a message like “The numbers are equal.”.
  7. If the condition is false, execute a different code block indicating that the numbers are not equal. For example, you can use System.out.println() to print a message like “The numbers are not equal.”.

the concept for checking whether two numbers are equal or not in Python:

  1. Prompt the user to enter the first number and store it in a variable, let’s call it num1.
  2. Prompt the user to enter the second number and store it in a variable, let’s call it num2.
  3. Use an if statement to compare the values of num1 and num2.
  4. In the if statement condition, use the equality operator == to check if num1 is equal to num2.
  5. If the condition is true, execute a code block indicating that the numbers are equal. For example, you can use the print() function to display a message like “The numbers are equal.”.
  6. If the condition is false, execute a different code block indicating that the numbers are not equal. For example, you can use the print() function to display a message like “The numbers are not equal.”.

C

#include <stdio.h>

int main() {
    int num1, num2;

    printf("Enter the first number: ");
    scanf("%d", &num1);

    printf("Enter the second number: ");
    scanf("%d", &num2);

    if (num1 == num2) {
        printf("The numbers are equal.\n");
    } else {
        printf("The numbers are not equal.\n");
    }

    return 0;
}

In both the C and C++ programs, the user is prompted to enter two numbers. The program then compares the two numbers using the equality operator ==. If the numbers are equal, it displays the message “The numbers are equal.” Otherwise, it displays the message “The numbers are not equal.”

C++

#include <iostream>

int main() {
    int num1, num2;

    std::cout << "Enter the first number: ";
    std::cin >> num1;

    std::cout << "Enter the second number: ";
    std::cin >> num2;

    if (num1 == num2) {
        std::cout << "The numbers are equal." << std::endl;
    } else {
        std::cout << "The numbers are not equal." << std::endl;
    }

    return 0;
}

Python

num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

if num1 == num2:
    print("The numbers are equal.")
else:
    print("The numbers are not equal.")

In this Python program, the user is prompted to enter two numbers using the input() function. The float() function is used to convert the input to floating-point numbers for numerical comparison.

The program then uses the equality operator == to check if the two numbers are equal. If they are equal, it prints the message “The numbers are equal.” Otherwise, it prints the message “The numbers are not equal.”

Java

import java.util.Scanner;

public class NumberEqualityChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

    System.out.print("Enter the first number: ");
    double num1 = scanner.nextDouble();

    System.out.print("Enter the second number: ");
    double num2 = scanner.nextDouble();

    if (num1 == num2) {
        System.out.println("The numbers are equal.");
    } else {
        System.out.println("The numbers are not equal.");
    }
}

}

javaScript

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question("Enter the first number: ", function(num1) {
    rl.question("Enter the second number: ", function(num2) {
        if (parseFloat(num1) === parseFloat(num2)) {
            console.log("The numbers are equal.");
        } else {
            console.log("The numbers are not equal.");
        }

        rl.close();
    });
});

In this JavaScript program, the user is prompted to enter two numbers using the readline module. The parseFloat() function is used to convert the input to floating-point numbers for numerical comparison.

The program then uses the equality operator === to check if the two numbers are equal. If they are equal, it prints the message “The numbers are equal.” Otherwise, it prints the message “The numbers are not equal.”

71 / 100 SEO Score

By Sandip Kumar Singh

I am Sandip Kumar Singh founder at Edgevertise Servise Pvt. Ltd. and a dedicated and passionate Computer Science professional .I am working as Assistant professor of (IT/Cs department) at R R Group of Institution Lucknow.

3 thoughts on “Write a Program that checks whether the two (2)numbers entered by the user are equal or not in C. content”
  1. whoah this blog is great i love reading your articles. Keep up the great work! You know, a lot of people are looking around for this information, you could help them greatly.

  2. Hey! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My blog addresses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to shoot me an email. I look forward to hearing from you! Excellent blog by the way!

Leave a Reply

Your email address will not be published. Required fields are marked *