0% found this document useful (0 votes)
25 views4 pages

In Class

The document contains a C program that calculates the sum of rows and columns in a 3x3 pressure matrix and identifies abnormal voltage levels in a list of ten voltage readings. It outputs the total of each row and column, the average voltage, and lists the abnormal cells based on specified voltage thresholds. The program successfully identifies three abnormal cells and displays the results.

Uploaded by

mosesdayes
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)
25 views4 pages

In Class

The document contains a C program that calculates the sum of rows and columns in a 3x3 pressure matrix and identifies abnormal voltage levels in a list of ten voltage readings. It outputs the total of each row and column, the average voltage, and lists the abnormal cells based on specified voltage thresholds. The program successfully identifies three abnormal cells and displays the results.

Uploaded by

mosesdayes
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

Dayes Moses

In-Class assignment 4

#include <stdio.h>

int main() {
int pressure[3][3] = {
{40, 100, 60},
{16, 90, 41},
{78, 20, 12}
};

int rowSum[3] = {0}, colSum[3] = {0};

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


for (int j = 0; j < 3; j++) {
rowSum[i] += pressure[i][j];
colSum[j] += pressure[i][j];
}
}
printf("The Total Of Rows is :\n");
for (int i = 0; i < 3; i++) {
printf("Row %d: %d\n", i + 1, rowSum[i],"\n");
}

printf("\nThe Total Of Columns is :\n");


for (int j = 0; j < 3; j++) {
printf("Column %d: %d\n", j + 1, colSum[j]);
}

//QUESTION 2

float voltages[10] = {3.7, 4.0, 2.9, 3.5, 4.3, 3.8, 3.1, 4.2, 2.0, 4.05};
float *ptr = voltages;
float sum = 0;
int abn_count = 0;

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


sum += *(ptr + i);
}
float average = sum / 10;
printf("Average Voltage: %.2fV\n", average);

printf("\nAbnormal Cells:\n");
for (int i = 0; i < 10; i++) {
float v = *(ptr + i);
if (v < 3.0 || v > 4.2) {
printf("Cell %d: %.2fV\n", i, v);
abn_count++;
}
}

printf("\nThe Total Number of Abnormal Cells is: %d\n", abn_count);

return 0;
}

Answer:
The Total Of Rows is :
Row 1: 200
Row 2: 147
Row 3: 110
The Total Of Columns is :
Column 1: 134
Column 2: 210
Column 3: 113
Average Voltage: 3.55V

Abnormal Cells:
Cell 2: 2.90V
Cell 4: 4.30V
Cell 8: 2.00V
The Total Number of Abnormal Cells is: 3

=== Code Execution Successful ===

You might also like