Sony exam
1. Complete the following procedures
*
*.*.
*..*..*..
*...*...*...*...
*....*....*....*....*....
*.....*.....*.....*.....*.....*.....
*...... *...... *...... *...... *...... *...... *......
*....... *....... *....... *....... *....... *....... *....... *.......
# Include <stdio. h> # define N 8 int main (){
Int I;
Int J;
Int K;
---------------------------------------------------------
|
|
|
---------------------------------------------------------
Return 0;
}
A:
# Include <stdio. h>
# Define N 8
Void main ()
...{
Int I;
Int J;
Int K;
For (I = 1; I <= N; I ++)
...{
K = I;
For (; k> 0; k --)
...{
Printf ("*");
For (j = I; j> 1; j --)
...{
Printf (".");
}
}
Printf ("");
}
Getch ();
}
2. Complete the program to sort the array in descending order.
# Include <stdio. h> void sort ();
Int main (){
Int array [] = {45, 56, 76,234, 3}; // number // meaning given
Sort ();
Return 0;
}
Void sort ()
{
---------------------------------------------------------
|
|
|
---------------------------------------------------------
}
3. feberana's series: 1, 1, 2, 3, 5 ...... Write the program for the tenth item. You can use recursion or other
Method.
# Include <stdio. h>
Int Pheponatch (int );
Int main ()
{
Printf ("The 10th is % d", Pheponatch (10 ));
Return 0;
}
Int Pheponatch (int N)
{
--------------------------------
|
|
--------------------------------
}
4. The following program will crash when running. Please find out the error and correct it and explain the cause.
# Include <stdio. h>
# Include <malloc. h>
Typedef struct {
TNode * left;
TNode * right;
Int value;
} TNode;
TNode * root = NULL;
Void append (int N );
Int main ()
{
Append (63 );
Append (45 );
Append (32 );
Append (77 );
Append (96 );
Append (21 );
Append (17); // Again, given as any number
}
Void append (int N)
{
TNode * NewNode = (TNode *) malloc (sizeof (TNode ));
NewNode-> value = N;
If (root = NULL)
{
Root = NewNode;
Return;
}
Else
{
TNode * temp;
Temp = root;
While (N> = temp. value & temp. left! = NULL) | (N <temp. value & temp.
Right
! = NULL
))
{
While (N> = temp. value & temp. left! = NULL)
Temp = temp. left;
While (N <temp. value & temp. right! = NULL)
Temp = temp. right;
}
If (N> = temp. value)
Temp. left = NewNode;
Else
Temp. right = NewNode;
Return;
}
}
The answer is being updated ..........