Papa 194 51
Uniform 189 85
Sierra 187 87
Whiskey 195 45
Zulu 184 55
Juliet 177 88
Quebec 175 68
Tango 157 96
Kilo 173 79
Xray 156 89
#include <stdio.h>
#include <ctype.h>
#include "bmi_util.h"
#define MAXSTUDENT 50
int main()
{
Student stu[MAXSTUDENT];
char ch;
unsigned nStu;
while ((ch = get_choice())) {
ch = toupper(ch);
switch (ch) {
case 'Q':
return 0;
case 'L': /* Load file */
nStu = load_student(stu);
break;
case 'S':
store_student(stu, nStu);
break;
case 'P':
print_student(stu, nStu);
break;
case 'H':
sort_by_height(stu, nStu);
break;
case 'W':
sort_by_weight(stu, nStu);
break;
case 'N':
sort_by_name(stu, nStu);
break;
case 'B':
sort_by_bmi(stu, nStu);
break;
default:
printf("No such choice!\n");
break;
}
}
return 0;
}
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- L
Pleaes input filename -- student.dat
10 records have been read.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- P
Whiskey 195 45 11.83
Papa 194 51 13.55
Zulu 184 55 16.25
Quebec 175 68 22.20
Kilo 173 79 26.40
Uniform 189 85 23.80
Sierra 187 87 24.88
Juliet 177 88 28.09
Xray 156 89 36.57
Tango 157 96 38.95
Totally 10 records.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- H
10 records sorted by height in ascending order.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- P
Xray 156 89 36.57
Tango 157 96 38.95
Kilo 173 79 26.40
Quebec 175 68 22.20
Juliet 177 88 28.09
Zulu 184 55 16.25
Sierra 187 87 24.88
Uniform 189 85 23.80
Papa 194 51 13.55
Whiskey 195 45 11.83
Totally 10 records.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- B
10 records sorted by BMI in ascending order.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- S
Pleaes input filename -- bmi.dat
10 records written.
L)oad student data from a file
S)tore student data to a file
P)rint student data on screen
Q)uit
Sort by H)eight
Sort by N)ame
Sort by W)eight
Sort by B)MI
Please choose an action and press ENTER -- Q
Whiskey 195 45
Papa 194 51
Zulu 184 55
Quebec 175 68
Uniform 189 85
Sierra 187 87
Kilo 173 79
Juliet 177 88
Xray 156 89
Tango 157 96
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "rational_util.h"
int main()
{
Rational A[N][N], B[N][N], C[N][N];
int k, m, n;
read_2_int(&m, &n);
read_matrix(A, m, n);
read_matrix(B, m, n);
add_matrix(A, B, C, m, n);
print_matrix(C, m, n);
printf("\n");
read_3_int(&m, &k, &n);
read_matrix(A, m, k);
read_matrix(B, k, n);
mul_matrix(A, B, C, m, k, n);
print_matrix(C, m, n);
return 0;
}
#define N 10
#define TRUE 1
#define FALSE 0
typedef int bool;
struct Rational {
int numerator;
int denominator;
};
typedef struct Rational Rational;
Rational read_rational();
void print_rational(Rational a);
int gcd(int a, int b);
void reduce(Rational *a);
void reduce_rational(Rational *a);
Rational mul_rational(Rational a, Rational b);
Rational add_rational(Rational a, Rational b);
bool read_matrix(Rational A[][N], int m, int n);
void print_matrix(Rational A[][N], int m, int n);
void add_matrix(Rational A[][N], Rational B[][N], Rational C[][N], int m,
int n);
void mul_matrix(Rational A[][N], Rational B[][N], Rational C[][N], int m,
int k, int n);
int read_2_int(int *a, int *b);
int read_3_int(int *a, int *b, int *c);
3 2
1/2 1/2
1/1 1/6
3/10 1/24
1/2 1/3
1/2 1/3
1/5 1/36
2 3 2
1 2 3
2 4 6
1 1/3
1/2 1/2
1/3 1
^Z
^Z
^Z
the program should generate the following output:
1 5/6
3/2 1/2
1/2 5/72
3 13/3
6 26/3