Sie sind auf Seite 1von 3

National University of Sciences and Technology School of Environmental and Civil Engineering

ASSIGNMENT #1
Exercise on Getting Started with C Language
Submission Date: 6th March, 2012

Lecturer Asad Ali Shah

National University of Sciences and Technology


School of Environmental and Civil Engineering
Course: Fundamentals of Computer Programming Class: CE-UG-2011 Total Marks: 80

[A] Point out the errors if any in the following C statements [1] int =314.562*150; [2] char name=Ajay; [3] 3.14*r*r*h=vol; [4] A=b=3=4; [5] Count=count+1; [6] Area++; [B] Display the following outputs using escape sequences [1] He said, Lets do it! [2] You must be crazy to hate C Programming [C] Solve the problems according to the specification given

6 Marks

6 Marks

(dont use space to separate the words and use one printf() command only)

18 Marks

[1] Write a program that prints the numbers 1 to 4 on the same line. Write the program using the following methods 6 Marks a. Using one printf statement with no conversion specifiers b. Using one printf statement with four conversion specifiers c. Using four printf statements [2] Given the equation y=ax^3+7, which of the following, if any, are correct C statements for this equation 6 Mark a. Y=a*x*x*x+7; b. Y=a*x*x*(x+7); c. Y=(a*x)*x*(x+7); d. Y=(a*x)*x*x+7 e. Y=a*(x*x*x)+7 f. Y=a*x*(x*x+7) [3] 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 6 Marks a. X=7+3*6/2-1; b. X=2%2+2*2-2/2; c. (3*9*(3+(9*3/(3))))

[D] Write programs for the following problems

50 Marks

[1] Assuming basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary. 5 Marks [2] Write a program that inputs three different integers from the keyboard, then prints the sum, the average and the product of the numbers. The output should look like this 5 Marks Input three different integers: 13 27 14 Sum is 54 Average is 18 Product is 4914 [3] Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D using 2 variables only. Hint: You will need to use + and operators in order to solve this 5 Marks

[4] If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits i.e. the sum of 12345 would be 15. (Hint: Use the modulus operator %) 10 Marks [5] If a five-digit number is input through the keyboard, write a program to reverse the number. 10 Marks [6] If you have two fractions a/b and c/d, their sum can be obtained from the formula. E.g. 15 Marks a/b + c/d = (a*d + b*c) / b*d + 2/3 = (1*3+4*2)/4*3 = 11/12 Write a program that encourages the user to enter two fractions, and then displays their sum in fractional form. You dont need to reduce in to decimal form. The interaction between the user and the program might look like this Enter first fraction: Enter second fraction: 2/5 Sum= 9/10 You can take the advantage if the fact that you can take multiple inputs at one time Scanf(%d %c %d,&iNominator,&cOperator,&iDenominator);

Das könnte Ihnen auch gefallen