w3resource

C Exercises: Reads two integers and checks whether they are multiplied or not

C Basic Declarations and Expressions: Exercise-24 with Solution

Check if two integers are multiples

Write a C program that reads two integers and checks whether they are multiplied or not.

Pictorial Presentation:

C Programming: Reads two integers and checks whether they are multiplied or not

C Code:

#include <stdio.h>
int main() {
    int  x, y; // Declare variables for two integers

    // Prompt user for the first number and store in 'x'
    printf("\nInput the first number: "); 
    scanf("%d", &x);
    // Prompt user for the second number and store in 'y'
    printf("\nInput the second number: ");
    scanf("%d", &y);
  
    if(x > y) 
    {
        int temp;
        temp = x; // Swap the values of 'x' and 'y'
        x = y;
        y = temp;
    }
    
    if((y % x)== 0) // Check if 'x' is a factor of 'y'
    {
        printf("\nMultiplied!\n"); // Print message if 'x' is a factor of 'y'
    } 
    else 
    {
        printf("\nNot Multiplied!\n"); // Print message if 'x' is not a factor of 'y'
    }
    
    return 0;
}

Sample Output:

Input the first number: 5                                              
                                                                       
Input the second number: 15                                            
                                                                       
Multiplied!

Flowchart:

C Programming Flowchart: Reads two integers and checks whether they are multiplied or not

C Programming Code Editor:


Previous: Write a C program that reads three floating values and check whether it is possible to make a triangle with them. Also calculate the perimeter of the triangle if the said values are valid.
Next: Write a C program that reads an integer between 1 and 12 and print the month of the year in English.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/c-programming-exercises/basic-declarations-and-expressions/c-programming-basic-exercises-24.php