nilai maksimum, minimum, dan rata

#include
main()
{
int arr[100], i, n, max=-999, min=999, x, j, k;
float total=0, rata;
printf("Masukkan jumlah data (maks. 100) = ");
scanf("%d",&n);
for(i=0;i printf("Data ke-%d = ",i+1);
scanf("%d",&arr[i]);
}

//menentukan nilai max
for(x=0;x if (arr[x]>max){
max=arr[x];
}
}
printf("\nNilai Maksimum= %d",max);

//menentukan nilai min
for (j=0;j if (arr[j] min=arr[j];
}
}
printf("\nNilai Minimum= %d",min);

//menentukan rata2
for (k=0;k total+=arr[k];
}
printf ("\nJumlah =%2.2f",total);
rata=total/n;
printf("\nRata-rata=%2.2f",rata);

return 0;
}

CONTOH MATRIKS

/*meitanisyah_G64090021*/

#include
main()
{
int i=1,j=1;
int m, n;
int k, l;
int z[100][100], x[100][100], c[100][100] ;
int jumlah=0;
printf("matriks z");
printf(" ukuran matriks (mxn) = ");
scanf("%d %d", &m, &n );
printf("matriks x");
printf(" ukuran matriks (kxl) = ");
scanf("%d %d", &k, &l );
if (m==k && n==l)
{
printf("\nmasukkan data matriks z\n");
for (i=1; i<=m; i++) // masukkan data matriks Z
for (j=1; j<=n; j++){
scanf("%d", &z[i][j]);}
printf("\nmasukkan data matriks x\n");
for (i=1; i<=k; i++) // masukkan data matriks X
for (j=1; j<=l; j++){
scanf("%d", &x[i][j]); }
printf("\nhasil penjumlahan kedua matriks \n");
for(i=1; i<=m; i++){
for(j=1; j<=n; j++){
c[m][n] = z[i][j] + x[i][j]; //Proses Penjumlahan Matriks
printf("%d", c[m][n]);
printf(" "); }
printf("\n");
}

}
else { printf("error");}
return 0;
}

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme