Commit e9aa324b by Mario Mihkelson

essa praktikum

parents
#include <stdlib.h>
#include <stdio.h>
#define P 10
void sisse(int N, int AA[]);
int arvut(int n, int av[]);
void failiarv(char nim[], int as[]);
int main()
{
int a, b, S = 0, i, v, juht;
int A[P];
printf("Palun sisestagesisestuse valikujuht-\n 0-pohipr, 1-alampr, 2-failist \nja liidetavate arv\n");
scanf("%d \n %d", &juht, &v);
if(juht == 0)
{
printf("Palun sisestage liidetavad a ja b");
scanf("%d %d", &a, &b);
S = a + b;
for(i = 0; i < v; i++)
{
printf("Palun sisestage liidetavad A[%d]\n", i);
scanf("%d", &A[i]);
printf("%d\n", A [i]);
S = S + A[i];
}
}
if(juht == 1)
{
sisse(v, A);
}
if(juht == 2)
{
printf("Sisestan liidetavad failist\n");
failiarv("numbrid.txt", A);
S = arvut(v, A);
printf("%d\n", S);
}
return 0;
}
void failiarv(char nim[], int as[])
{
int i;
FILE *fi;
fi = fopen("nim.txt", "r");
for(i = 0; i < 4; i++)
{
fscanf(fi, "%d", &as[i]);
}
}
void sisse(int N, int AA[P])
{
int i;
for(i = 0; i < 4; i++)
{
printf("Palun sisestage liidetavad AA[%d]\n", i);
scanf("%d", &AA[i]);
}
}
int arvut(int n, int av[P])
{
int i, abi = 0;
for(i = 0; i < n; i++)
{
abi = abi + av[i];
}
return(abi);
}
File added
kakdatuuuuuu
\ No newline at end of file
55
66
\ No newline at end of file
#include<stdio.h>
typedef struct { int N;
int MATR[25];
double SP[25];
} andmed;
andmed sisesta_andmed()
{
andmed x;
int j;
do
{
printf("tudengite arv (1...25) =");
scanf("%d",&x.N);
}
while((x.N<1)||(x.N>25));
for (j=0;j<x.N;j++)
{ do printf("%d. tudengi matrikli number on ",j);
while(( scanf("%d",&x.MATR[j])<0));
do printf("%d keskmine hinne (0...5) on ",x.MATR[j]);
while (5 < (scanf("%lf", &x. SP[j])));
}
return (x);
}
int max_hinne(y)
andmed y;
{
int k,max;
max=0;
for (k=0;k<y.N;k++) if (y.SP[max]<y.SP[k]) max=k;
return (max);
}
int main()
{
andmed ryhm;
int i,EDUK,tun;
ryhm=sisesta_andmed();
for(i=0;i<ryhm.N;i++)
printf("%d tudengi matrikkli nr on %d ja keskmine pall on %4.2lf\n",i,ryhm.MATR[i],ryhm.SP[i]);
EDUK=max_hinne(ryhm);
printf("Edukas on %d ja tema keskmine hinne = %4.2lf . \n",ryhm.MATR[EDUK],ryhm.SP[EDUK]);
scanf("%d", &tun);
getchar();
getchar();
return(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment