Question

In: Computer Science

1.Divisors flow chart using modulo operator (%) to print out all the divisors of a user...

1.Divisors

flow chart using modulo operator (%) to print out all the divisors of a user entered number. Your program should prompt the user to enter a positive number or 0 to end. Using a loop variable that starts at 1, your program should print out all the divisors of the entered number plus the number of printed divisors and their sum.

For example:
This program identifies and displays divisors of a given number.
Developed as an IPC144 project.

Enter a positive number. Enter 0 to end: 15
1 3 5 15
4 divisors
sum of divisors: 24

Enter a positive number. Enter 0 to end: 36
1 2 3 4 6 9 12 18 36
9 divisors
sum of divisors: 91

Enter a positive number. Enter 0 to end: 43
1 43
2 divisors
sum of divisors: 44
Enter a positive number. Enter 0 to end: 0
Thanks and bye!

  1. Divisor counter

Using what you did in part 1,to develop a function called
unsigned divisorCount (unsingned num)

That gets an integer number as an input parameter and returns the number of divisors of that number. For example, if you send 15 to the function, it will return 4 as 15 has 4 divisors: 1, 3, 5, 15
The function will return 2 for 17 because 17 only has two divisors


3.Prime number

Using the function you developed in part 2, write a
int isPrime(unsigned num)

That gets a number as a paremeter and returns 1 if the number is prome and returns 0 if the number is not prome.

Use this function to write a code that gets a number from the user and prints all the prime numbers smaller and equal to that number

A sample run of your code should look like:

Please enter a positive integer number (0 to end): 12 Primes before 12 are: 2 3 5 7 11

5 Prime numbers smaller than 12

Please enter a positive integer number (0 to end): 7 Factors of 7 are: 2 3 5 7

4 prime numbers smaller than 7

Please enter a positive integer number (0 to end): 0

Thanks and have a good day!

Hint: This question is divide to three-part each of the parts is individual and the answer for each of the part will need to link together with a flowchart and c code

Solutions

Expert Solution

Flow chart to find divisors :

  • read n
  • if n is 0, end the program
  • set i = 1, sum = 0, count = 1
  • loop until i<=n
    • if n%1 ==0, print i, add i to sum, increment count
    • increment i
  • print sum and count

C function to find divisors count:

unsigned int divisorCount(unsigned int n){
int count = 0;
for(undigned int i = 1; i<=n; i++){
if(n%i==0)
count += 1;
}
return count
}

function for prime number check:

int isPrime(unsigned int n){
if(divisorCount(n)>2)
return 0;
return 1;
}

complete program that prints prime number less than n:

  • get a number n from user.
  • set count = 0
  • loop for i = 2 to count
    • if isprime(i) then print i and increment count
  • print count

#include <stdio.h>

unsigned int divisorCount(unsigned int n){
int count = 0;
for(unsigned int i = 1; i<=n; i++){
if(n%i==0)
count += 1;
}
return count;
}

int isPrime(unsigned int n){
if(divisorCount(n)>2)
return 0;
return 1;
}

int main(){
unsigned int n;
int count;
printf("Please enter a positive integer number(0 to end: ");
scanf("%u",&n);
while(n!=0){
count = 0;
printf("Prime number before %u are", n);
for(int i =2;i<=n;i++){
if(isPrime(i)){
printf("%d ", i);
count++;
}
}
printf("\n%d prime numbers smaller than %u\n", count, n);
printf("Please enter a positive integer number(0 to end: ");
scanf("%u",&n);
}
}

output:


Related Solutions

Read a number N and print all its divisors.
Read a number N and print all its divisors.
Write a program that will print out “W” using a character that a user provides. use...
Write a program that will print out “W” using a character that a user provides. use for loop statement. in java please
using Emulator Write an Assembly program that will produce all divisors for a 1-digit decimal number....
using Emulator Write an Assembly program that will produce all divisors for a 1-digit decimal number. For example, if the number is 6, then the outputs will be 1,2,3,6 which are the divisors of 6. show me the output
1. Create a flow chart from the algorithm then create python code. Algorithm: Tell the user...
1. Create a flow chart from the algorithm then create python code. Algorithm: Tell the user to enter their name, how many cars the user has, and the average number of cars per family in the users state. Create a variable to show the difference between the users number of cars and the average number of cars per family. Print the values of name, number of cars, average number of cars, and the difference in 2 decimal places.
Ask the user to enter test scores. Once they have entered -1, print out the highest...
Ask the user to enter test scores. Once they have entered -1, print out the highest grade. Ensure that the grade entered is an integer.(Using Java Language) Enter integers between 0 and 100, -1 when finished. Enter a test score: [asdf] Enter an integer. Enter a test score: [32.5] Enter an integer. Enter a test score: [42] Enter a test score: [99] Enter a test score: [87] Enter a test score: [x] Enter an integer. Enter a test score: [-1]...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Your application will read in from the user an employee's name and salary, and print out...
Your application will read in from the user an employee's name and salary, and print out a Console Check similar to the following. Your newly modified check printing application will this time accommodate names and numbers of different lengths WITHOUT pushing the left or right hand side of the check out of whack. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > | $1,000,000 | > > > > ___Pay to the Order of___ Johnny PayCheck > >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Pease only use technique from chapter 1-4 in C++...
Create a python program that will ask the user for his job title and print out...
Create a python program that will ask the user for his job title and print out the first letter, the last letter and the total number of letters in his job
How to make a flow chart out of this??? To compute the rates you have the...
How to make a flow chart out of this??? To compute the rates you have the following established: 1. Regular service - $6.00 plus first 50 minutes free. Charges for over 50 minutes are $0.20 per minute. 2. Premium service - $15.00 plus: a. For calls made from 6:00am to 6:00pm, the first 75 minutes are free; charges for over 75 minutes are $0.10 per minute. b. For calls made from 6:00pm to 6:00am, the first 100 minutes are free;...
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter...
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be : [srivatss@athena shell]> ./mult.sh I will be printing the multiplication table Please enter a number 10 1 x 10 = 10 2 x 10 = 20 3 x 10 = 30 4 x 10 = 40 5 x 10 = 50 6 x 10 = 60 7 x 10 = 70 8 x 10...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT