Question

*Please write in code in C* First, write a function called prime_check(int x) that takes an...

*Please write in code in C*

First, write a function called prime_check(int x) that takes an integer number as an input then return 1 if it is a prime number nd returns 0 if it is a composite number

Then, Write a program that prompt the user to input two numbers:

Print the multiplication of these two numbers if both of them are prime.

Or Print " Sorry at least one of your number is composite" if otherwise

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

#include <stdio.h>

int prime_check(int x);

int main() {
    int n1, n2;
    printf("Enter two integers: ");
    scanf("%d", &n1);
    scanf("%d", &n2);
    if (prime_check(n1) && prime_check(n2)) {
        printf("%d\n", n1 * n2);
    } else {
        printf("Sorry at least one of your number is composite\n");
    }
    return 0;
}

int prime_check(int x) {
    int i;
    for (i = 2; i < x; ++i) {
        if (x % i == 0)
            return 0;
    }
    return x > 1;
}


Please let me know if you have any doubts Please upuote this answer. Thanks!!

Add a comment
Know the answer?
Add Answer to:
*Please write in code in C* First, write a function called prime_check(int x) that takes an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use C programming Make sure everything works well only upload Write a program that takes an...

    Use C programming Make sure everything works well only upload Write a program that takes an integer from standard input and prints all prime numbers that are smaller than it to standard output. Recall that a prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. At the start of the program, prompt the user to input a number by printing "Input a number greater than 2:\n". If the user's input is less...

  • Q2. To check and print if entered integer is prime or not. Prompt the user to...

    Q2. To check and print if entered integer is prime or not. Prompt the user to enter a positive integer or 0 to exit. while negative integer entered - prompt for valid values again. If positive integer entered - check if it is prime. Write a separate function that accepts a positive integer as argument and checks and returns 1 if the integer is prime or 0 if it is not prime. Call the function from main. Accept the return...

  • please write program in C++ Write a function called productEven, that takes as its parameter an...

    please write program in C++ Write a function called productEven, that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. please write the program in C++

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • Functions can return a string, not just an int or a float. Write a function called...

    Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a number:...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • C Programming For this task, you will have to write a program that will prompt the...

    C Programming For this task, you will have to write a program that will prompt the user for a number N. Then, you will have to prompt the user for N numbers, and print then print the sum of the numbers. For this task, you have to create and use a function with the following signature: int sum(int* arr, int n); Your code should look something like this (you can start with this as a template: int sum(int* arr, int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT