Assignment03

advertisement
CSE 1311 – Homework #03
Due: Sunday, September 27, 2015 at 11:59pm
1- You must submit your homework through Blackboard (https://elearn.uta.edu/).
2- The answer file should be named using the following pattern:
X_Y_HW3.doc where X is your last name and Y is your first name.
3- Your answer file should include:
a. A copy of your code from program1.
b. Your answer for program2.
c. A copy of your code from program3.
d. A copy of your code from program4.
4- Make sure your code can be compiled with no error prior submission. Codes which cannot be
compiled will get 0 points.
5- Your program must compile as a C89 program.
Assignment:
Program 1- (30) Write a program that prompts the user for a positive integer n and then sums the
integers in the range of 100 to 1000 (inclusive) that are evenly divisible by n. The program will print
the final sum.
 Sample Outputs:
1- Enter a positive integer: (13)
The sum is 37674
Program 2- (10) The following program is written to print out all multiples of 3 between 1 and 30.
But it does not produce expected output. First, find the bug and second correct it.
Your answer should include:
1- The line that contains the error in the original code.
2- Your corrected version of that line.
Here is the program:
#include <stdio.h>
int main(){
int i;
for (i = 7; i <= 70; i = i+7);
{
printf("%d\n", i);
}
}
Program 3- (30) Write a program that prompts for an integer, n, and then prints a sideways pyramid
of asterisks that is n asterisks in height.
 Sample Outputs:
1- Enter the number: (4)
*
**
***
****
***
**
*
Program 4- (30) Write a program that prompts for two integers A and B, then


If A > B, the program should exit without doing anything.
Otherwise, the computer computes the following sum and prints the result.
1.0
1.0
1.0
1.0
+
+
+ ...+
A
A+1
A+2
B

Sample Outputs:
1- Enter the first integer: (4)
Enter the second integer: (4)
The result is: 0.25
2- Enter the first integer: (4)
Enter the second integer: (5)
The result is: 0.45
3- Enter the first integer: (4)
Enter the second integer: (6)
The result is: 0.62
Note: here is code you can use to store integer values in double numbers:
int a, b;
double a2, b2;
a2 = a;
b2 = b;
You may (or may not) need to do that, depending on your solution. Have in mind that, in
the C language, 1/4 is equal to 0, if 1 and 4 are integers, but 1.0/4.0 is equal to 0.25., if 1.0
and 4.0 are doubles.
Download