

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
this is exam for Programming Fundamentals for Engineers in c languge
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


st
Student Name:______________________ SID:___________________ Time:40 minutes QUESTION 1 (10 MARKS) Circle the right answer. 1.1 Referring to the sample code bellow, what is the new content of the "x" array? a) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } b) { 0, 1, 20, 3, 4, 5, 6, 7, 8, 9 } c) { 0, 1, 2, 20, 4, 5, 6, 7, 8, 9 } d) { 0, 1, 2, 3, 20, 5, 6, 7, 8, 9 } e) { 0, 1, 2, 3, 4, 20, 6, 7, 8, 9 } 1.2 In the following code segment, what is the value of i? int i; i = sizeof("\007"); a) 1 b) 2 c) 3 d) 4 e) 5 f) 6 1.3 What happens when the program below is compiled and executed? a) The code prints out: j=3. b) It does not compile c) The address of "j" is printed out. d) The code prints out: j=2. e) The code prints out: j=4. 1.4 In What is the value of "x" in the sample code below? double x; x = 3 + 5 * 2 + 2; a) 12 b) 15 c) 18 d) 23 e) 32 1.5 What value does x[3] in the sample code below contain? int x[5] = {1,2,3,4,5} a) 1 b) 2 c) 3 d) 4 e) 5
Given the function below, find and correct the syntax errors int afunction ( int a, int b) { float c , sum; int n, a[10]; for (n= =0; n<=10; n++) if (n mod 3) printf ("%d", a[n]); sum=sum + a[n]; return sum; } main() { int sum; afunction (5,5) printf ("%s \n", sum); return sum; } QUESTION 3 (6 MARKS) Show the output generated by each of the following C programs? #include <stdio.h> main ( ) { int a, b = 0; static int c[10]={1,2,3,4,5,6,7,8,9,0}; for (a = 0; a < 10; ++a) if ((c [a] % 2) == 0 )b += c[a]; printf ("%d", b); } #include <stdio.h> main ( ) { int a, b = 0; static int c[10]={1,2,3,4,5,6,7,8,9,0}; for (a = 0; a < 10; ++a) if ((a % 2) == 0 )b += c[a]; printf ("%d", b); } #include <stdio.h> #define ROWS 3 #define COLUMNS 4 int z [ROWS][ COLUMNS] = {1,2,3,4,5,6,7,8,9,10,11,12}; main() { int a,b,c,= 999; for (a = 0; a < ROWS; ++a) #include <stdio.h> #define ROWS 3 #define COLUMNS 4 int z [ROWS][ COLUMNS] = {1,2,3,4,5,6,7,8,9,10,11,12}; main() { int a,b,c; for (a = 0; a < ROWS; ++a) {