|
Birden cok subscripti olan arrayler
/*Ikilenmis subscript array ornegi*/
#include
#define OGRENCILER 3
#define SINAV 4
int endusuk(int [][SINAV], int, int);
int enyuksek(int [][SINAV], int, int);
float ortalama(int [], int);
void ArrayYaz(int [][SINAV], int, int);
main()
{
int ogrenci ,
ogrenciNotlari[OGRENCILER][SINAV] = { {77, 68, 86, 73}, {96, 87, 89, 78},
{70, 90, 86, 81}};
printf("Array:\n");
ArrayYaz(ogrenciNotlari, OGRENCILER, SINAV);
printf("\n\n"En Dusuk Not:%d\n", En Yuksek Not:
%d\n",
endusuk(ogrenciNotlari, OGRENCILER, SINAV),
enyuksek(ogrenciNotlari, OGRENCILER, SINAV);
for(ogrenci = 0; ogrenci <= OGRENCILER -1; ogrenci++)
printf("Ogrenci %d icin ortalama not: %.2f\n",
ogrenci, ortalama(ogrenciNotlari[ogrenci], SINAV));
return(0);
}
/*en dusuk notu bul*/
int endusuk(int notlar[][SINAV], int ogrenciler, int testler)
{
int i, j, dusukNot = 100;
for(i = 0; i <= ogrenciler - 1; i++)
for(j = 0; j <= testler -1; j++)
if(notlar[i][j] <
dusukNot)
dusukNot =
notlar[i][j];
return(dusukNot);
}
/*En yuksek notu bul*/
int enyuksek(int notlar[][SINAV], int ogrenciler, int testler)
{
int i, j , yuksekNot = 0;
for(i = 0; i <= ogrenciler - 1; i++)
for(j = 0; j <=testler - 1; j++)
if(notalar[i][j] > yuksekNot)
yuksekNot
= notlar[i][j];
return(yuksekNot);
}
/*ortalam not hesaplama*/
float ortalama(int toplamNot[], int testler)
{
int i, toplam = 0;
for(i = 0; i <= testler -1; i++)
toplam += toplamNot[i];
return(float) toplam / testler;
}
/*Ciktisini Al */
void ArrayYaz(int notlar[][SINAV], int ogrenciler, int testler)
{
int i, j;
printf("
[0] [1] [2] [3]");
for(i = 0; i<=ogrenciler -1; i++)
{
printf("\nogrenciNotlari[%d] ", i);
for(j = 0; j <=testler - 1; j++)
printf("%-5d",
notlar[i][j]);
}
}
|