Professional Documents
Culture Documents
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void guessgame(void);
int main(void){
srand(time(NULL));
guessgame();
}
void guessgame(void)
{
int x;
int play;
char guess;
do{
x = 65 + rand() % 25;
printf("Please enter a letter from A to Z\n");
scanf("\n%c", &guess);
while (guess != x){
if (guess < x)
printf("Too low! Please try again:\n");
else
printf("Too high! Please try again:\n");
scanf(" %c", &guess);
}
printf("Great! Your guess is right\n");
printf("Would you like to play again?\n");
printf("Please Enter 1 for Yes and 2 For No:\n");
scanf("%d", &play);
} while (play == 1);
}
//Tutorial 5 qns 4
#include <stdio.h>
#define size 9
void printcomission(double c[], int w);
int main(void)
{
double b, f; // sales amount
double a[30] = { 0 }; // to store sales amount
size_t i;
int m; // number of employee
printf("Please enter the number of employees to be calculated, maximum 3
0 employee:\n");
scanf("%d", &m);
printf("Please enter the sales amount of the first employee:\n");
scanf("%lf", &b);
a[0] = b;
for(i = 1; i < m; ++i){
++count[sum];
}
printf("Roll sum\tNumber of times\n");
for (i = 0; i <= 12; ++i){
printf("%4d%17d\n", i, count[i]);
}
}
//tutorial 5 qns 7
#include <stdio.h>
#define MAX 40
int main(void){
int a[40] = { 1, 2, 6, 4, 8, 5, 9, 7, 8, 10, 1, 6, 3, 8, 6, 10, 3, 8, 2,
7,
6, 5, 7, 6, 8, 6, 7, 5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 };
int b[10] = { 0 };
size_t i;
size_t pass;
int hold;
size_t e;
int k = 0;
for (pass = 1; pass < 40; ++pass){
for (i = 0; i < 39; ++i){
if (a[i]>a[i + 1]){
hold = a[i];
a[i] = a[i + 1];
a[i + 1] = hold;
}
}
}
printf("The newly sort array is:\n");
for (i = 0; i < 40; ++i){
printf("%d", a[i]);
}
puts("");
for (i = 0; i < 40; ++i){
switch (a[i]){
case 1:
++b[0];
break;
case 2:
++b[1];
break;
case 3:
++b[2];
break;
case 4:
++b[3];
break;
case 5:
++b[4];
break;
case 6:
++b[5];
break;
case 7:
++b[6];
break;
case 8:
++b[7];
break;
case 9:
++b[8];
break;
case 10:
++b[9];
break;
}
}
printf("Response\tVaue\tHistogram\n");
for (e = 1; e <= 10; ++e){
printf("%d\t\t%d\t", e, b[e - 1]);
for (i = 0; i < b[k];++i){
printf("*");
}
// Tutorial 5 qns 8
#include <stdio.h>
void printheader(void);
int main(void){
int total=0;
int a[4][5] = { 0 };
size_t i;
size_t j;
printf("Please enter the number of product sold by the salesperson,start
ing with p0 to p4.\n");
printf("Press enter after each entry.\n");
for (i = 0; i <= 3; ++i){
for (j = 0; j <= 4; ++j){
scanf("%d", &a[i][j]);
}
if (i == 3){
break;
}
printf("Please enter the sales detail of the next salesperson.\n
");
}
printheader();
for (j = 0; j <= 3; ++j){
printf("%d\t\t", j);
for (i = 0; i <= 4; ++i){
printf("%d\t", a[j][i]);
total += a[j][i];
}
printf("%d\n", total);
total = 0;
}
total = 0;
printf("\t");
for (j = 0; j <= 4; ++j){
for (i = 0; i <= 3; ++i){
total += a[i][j];
}
printf("\t%d", total);
total = 0;
}
puts("");
}
void printheader(void){
int i;
printf("Salesperson");
//printf("\t\t");
for (i = 0; i <= 4; ++i){
printf("\tp%d", i);
}
puts("");
}