Question

THE PROGRAMMING LANGUAGE IS C++ Part 1.Create a program that decides whether a given integer is...

THE PROGRAMMING LANGUAGE IS C++

Part 1.Create a program that decides whether a given integer is prime or not. The program should at the end of its analysis print the number followed by prime or composite.

Part 2.Make the program from part 1 print the prime factors of any composite number entered (an additional feature to Part 1).

THE PROGRAMMING LANGUAGE IS C++

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

PART 1:

#include<iostream>
using namespace std;
int main()
{
int n,i,count=0;
printf("Enter a number: ");
scanf("%d",&n);
if(n==1)
{
printf("%d is neither prime or composite number.",n);
}
else
{
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
printf("%d is prime number.",n);
else
printf("%d is composite number.",n);
}
return 0;
}

PART 2:

#include<iostream>
using namespace std;
int main()
{
int n,i,count=0;
printf("Enter a number: ");
scanf("%d",&n);
if(n==1)
{
printf("%d is neither prime or composite number.",n);
}
else
{
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
printf("%d is prime number.",n);
else
{
printf("%d is composite number.",n); //part 2
printf("\nPrime factors are: ");
int j=2;
while(n>1)
{
while(n%j==0)
{
printf("%d ",j);   
n=n/j;
}
j++;
}
}
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
THE PROGRAMMING LANGUAGE IS C++ Part 1.Create a program that decides whether a given integer is...
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
  • Answer should be in C programming language Write a program that will create an array of...

    Answer should be in C programming language Write a program that will create an array of 10 floating point numbers and take input 10 floats from keyboard. The program will print the position (index) of the maximum and minimum number among them

  • Using the C Programming Language: An integer number is said to be a perfect number if...

    Using the C Programming Language: An integer number is said to be a perfect number if its factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a function perfect that determines if parameter number is a perfect number. Use this function in a program that determines and prints all the perfect numbers between 1 and 1000. Print the factors of each...

  • 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...

  • Using the programming language C, read user input of an integer, check and output whether the...

    Using the programming language C, read user input of an integer, check and output whether the integer is an odd number or even number.

  • You are to create a program that queries the user for a range of integer values...

    You are to create a program that queries the user for a range of integer values (min and max). For this range, you are to find all of the prime numbers and print them to the screen. The user is then given the option to request that all of the non-prime numbers be printed to the screen with at least one factor pair that proves that they are not prime. (Using language C)

  • use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times)...

    use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times) Outputs: • [integer) highest value . [integer] lowest value Description: Write a program that lets the user enter 10 values. These values should be stored in an array. Your program will then find the highest and lowest values in the array. Your program will display the list of number as a comma separated list, and print which values is the highest and lowest Do...

  • Q1 SUMMER2020- nts python language Example Write a program to read an integer r then print...

    Q1 SUMMER2020- nts python language Example Write a program to read an integer r then print a triangle with r number of rows using .asterisks Result Input 5 Hint: Use end= parameter of the print function to not add a newline to the end of the string * * * * * * * * * * * * 9 - عام python language Course Information o Course Material Assignments o example input Lab Exercises Quizzes Result 7.0 ACUTE 7.0...

  • Part 1: Write a C++ function that inputs a positive integer and determines whether it is...

    Part 1: Write a C++ function that inputs a positive integer and determines whether it is prime using trial division. Part 2: Use the function from part 1 to make a C++ program that finds as many primes of the form n2 + 1, where n is a positive integer, as you can.

  • Language is C programming Student ID should be 8 numbers long. create a program to read...

    Language is C programming Student ID should be 8 numbers long. create a program to read your student ID number and store it in an array. Input can not be hard wired, I have to be able to input my number Then change the first number to a letter. If the same number repeats in other parts of your student ID, you must change that number to a letter as well. print original array and modified array as your output....

  • Question 4: C Programming (15 points) Create a program that asks the user for an integer...

    Question 4: C Programming (15 points) Create a program that asks the user for an integer number representing the number of students in a classroom. Your program will then malloc an array of struct students having the same number of cells as input by the user's integer number. The student struct will have only two fields: student name and gpa. Your program then opens a CSV file

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