Question
Create An Array Of 6x8 And Read Each Number Into The Array With The Following: Read Each Number Into One Dimension Of The Array Until
Create An Array Of 6x8 And Read Each Number Into The Array With The Following: Read Each Number Into One Dimension Of The Array Until You Hit 0 Then Move To The Next Set Example: After You Have Read The Numbers Into The 2-Dimensional
Create an array of 6x8 and read each number into the array with the following: read each number into one dimension of the array until you hit 0 then move to the next set Example:
After you have read the numbers into the 2-dimensional array totally, then sum them up and print out the sum
I have already written some code:
#include
int main(void){
char *file_name = \"\";
FILE *fptr = fopen(file_name, \"r\");
if(fptr == NULL){
printf(\"Error\");
return 1;
}
// declare the 2 dimensional array
int num;
int i = 0, j = 0;
while (fscanf(fptr, \"%d\", &num) == 1) {
// put the number in the array
if (num != 0) {
arr[i][j++] = num;
}
else {
arr[i++][j] = num;
j =0;
}
fclose(fptr);
}
int total_rows = i;
int sum = 0;
for (int i = 0; i
for (int j = 0; j
if (arr[i][j] != 0) {
sum += arr[i][j];
}
else {
//print the sum
sum = 0;
break;
}
}
}
return(0);
}
The txt file looks something like this:
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