Assignment 1
Assignment 1
(EAE&AT)
Assignment 1
1. Identify and correct the errors in each of the following statements:
a) printf( "The value is %d\n", &number );
b) scanf( "%d%d", &number1, number2 );
c) if ( c < 7 ); {
printf( "C is less than 7\n" );
}
d) if ( c => 7 ) {
printf( "C is greater than or equal to 7\n" );
}
2. State the order of evaluation of the operators in each of the following C
statements and show the value of x after each statement is performed.
a) x = 7 + 3 * 6 / 2 - 1;
b) x = 2 % 2 + 2 * 2 - 2 / 2;
c) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 3 ) ) ) );
3. Write a program that asks the user to enter two numbers, obtains them from
the user and prints their sum, product, difference, quotient and remainder.
4. Write a program that asks the user to enter two integers, obtains the numbers
from the user, then prints the larger number followed by the words “is larger.”
If the numbers are equal, print the message “These numbers are equal.”
5. Write a program that reads in three integers and then determines and prints
the largest and the smallest integers in the group.
6. Write a program that reads an integer and determines and prints whether it’s
odd or even. [Hint: Use the remainder operator. An even number is a multiple
of two. Any multiple of two leaves a remainder of zero when divided by 2.]
7. Write a program that inputs one five-digit number, separates the number into
its individual digits and prints the digits separated from one another by three
-1-
EGYPTIAN ACADEMY OF ENGINEERING & ADVANCED TECHNOLOGY
(EAE&AT)
spaces each. [Hint: Use combinations of integer division and the remainder
operation.] For example, if the user types in 42139, the program should print
42139
8. write a program that calculates the squares and cubes of the numbers from 0
to 10 and uses tabs to print the following table of values:
9. Write a program that inputs three different integers from the keyboard, then
prints the sum, the average, the product, the smallest and the largest of these
numbers. Use only the single-selection form of the if statement you learned in
this chapter. The screen dialogue should appear as follows:
-2-