Programming Fundamentals for Engineers - Final Exam, Slides of Programming for Engineers

this is a slides for Programming Fundamentals for Engineers in c languge

Typology: Slides

2021/2022

Uploaded on 05/18/2023

khader-qaabar-1
khader-qaabar-1 🇵🇸

5 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Al-Quds University - Faculty of Engineering - Computer Engineering Department
Programming Fundamentals for Engineers 0702102
Final Exam
Monday, January, 17th, 2011 Time allowed: 120 minutes
Circle your section: (1) SW 8:00 – 9:20 (2) NT 9:30
Name: _____________________________________________ Reg #: ______________________________
Note: Before writing your C Code, provide adequate Analysis/Algorithm where applicable (mainly in Q 3 and 4).
Start answering every question in a new page!
Answer Quetion1 and Question 2 on this question paper & Submit with answer book!
Q1) What is the exact output in each case of the following, assuming these declarations before each one? (36
marks)
int i = 2, j, k = 0, *v, x, *l, y, z, w = 10, *m, n = 4, o, *nPtr, *oPtr, p, q, r;
p = q = r = 20;
1 ) w h i l e ( i < = 1 5 )
{ f o r ( j = 1; j < = 15 ; j + + )
i f ( j % 3 = = 0 ) k + + ;
i = i + 2; }
printf("\n k = %d", k);
S o l u t i o n :
k = 35
Page 1 of 13
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Programming Fundamentals for Engineers - Final Exam and more Slides Programming for Engineers in PDF only on Docsity!

Al-Quds University - Faculty of Engineering - Computer Engineering Department Programming Fundamentals for Engineers 0702102 Final Exam Monday, January, 17th, 2011 Time allowed: 120 minutes Circle your section: (1) SW 8:00 – 9:20 (2) NT 9: Name: _____________________________________________ Reg #: ______________________________ Note: Before writing your C Code, provide adequate Analysis/Algorithm where applicable (mainly in Q 3 and 4). Start answering every question in a new page! Answer Quetion1 and Question 2 on this question paper & Submit with answer book! Q1) What is the exact output in each case of the following, assuming these declarations before each one? ( marks) i n t i = 2 , j , k = 0 , * v , x , * l , y , z , w = 1 0 , * m , n = 4 , o , * n P t r , * o P t r , p , q , r ; p = q = r = 2 0 ; 1 ) w h i l e ( i < = 1 5 ) { f o r ( j = 1 ; j < = 1 5 ; j + + ) i f ( j % 3 = = 0 ) k + + ; i = i + 2 ; } p r i n t f ( " \ n k = % d " , k ) ; S o l u t i o n : k = 35

  1. v = & x ;
  • v = 1 2 ; p r i n t f ( " \ n % d \ t % d " , * v , + + x + 6 ) ; S o l u t i o n : 13 19
  1. m = & w ; / / A s s u m e w i s i n t h e l o c a t i o n 0 x F A 1 2 0 0 1 5 , a n d i n t e g e r t a k e s 4 b y t e s p r i n t f ( " \ n w = % d & w = % p , * m = % d , m = % p \ n " , w , & w , * m , m ) ; ( * m ) + + ; p r i n t f ( " * m = % d , w = % d \ n " , * m , w ) ; m - - ; p r i n t f ( " * m = % d , m = % p \ n " , * ( m + 1 ) , m ) ; W=10 &w= FA120015, *m=10, m=FA *m=11, w = 11 *m = 11, m = FA

Note: Decrement of 1 in integer pointer means FA120015 - 4 = FA Answer in above box is according to the assumption in question

n P t r = & n ; o = * n P t r / 3 + 1 2 ; o P t r = n P t r ; p r i n t f ( " n = % d , o = % d , * n P t r = % d , * o P t r = % d \ n " , n , o , * n P t r , * o P t r ) ; N=4, o=13, *nPtr=4, *oPtr=4 (4)

  1. p r i n t f ( " % d " , ( 5 % 2 > 1 6 *. 2 5 & & 6 - 5 ) ) ; 0
  1. p r i n t f ( " % d " , ( i n t ) ( 2. 3 * 5 ) / 3 ) ; S o l u t i o n : 3 Note: actual output should be 3.83 but due to typecasting to integer, decimal part will be discarded
  2. p r i n t f ( " % 4. 2 f " , ( f l o a t ) ( 6 * 5 ) / ( 7 * 2 + 8 ) ) ;

Q2) What is the output of the following programs? (12 marks) main() { char far *s1, *s2; printf (“%d%d”, sizeof(s1), sizeof (s2)); } 4 2 int x=40; main() { int x=20; printf (“\n%d”,x); } 20 Whenever there is a conflict between local and global variables – the local variable gets priority main() { int x=40; { int x = 20; printf (“\n%d”, x); } printf (“%d”, x); } 20 40 the variable that is more local gets priority incase of conflict between local variables main() { int i=4; switch (i) { default: printf (“\n Chocolate”); case 1: printf (“\n Vanilla”); break; case 2: printf (“\n Strawberry”); break; case 3: printf (“\n Then nothing”); } }

main() { inti = -3,j=2,k=0,m; m = ++j&&++i||++k; printf(“\n%d%d%d%d”,i,j,k,m); }

If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program? main() { float a=5.375; char p; inti; p = (char)&a; for (i-0, i<=3; i++) printf (“%02x”, (unsigned char) p[i]); } 00 00 AC 40 Q3) Answer with True or False (20 marks)

  1. A function may have several declarations but only one definition ____T____
  2. Are the following two statements the same? ___F_____ a <= 20? b = 30 :c = 30; (a <= 20)? b : c = 30;
  3. Expressions ptr++ and ++ptr are same. ____F____
  4. A pointer to a block of memory is the same as an array. ____T____
  5. Are the following two statements the same? a <= 20? b = 30 :c = 30; *((a <= 20)? &b : &c) = 30; ____T____
  6. y = int (x + 0.5); rounds off x, a float, to an integer? ________
  7. A function cannot be defined inside another function ____T____
  8. In a function two return statements should never occur successively. ____T____
  9. For the following statements, would arr[3] and ptr[3] fetch the same character? ___T_____ char arr[] = “surprised”; char *ptr = “surprised”;
  10. The program bellow outputs an Error. ____F____

Q5) a. Develop an algorithm that asks the user to enter two positive non equal numbers representing the low_end and high_end values of a range, compute and output the sum of the even numbers in the range? ( marks) b. Develop a function to swap two characters using pointers? (5 marks)