- Program 1
Write a C function void product (int a, int b)
prints one line in multiplication table: a*1 a*2 a*3 ....a*b.
The results suppose to be printed in one line with tab space between the values.
For example, if the parameters are 3 and 4 the function prints:
3     6     9    12
Write a program that prints the multiplication table m X m, where m is an input value.
Solution:
#include <stdio.h>
void product (int a, int b); /* function prototype */
int main(){
int i, m;
scanf("%d", &m)
for (i = 1; i <= m; i++){
product (i, m);
printf("\n");
}
return 0;
}
/* function definition */
void product (int a, int b){
int i;
for (i = 1; i <= b; i++){
}
}
- Program 2
Write a function void printStar (int num) that prints one line of *, the amount of stars
in the line should be equal to the value of the parameter num.
For example
if num = 3,
function prints ***,
if num = 5 , function prints *****.
Write a program that will print the following tringle:
*
**
***
****
*****
******
.....
*******...***
where the amount of lines and the amount of stars in the last line equals to the input value.
Solution:
#include <stdio.h>
void printStar (int num); /* function prototype */
int main(){
int i, m;
scanf("%d", &m)
for (i = 1; i <= m; i++){
printStar ( i );
printf("\n");
}
return 0;
}
/* function definition */
void printStar (int num){
int i;
for (i = 1; i <= num; i++){
}
}
- Program 3 -
random number generator
#include <stdio.h>
#include <stdlib.h>       /* for prototype of function rand( ) */
int main( ){
}
the output:
2     5     4     2     6
2     5     1     4     2
3     2     3     2     6
5     1     1     5     5
- Program 4 - random number generator
#include <stdio.h>
#include <stdlib.h>       /* for rand and srand functions */
int main( ){
int i;
unsigned seed; /* number used to seed the random number generator */
printf("Enter the seed: ");
scanf("%u", &seed);
srand(seed); /* seed the random number generator */
for (i = 1; i <= 20; i++){
}
return 0;
}
- Program 5 - random number generator
#include <stdio.h>
#include <stdlib.h>       /* for rand and srand functions */
int main( ){
}