Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "hilfe.h"
- #include <string.h>
- double average(double arr[][3], int länge);
- double minimum(double arr[][3], int länge);
- int main(){
- double length[MAX_DATA];
- int n = 0;
- double input;
- char unit[2];
- //Intro
- printf(" == Length Converter == ");
- printf("\n\nPlease provide the number of records(max 100) you want to enter: ");
- scanf("%d", &n);
- //Fehlerhandling n<= 0
- if(n > MAX_DATA || n <= 0){
- printf("Error: Please check the number of records you want to enter\n");
- return EXIT_FAILURE;
- }
- //Dekleration von Double Array für Werte und für Meterwerte
- double records[n][3];
- double meterwerte[n];
- int i;
- for(i = 0; i < n; i++){
- printf("Entry %d : <length> <unit>\n" , i+1);
- scanf("%lf %s",&input,&unit[0]);
- // Usereingabe
- // Usereingabe (Zahl) in Tabelle Spalte 1 schreiben
- records[i][0] = input;
- // Usereingabe (String) in Tabelle Spalte 2 codiert als Double ( 0.00 = mm,..)
- // Überprüfen der Einheit und schreiben in Spalte 3 (in m)
- if(strcmp(unit, "mm") ==0){
- records[i][1] = 0;
- records[i][2] = input/1000;
- }else if(strcmp(unit, "cm") ==0){
- records[i][2] = input/100;
- records[i][1] = 1;
- }else if(strcmp(unit, "dm") ==0){
- records[i][2] = input/10;
- records[i][1] = 2;
- }else if(strcmp(unit, "km") ==0){
- records[i][2] = input * 1000;
- records[i][1] = 3;
- }
- printf("%lf m\n", records[i][2]);
- }
- // for(int i = 0; i < n; i++){
- // meterwerte[i] = records[i][2];
- // }
- puts("\n--------");
- printf("Average: %6.3lf m\n",average(records,n));
- printf("Minimum: %6.3lf m\n", minimum(records,n));
- puts("");
- return 1;
- }
- double average(double arr[][3], int länge){
- double ret = 0;
- int i;
- for(i = 0; i < länge; i++){
- ret += arr[i][2];
- }
- return ret /= länge;
- }
- double minimum(double arr[][3], int länge){
- double min = arr[0][2];
- for(int i = 1; i < länge; i++){
- if(arr[i][2] < min){
- min = arr[i][2];
- }
- }
- return min;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement