Knowee
Questions
Features
Study Tools

write easies code for me : Write a program in C to find if a number is prime or not.

Question

write easies code for me : Write a program in C to find if a number is prime or not.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple program to check if a number is prime:

#include <stdio.h>

int main() {
    int num, i, isPrime = 1;

    printf("Enter a number: ");
    scanf("%d", &num);

    if (num <= 1) {
        isPrime = 0;
    } else {
        for (i = 2; i <= num / 2; ++i) {
            if (num % i == 0) {
                isPrime = 0;
                break;
            }
        }
    }

    if (isPrime)
        printf("%d is a prime number.\n", num);
    else
        printf("%d is not a prime number.\n", num);

    return 0;
}

This program prompts the user to enter a number, then checks if the number is prime by testing divisibility from 2 up to half of the number. If the number is divisible by any of these, it is not prime.

This problem has been solved

Similar Questions

Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying "prime", and if it is not a prime number saying "not a prime". Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.

What are looping statements. Write a program to check whether a number is prime no. or not.

Problem StatementCharlie is intrigued by the concept of prime ASCII codes. Write a program to help Charlie determine whether a given character corresponds to a prime ASCII code. Check if the ASCII code is a prime number and print "yes" if it is prime and "no" otherwise.Assist Charlie in developing a program that accurately identifies prime ASCII codes for different characters.Input format :The input consists of a character c.Output format :The output prints "yes" if the converted ASCII code is a prime number, and "no" if it is not a prime number.

Write a program primes.py that reads a positive integer from standard input, and determines whether or not the number is prime.

A prime number is an integer greater or equal to 2 that is only divisible by 1 and by itself. The first few primes are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 …N is a prime if and only if it is not divisible evenly by any of the numbers from 2 to N−1. Let’s implement this decision as a function.In the same program numbers.cpp, add a functionbool isPrime(int n);The function should return true if n is a prime, otherwise return false. Change the main function to test your new code.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.