Professional Documents
Culture Documents
(Q1) (5 marks)
A. Fill in the blanks ( 4 marks)
- The main difference between structures and arrays is …Structures are heterogeneous data structure
(different data types) while arrays are homogenous data structure (all elements are same data type)
- Structures in C language can be used to defined……. users’ own data types …………,…………..
- Passing by reference is used when we want ……. update or return more than one data item…………
- The algebraic formula a – [ ( b / c ) x d ] can be presents in C language ……a – b / c * d …..…………
----------------------------------------------------------------- switch(Q)
------------------------------------------------------------------
{
If ( Q > 0 &&| Q < 9 )
Z = 8; case 1: case 2: case 3:
else case 4: case 5: case 6:
Z = 9; case 7: case 8:
Z = 8;
------------------------------------------------------------------ break;
------------------------------------------------------------------- default:
-----------------------------------------------------------------
------------------------------------------------------------------
Z = 9;
}
D. Fill in the two columns, assume that you have the following statements: ( 3 marks)
Equivalent
int X = 2, Y = 5 ; C Expression Algebraic Value
float F= 2.5, G = 3.5; Expression
X+=5 X=X+5 7
F-=G F=F–G -1.0000
Y*=(X–3) Y = Y*(X–3) -5 or 20
F/=3 F=F/3 0.83 or -0.5
X%=(Y–2) X = X%(Y-2) 0 or 2
E. Consider the following function named
void reverse(char A[20])
“reverse” that reverses a given string A,
which received as argument, into B and {
print the reversed version B. int i = ..0.. , j = ..0.., count = …0…;
char …B[20]…;
Fill in the blanks to complete the while ( A[count] != '\0' )
implementation of reverse …count++;
for (j = count. ; j >= 0 ; j - -)
B[ …i++…] = …A...[ j ];
printf("%..s..", B);
} (4 marks)
(2 marks) ( 3 marks)
A) Write a C function that accepts a 1-dimensional floating-point array and its size as arguments and
prints the smallest values in that array. (5 marks)
……………………………………………………………………………………………………………………………
………………………void Smallest1DArray( float *Arr, int Size) …………………………………
…………………… { …………………………………………………………………………………………………
………………………… …………float smallest = Arr[0] ; ………………………………………………
………………………………………for ( int i = 1 ; i < Size ; i++) ……………………………………..……
……………………………………………if ( Arr[ i ] < smallest ) …………………………………………
…..………………………………………………smallest = Arr[ i ] ; ……………………………………………
………………………………………printf(“ % f “ , smallest ) ; ……………………………………………
………………………} ……………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
B) Write a C program that has two functions: main function and the other function (called “Average” )
accepts a 2-dimensional floating-point array of size 2 x 3 as argument and returns the average of the
values in that array. The main function should declare a 2D array with the values {8,3,5,2,4,5}, and
then gets the average by calling the Average function and finally prints the average. (9 marks)
……………………………………………( 7 mark ).
………START………………………………………………
……… SET Engine 0 …………………………….
……… SET Count 0 …………………………….
……… SET Number 0 …………………………….
L1: … GET/READ/INPUT Size ………………
……… IF Size = -1 THEN …………………………
………………Average Enigne / Number ……
………………PRINT Average , Count ……………
………………STOP …………………………………………
………ENDIF ……………………………………………
……… IF Size > 1.5 THEN …………………………
………………Count Count + 1
………ENDIF ……………………………………………
………Number Number + 1 ……………………
………Engine Engine + Size …………………
………GOTO L1 …………………………………………
……………………………………………………………………
……………………………………………………………………
……………………………………………………………………
…………………………………………………………………
……………………………………………………………
A) Define a structure called “Name” that has one data member; a string of size 20, and define another
structure called "Personal-Info" that has two members: National-ID as a string of size 12, and
array of above structure “Name” to presents the first name, second name, and family name.
void main ()
{
struct Personal-Info Employee[12] ;
for ( int i =0 ; i < 12 ; i++)
{
scanf(“%s”, Employee[i].N-ID;
scanf(“%s”, Employee[i].PerName[0].N);
scanf(“%s”, Employee[i].PerName[1].N);
scanf(“%s”, Employee[i].PerName[2].N);
}
}
………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………
……………………………………………………………………………………………………………………………
Good Luck