Do your own work. Programs which are written in groups are easily identified and will receive grades of 0 for all participants.
Skill set for this assignment:
Examples:
1. If your input is 0 and 3 your program will display the following
message:
One integer is zero and one integer is positive.
2. If your input is 0 and 0 your program will display the
following message:
Two integers are zero
3. If your input is 5 and 6 you will display the following
message:
Two integers are positive.
4.If your input is -3 and 0 you will display the following:
One integer is zero and one is negative
Problem 2 (20 points)
Write a C program that reads one integer. The program performs the following, if the integer
is positive, the program prints the input number on one line the amount of times that equals to the input number
(numbers should be separated by space),
if the input number is negative, the program checks if the number is divisible by 5 or not and prints the
appropriate message, and if the input number is 0, the program prints Hello 3 times on different lines.
You have to use loop while or loop for in your program.
Example:
1. if input is 5, the output should be:
5 5 5 5 5
2. if the input is -7, the output should be: the number -7 is not divisible by 5
3. if the input is 0, the output should be:
Hello
Hello
Hello
Problem 3 (20 points)
Write a program that inputs a series of non-negative integers, the
first negative value will terminate the input.
The program determines and prints the amount of numbers that are divisible by 6 among input numbers
and the average of all numbers that are divisible by 6 among input
numbers. If there are no numbers divisible by 6 among the input number,
the program prints the following message: there are no numbers
divisible by 6. You have to
use loop while or loop for in your program
Examples:
1. if the input is 6 7 9 -12
the output should be:
there is 1 number that is divisble by 6 and their average is
6.0
2. if the input is -12
the output should be:
there is no numbers that are divisible by 6 and the average of these numbers is 0.0
3. if the input is: 8 12 3 6 6 18 -3
the output should be:
there are 4 numbers divisible by 6 and the
average is 10.5
Problem 4 (20 points)
Write a C program that solving a
linear equation ax + b = 0.
The program should accept as an input any two
integers as the coefficients a and b of the
equation.
The output will be the solution of the linear equation.
Directions: if a is not 0 the linear equation has a unique solution x = -b/a, if a is 0 and b is not 0 the linear equation doesn't have solutions at all, and if a and b are zeros the linear equation has infinite number of solutions. Your program has to consider all cases that were described above.
Examples:
1. if the input is a = 4 and b = 10, the output should be the equation has a unique solution x = -2.5
2. if the input is a = 0 and b = 0, the output should be there are infinite amount of solutions
3. if the input is a = 0 and b = 6, the output should be there is no solution for the given equation
Problem 5
(20 points):
Write a C program that reads a sequence of
integers. Assume that the first integer read with scanf specifies the
number of values remaining to be entered. The program finds
and prints the amount and the average of the even numbers among the
inputs. The first integer should not be taken into account.
Example:
If the input is: 6 6 -8 9 0 1 3
The output should be: There are 3 even numbers and their average
is
0.666667
Explanation to the output:since (6+(-8)+0)/2 is 2/3 which is
0.666667. Pay attention, that the first number 6 indicated that six more
integers was entered. Also, pay attention, that the first integer WAS
NOT TAKEN IN ACCOUNT for the calculation of the amount of even numbers and
their average.
Write a C program that reads in a number N and prints out all those numbers between 1 and N that are perfect numbers. For example, if the prompted input was 30, the program would print out 6 and 28. Your program should be able to accept values of N up to 10000.
The program has to check a validity for the input.
A few remarks and helpful hints: