Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void beolvas(double* tomb);
- void kiir(double* tomb);
- void avgc(double* tomb);
- void minimax(double* tomb);
- void avgelter(double* tomb,double atlg);
- int main() {
- double asd[100];
- beolvas(asd);
- kiir(asd);
- avgc(asd);
- minimax(asd);
- printf("Kerem adjon meg egy atlagot amelyre kivanja vizsgalni az elemeket:");
- double atl;
- scanf_s("%lf", &atl);
- avgelter(asd, atl);
- }
- void beolvas(double* tomb) {
- double bekert;
- int ok = 0, i = 0;
- do {
- printf("Kérem adjon meg 3 értéket.\n");
- for (i = 0; i < 3;)
- {
- scanf_s("%lf", &bekert);
- if (bekert > 0 && bekert <= 50) {
- tomb[i] = bekert;
- ok = 1;
- i++;
- }
- else {
- printf("Error! Kérem adjon meg masik adatot:\n");
- ok = 0;
- }
- }
- } while (ok != 0 && i != 3);
- }
- void kiir(double* tomb) {
- printf("A tomb elemei:\n");
- for (int j = 0; j < 3; j++)
- {
- printf("%.2lf\n", tomb[j]);
- }
- }
- void avgc(double* tomb) {
- double avg = 0, sum = 0, db = 0;
- for (int i = 0; i < 3; i++)
- {
- sum = sum + tomb[i];
- }
- avg = sum / 3;
- printf("A tomb elemeinek alaga: %.3lf\n", avg);
- }
- void minimax(double* tomb) {
- double min = tomb[0], max = tomb[0];
- for (int i = 0; i < 3; i++)
- {
- if (max < tomb[i]) {
- max = tomb[i];
- }
- if (min > tomb[i])
- {
- min = tomb[i];
- }
- }
- printf("A tomb legkissebb eleme:%.2lf\nA tomb legnagyobb eleme:%.2lf\n", min, max);
- }
- void avgelter(double* tomb, double atlg) {
- printf("A tomb elemeinek atlagtol valo elterese:\n");
- for (int i = 0; i < 3; i++) {
- double szam = tomb[i] - atlg;
- if (szam > 0) {
- printf("+%.1lf,", szam);
- }
- if (szam < 0) {
- printf("%.1lf,", szam);
- }
- if (szam == 0)
- {
- printf("%.1lf\n", szam);
- }
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement