Revisions Questions of C Programming
Revisions Questions of C Programming
23. Explain the similarity and difference between Nested if and switch ststements
24. Write the output of the following program given the input as
a. K=12 P= 7 H= 10 and G= 100
b. K=15 P= 70 H= 100 and G= 100
c. K=25 P= 32 H= 170 and G= 81
d. K=100 P= 100 H= 100 and G= 100
Int K,H,P,G
If (K>P && G!=H)
{
printf(“Value ok”);
Printf((“ Add Ten to G”);
}
else if (K<P II G==H)
Printf(“The values are wrong”);
else if (K<=P II G>=H)
Printf(“The values are almost ok”);
else if (K>=P II G>=H)
Printf(“The values are almost ok”);
else
Printf (“Try again”);
Printif( “it shall be well”);
25. Write the output of the following C program
#include <stdio.h>
main ()
{ int digit;
digit = 0;
while (digit <=9)
{ printf(“%d\n”, digit);
++digit;
}
}
26. Rewrite the program in 25 above using FOR and DO WHILE statements as used in C programming
27. Differentiate between printf() and scanf() functions of C programming and explain their relation with
#include<stdio.h> header file
28. With the aid of syntax diagrams differentiate between FOR and DO WHILE repetition control structures
29. Write the output of the following C program
#include<stdio.h>
{
int i, j ;
for(i=1; i<=2; i++)
for(j=1; j<=2; j++)
{
if(i==j)
continue;
else
printf(“%d %d\n”, i,j );
}
}
30. Rewrite the program in 29 above using WHILE and DO WHILE statements
31. Write the output of the following codes
a. for(int k=1;k<=5; k++)
{
for(int J=1;j<=5; j++)
printf(“%d ”,k);
printf(“\n”);
}
b. for(int k=1;k<=5; k++)
{
for(int J=1;j<=5; j++)
printf(“%d ”,j);
printf(“\n”);
}
c. for(int k=1;k<=5; k++)
{
for(int J=1;j<=5; j++)
printf(“%d ”,k*j);
printf(“\n”);
}
d. for(int k=6;k>=1; k--)
{
for(int J=1;j<=k; j++)
printf(“%d ”,j);
printf(“\n”);
}
e. for(int k=7;k>=1; k--)
{
for(int J=1;j<=5; j++)
printf(“%d ”,k);
printf(“\n”);
}
f. for(int k=1;k<=5; k++)
{
for(int J=1;j<=k; j++)
printf(“%d ”,k);
printf(“\n”);
}
g. for(int k=1;k>=5; k++)
{
for(int J=1;j<=5; j++)
printf(“%d ”,j*k);
printf(“\n”);
}
32. Rewrite the program in 31 above using WHILE and DO WHILE statements
33. Define the term Data Structures
34. Give a brief description of the following data structures
a. Arrays
b. Stack
c. List
35. Differentiate between passing by value and passing by reference as used in c programming giving
examples in each case
36. Explain two advantages of using arguments/ parameters when writing programs involving functions in
programming
37. Explain the importance of the following in relation to program development
a. Use of care
b. Choice of identifier
c. Indenting
d. Use of Sub Programs
38. With the aid of a C program illustrate the scope of Local and Global variables
39. Illustrate bubble sort using the following number
8 2 9 6 3 5 7 4
40. Illustrate selection sort using the following number
6 7 15 8 3 11 12
41. Explain advantage(s) of bubble sort over other sorting algorithms
42. Differentiate between the following sorting algorithms
43. Explain the reason why bubble sort algorithm is considered slow;
44. Compare and contrast between bubble and selection sort.
45. Draw flowcharts for bubble, selection and insertion sorting algorithms
46. Write algorithms to illustrate quick sort algorithm.
47. Explain three differences between binary search and sequential search algorithms
48. Draw a flowchart to illustrate searching for a number in an array of ten numbers.
49. Write an algorithm for binary search algorithm
50. Explain the main difference between bubble sort and selection sort algorithms
51. Distinguish between insertion sort and quick sort algorithms
52. Explain Three advantages of insertion sort over bubble and selection sort algorithms