Question
Programming C Two dimensional Arrays, String, Passing Two dimensional array as argument to function, loops Problem Description: Write a program that assigns the following data
Programming C
Two dimensional Arrays, String, Passing Two dimensional array as argument to function, loops
Problem Description:
Write a program that assigns the following data to a two dimensional Array then displays the Array with average of each row in a table format and the total of all element and total of elements in both diagonals.
Program first must ask for a code to continue. The code is A23bc5, case sensitive. The program must keep asking for code until the correct code is entered.
23.5 30.1 56.2 11.9
45.1 8.9 77.3 54.1
6.6 7.7 8.8 2.2
9.9 8.9 7.8 23.6
Sample output:
Avg.
23.5 30.1 56.2 11.9 30.4
45.1 8.9 77.3 54.1 .
6.6 7.7 8.8 2.2 .
9.9 8.9 7.8 23.6 ..
Total of both diagonals is: 171.6
Total of element in list: ????
Requirement
Must use two dimensional Array
Must create constants for size of the array
Must have 3 functions, one to calculate the total of all elements and one to calculate total of both diagonals (Must pass the two dimensional array to each function to do the calculation), and one to check for the correct code.
I've got this far, now im stuck
-------------------------------------------------------
#include
#include
#define ROW 4 /* Constant for Rows */
#define COLUM 4 /* Constant for Colum */
#define PASS 6
double passfun(key1);
double average(double s1_array[ROW][COLUM]);
double average1(double s1_array[ROW][COLUM],int R);
int main()
{
double s1_array[ROW][COLUM] = { /* Defining arrays */
{ 23.5, 30.1, 56.2, 11.9},
{ 45.1, 8.9, 77.3, 54.1},
{ 6.6, 7.7, 8.8, 2.2},
{ 9.9, 8.9, 7.8, 23.6}
};
double diag, tot1;
int word;
char password[PASS] = {'A','2','3','b','c','5'}; /* declaring password */
word = passfun(password); /* calling password function */
diag = average(s1_array); /* calling diagonal function */
tot1 = average1(s1_array,R);
}
double passfun(char password[ROW][COLUM]) /* function for password */
{
char input[PASS];
do{
printf("Enter the password to proceed."); /* do while loop for password */
scanf("%s", input);
fflush (stdout);
} while (strcmp (input, password) !=0);
printf("Correct Answer");
}
double average1(double s1_array, int R)
{
double tot=0.0;
int j;
for (j=0, j < ROW, j++){
tot+=s1_array[R][j]
}
return tot/4;
}
double average(double s1_array)
{
double i,j;
for(i=0,i < ROW; i++)
for(j=0, j < COLUM; j++){
printf("%f", s1_array[][])
}
printf("%f/n", average1(ROW, COLUM))
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started