Sie sind auf Seite 1von 4

EASTERN MEDITERRANEAN UNIVERISTY

INFORMATION TECHNOLOGY

ITEC114

STRUCTURED PROGRAMMING

ASSIGNMENT 1

Mohamed Sanime Bin Abdel Wahab Amira

16700107

GROUP 1

ACADEMIC YEAR: FALL 2017 – 2018

November 27, 2017


Q1) What will be the output of the program? Without trace table will not be marked.
(30 p.)

TRACE TABLE

Main() F1() F2()


k m r x x y
3 5 0 3 5 0
4 6 2
8 5 6

OUTPUT
1 > 8 8
2 > 4 11
3 > 8 4

Q2) Write a C program with a function called getRandom() which will generate 10 random
numbers (between 0 and 9) with using an array and print them in main() as follows: (40 p.)

2
#include <stdio.h>
#include "stdlib.h"
#include "time.h"

int getRandom( )
{
int vrow;
vrow= rand()%10;
return vrow;
}

void main ()
{
int tab[10];
int i;
srand(time( NULL ) );
for ( i = 0; i < 10; i++ )
{
tab[i]=getRandom();
printf( "\t p[%d] : %d\n", i, tab[i]);
}
getchar();
getchar();
}

3
Q3) Write needed statements for the followings: (25 p.)

a) Write a function called menu which prints the text string "Menu choices". The
function does not pass any data back, and does not accept any data as parameters.

void menu( void )


{
printf("Menu choices");
}

b) Write a function prototype for the above function.

void menu( void );

c) Write a function called total, which totals the sum of an integer array passed to it (as
the first parameter) and returns the total of all the elements as an integer. Let the
second parameter to the function be an integer which contains the number of
elements of the array.

int total( int array[], int elements )


{
int loop, sum;

for( loop = 0, sum = 0; loop < elements; loop++ )


sum += array[loop];
return sum;
}

d) Write a function prototype for the above function.

int total( int [], int );

Das könnte Ihnen auch gefallen