You are on page 1of 9

King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Information and Computer Science

Department Summer Semester 2 !"2 # $ !%& ICS ' % ( Computer Programming Using C Ma)or E*am ' +ednesday, '2 -uly 2 .ime/ 0 minutes
1ame/ ID2/ Please circle your section num3er 3elo4/ Section Instructor 1ame ' Faisal 5lvi 2 +aheed 5slam

6uestion 2 ' 2 % 9 .otal

Ma*imum Mar7s !*9:2 ' ' ' !

83tained Mar7s

'

6; '/ <5 marks each * 4 = 20 marks= >ive output for each of the follo4ing programs in the space provided/ $a& #include <stdio.h> void main(void) { int ctemp = 37, ftemp; ftemp = 9*ctemp ! " 3#; p$intf(%ftemp = &#d%, ftemp); '

$3& #include <stdio.h> void main(void) { int a(e, id, calc; cha$ c), c#, c3, c*; p$intf(%+nte$ ,ou$ the fi$st fou$ cha$acte$s of ,ou$ name- %); scanf(%&c&c&c&c%, .c), .c#, .c3, .c*); p$intf(%+nte$ ,ou$ a(e- %); scanf(%&d%, .a(e); p$intf(%+nte$ ,ou$ fou$/di(it id- %); scanf(%&d%, .id); calc = a(e 7 " id&)000; p$intf(%1ou$ pass2o$d is- &c&d&c%, c*, calc, c#); '

5ssume that the user types/ Sami 23 4312

$c& #include <stdio.h> void main(void) { int c, 3; p$intf(%+nte$ an inte(e$ f$om ) to 3- %); scanf(%&d%, .c); 3 = * / c; s2itch(3) { case )- p$intf(%4elcome5n%); 6$ea7; case #- p$intf(%c and 3 a$e e3ual85n%); 6$ea7; case 3- p$intf(%1ou t,ped )5n%); default- p$intf(%9ood6,e5n%); 6$ea7; ' '

5ssume that the user types/ 1

$d& #include <stdio.h> void main(void) { int i, sum = 0; float av(; fo$(i = ); i < )#; i"") { if(i & # == 0) sum = sum " i; else sum = sum " ); ' av( = sum )0.0; p$intf(%:he sum is- &*d5n%, sum); p$intf(%:he ave$a(e is- &*.#f%, av(); '

6; 2/ <10 marks= Design and implement a program 4hich inputs from the the three sides of a triangle a, b and c; It then calculates and prints the perimeter and area of the triangle using the formulas/
a +b +c 2 area = s ( s a ) ( s b ) ( s c ) s= perimeter = 2 s

6; %/ <10 marks= Design and implement a program in C that calculates the sum/ sum : ' ( ? ( ?@@;; ? .he value of n is entered 3y the user; .he program calculates and prints the value of sum;

6; 9/ <10 marks= Design and implement a program that computes the amount paya3le 3y an airline passenger on his 3aggage 3ased on the follo4ing ta3le/ Weight B 2 7g D 2 7g and B 9 7g D 9 7g SC; ' ? SC; $' Amount SC; ' per 7g for each additional 7g e*ceeding 2 7g&; SC; ' per 7ilogram

.he program as7s the user to enter the 4eight of his 3aggage; .he program then outputs the amount paya3le;

You might also like