1.
Find the output:
Code:
int x =5, y;
while (x >= 2) {
y=1;
while (y <= x) {
printf ( “ * “ );
y++; }
x--;
printf ( “\n” ); }
2.
Find the output of the following program segment.
int A [ ] = { 1, 3, 5, 2, 4, 7 }; int i, h, j = 5;
for ( i = 0; i < 3; i ++ ) {
h = A [ i ];
A [ i ] = A [ j ];
A [ j ] = h; j = j - 1; }
for ( j = 0; j < = 5; j++ )
printf ( “ %4d “ , A [ j ] );
3.
Given the following main program, write a function which prints the average of array elements.
void xyz ( int [ ], int );
int main ( ) {
int A [10 ] = {1,2, . . . ., 10}; int n; \\ n refers to 10 elements.
xyz ( A, n );
return 0; }
4.
Given the following function, write the main program which calls the function and prints the results.
int xyz ( int x, int y, int y ) {
int a, b;
a = x + y + z:
b = a/3;
return b; }
Here is what I believe is the answers,
1.
*
*
*
*
2.
everything is printed backwards 7,4,2,5,3,1
3.
I'm stuck on this one
4.
stuck on this on as well