User:Bronkid23

  1. include <stdio.h>
  2. include <stdlib.h>
  3. include <ctype.h>
  4. define NUM_COL 3
  5. define NUM_ROW 10


void header(void); char again(void); void findmean(int[][NUM_COL]); void findmax(int[][NUM_COL]);

int main() {

char doagain='y';

       while (toupper(doagain) == 'Y')
       {
       int thearray[NUM_ROW][NUM_COL];

header();

int i,j,mean; int a; FILE *infpt; char filename[30]; printf("enter the name of the file: "); fflush(stdin); scanf(" %s",filename); infpt=fopen(filename,"r"); if (infpt == 0) { printf("that's not a file. Try again please: "); doagain='y'; continue; }

for (i=0;i<NUM_COL;i++) //read in data { for (j=0;j<NUM_ROW;j++) { //fflush(stdin); fscanf(infpt," %d",&thearray[i][j]); //printf("thearray[%d][%d] is %d\n", i, j, thearray[i][j]); } }

findmean(thearray); findmax(thearray);

        doagain=again();
       }

system("pause"); printf("\n\n\n"); }

void header(void) {

       printf("this is a header\n\n");

}



void findmean(int a[][NUM_COL] ) { int sum1=0,sum2=0,mean1=0,mean2=0; int k; for (k=0;k<NUM_ROW;k++) { sum1=sum1 + a[k][1]; sum2=sum2 + a[k][2]; } mean1=sum1/NUM_COL; mean2=sum2/NUM_COL;

if (mean1>=mean2) { printf("the second column is larger than the third\n"); printf("the vaule is %d\n",mean1); } else { printf("the third column is larger than the second\n"); printf("the value is %d\n",mean2); } return; }

void findmax(int b[][NUM_COL]) { int max=0,m,n,max_pos=0; for (m=0;m<NUM_ROW;m++) { if (b[m][1]>max) { max=b[m][1]; max_pos=m+1;

} } printf("the max of colum 2 is %d\tthe position is: [%d][2]",max,max_pos); }



char again(void) {

       char doagain;
       do
       {
        printf("would you like to run the program again(y/n)?\n\n");
       fflush(stdin);
       scanf("%c",&doagain);
               }
       while (toupper(doagain) != 'Y' && toupper(doagain) != 'N');
               return(doagain);

}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.