Question

In: Computer Science

Write a program that asks the user for an integer. The program checks and prints to...

Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”.

please do it with a “ while Loop”,

Thanks..

Solutions

Expert Solution

Answer-

Your code is here-

  • #include<stdio.h>
  • int main()
  • {
  • int n, c = 2, f = 1;
  • printf("user enter a integer number\n");
  • scanf("%d", &n); //read a number
  • while(c < n) //using whille loop
  • {
  • if(n%c == 0)
  • {
  • f = 0;
  • break;
  • }
  • c++;
  • }    
  • if(f) //f=1 its print number is prime and f=0 then not prime
  • {
  • printf("%d is prime \n", n); //diplay a number
  • }
  • else
  • {
  • printf("%d is not prime \n", n);
  • }
  • return 0;
  • }

screenshot of output-

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a short program that asks the user for a sentence and prints the result of...
Write a short program that asks the user for a sentence and prints the result of removing all of the spaces. Do NOT use a built-in method to remove the spaces. You should programmatically loop through the sentence (one letter at a time) to remove the spaces.
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
Write a program which prompts the user for a positive integer, and then prints out the...
Write a program which prompts the user for a positive integer, and then prints out the prime factorization of their response. Do not import anything other than the Scanner. One way you might go about this using nested loops: Start a "factor" variable at 2 In a loop: repeatedly print the current factor, and divide the user input by it, until the user input is no longer divisible by the factor increment the factor This plan is by no stretch...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Write a program that asks the user to type in two integer values. Test these two...
Write a program that asks the user to type in two integer values. Test these two numbers to determine whether the first is evenly divisible by the second and then display the appropriate message to the terminal. Objective C
• Write a C++ program that asks the user to input two integer values, then calls...
• Write a C++ program that asks the user to input two integer values, then calls a void function "swap" to swap the values for the first and second variable. • As we mentioned before, in order to swap the valors of two variables, one can use the following: temp= variable1; variable1 = variable2; variable2 = temp; • Display the two variables before you call swap and after you call that function. Comment in code would be greatly appreciated to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT