Skip to content

Commit 39c52fc

Browse files
authored
Create 1. Elephant Seals.txt
1 parent b2476c6 commit 39c52fc

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
************************************************************************************
2+
Q. Compute the average weight for a population of elephant seals read into an array.
3+
************************************************************************************
4+
5+
6+
#include <stdio.h>
7+
#include <math.h>
8+
#include <malloc.h>
9+
#include <stdlib.h>
10+
11+
double average(int row,int column,int mat[row][column])
12+
{
13+
14+
int a;
15+
int b;
16+
double sum=0.0;
17+
int t = 1000;
18+
19+
for(a=0;a<row;a++)
20+
{
21+
for(b=0;b<column;b++)
22+
{
23+
sum+=mat[a][b];
24+
}
25+
}
26+
return(sum/t);
27+
28+
}
29+
30+
int main()
31+
32+
{
33+
34+
int i;
35+
int j;
36+
int r=50;
37+
int col=20;
38+
FILE *file;
39+
40+
int** mat=malloc(r*sizeof(int*));
41+
42+
for(i=0;i<r;++i)
43+
{
44+
mat[i]=malloc(r*sizeof(int));
45+
}
46+
47+
file=fopen("data.txt", "r");/*Text file consisting of raw data in 50 rows and 20 columns*/
48+
49+
for(i = 0; i < 1000; i++)
50+
{
51+
for(j = 0; j <col; j++)
52+
{
53+
if (!fscanf(file, "%d", &mat[i][j]))
54+
break;
55+
printf("%d\t",mat[i][j]);
56+
57+
if(j==col-1)
58+
{
59+
printf("\n\n");
60+
}
61+
62+
printf("Average of elephant seal is %.2f\n\n",average(r,col,mat));
63+
}
64+
}
65+
66+
fclose(file);
67+
return 0;
68+
69+
}
70+
71+
72+
73+
~ TSG405, 2021

0 commit comments

Comments
 (0)