0% found this document useful (0 votes)
23 views6 pages

Lab Exercise Week 11 - Danial Sharil

This document contains code for 3 exercises involving arrays and matrices in C programming language. The first exercise calculates student marks and finds the highest scoring student. The second exercise determines employee bonuses based on years of service. The third exercise performs addition and subtraction on 2D integer matrices and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Lab Exercise Week 11 - Danial Sharil

This document contains code for 3 exercises involving arrays and matrices in C programming language. The first exercise calculates student marks and finds the highest scoring student. The second exercise determines employee bonuses based on years of service. The third exercise performs addition and subtraction on 2D integer matrices and prints the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

MUHAMMAD DANIAL BIN SHARIL

2021881608

PI009E33

EXERCISE 1
#include <stdio.h>

float CalculateMark(float a, float b, float c, float d);


void AnalyzeMark(float mark[], char student[][40]);

int main() {
char name[10][40];
float assg[10], project[10], midterm[10], final[10], total [10];

for (int i = 0; i<10; i++){


printf ("Enter Student name: ");
scanf("%s", name[i]);
printf("Enter Assignment, Project, Midterm and Final exam marks : ");
scanf("%f %f %f %f", &assg[i], &project[i], &midterm[i], &final[i]);}

for (int i = 0; i<10 ; i++){


total[i] = CalculateMark(assg[i], project[i], midterm[i], final[i]);}

for (int i = 0; i < 10; i++) {


printf ("%s\t", name[i]);
printf ("%.2f\n", total[i]);
}
printf("\n");
AnalyzeMark(total, name);

return 0;
}

float CalculateMark(float a, float b, float c, float d) {


float total;
total = a + b + c + d;
return total;
}

void AnalyzeMark(float mark[10], char student[10][40]){


int best = 0;
float highest = 0, sum = 0;
for (int i = 0; i < 10; i++){
if (mark[i] > highest){
highest = mark[i];
best = i;
}
sum += mark[i];
}
printf("Average mark : %.2f\n", sum/10);
printf("Best student is %s with %.2f mark.", student[best], mark[best]);
}
EXERCISE 2
#include <stdio.h>
void displayBonus(int a);

int main()
{
int yrService[5];
int i, j=1;

for (i=0;i<5;i++){
printf("EnterThe Year of Service Employee %d: ", j);
scanf("%d",&yrService[i]);
displayBonus(yrService[i]);
j++;
}

}
void displayBonus(int a)
{ if (a>10)
printf ("3 Month Bonus\n\n");

else
printf ("One Month Bonus\n\n");
EXERCISE 3
#include <stdio.h>
void MatAdd(int matrix1 [4][3], int matrix2 [4][3]);
void MatSub(int matrix1 [4][3], int matrix2 [4][3]);

int main() {

char choose;
int matrix1 [4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
int matrix2 [4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
int i, j;

printf("First Matrix \n");


for(i=0; i<4; i++) {
for(j=0; j<3; j++){
printf("%d\t ",matrix1[i][j]);}
printf("\n");}

printf("\nSecond Matrix \n");


for(i=0; i<4; i++){
for(j=0; j<3; j++){
printf("%d\t", matrix2[i][j]);}
printf("\n"); }

printf("\nChoose an Operation\n");
printf("A - Addition\n");
printf("B - Subtraction\n");
scanf("%c",&choose);
printf("\n");

if (choose == 'A'){
printf("Addition Matrix is\n");
MatAdd(matrix1, matrix2);}

else if (choose == 'B'){


printf("Subtraction Matrix is\n");
MatSub(matrix1,matrix2);}

else printf("Invalid Input");}

void MatAdd (int matrix1 [4][3],int matrix2 [4][3]) {


int i, j;
int addition[4][3];
for(i=0;i<4;i++){
for(j=0; j<3; j++){
addition[i][j] = (matrix1[i][j]) + (matrix2 [i][j]);
printf("%d\t", addition[i][j]); }
printf("\n"); }}

void MatSub(int matrix1 [4][3], int matrix2 [4][3]) {


int i, j;
int subtraction[4][3];
for(i=0;i<4;i++){
for(j=0; j<3; j++){ subtraction[i][j] = (matrix2[i][j]) - (matrix1 [i][j]);
printf("%d\t", subtraction[i][j]); }
printf("\n"); }
}

You might also like