1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170:
| /*Burak Ücöz 12.01.2010*/ /*Copyright*/
#include<stdio.h> #include<math.h>
/*Prototyp*/
int eingabe(); float volumen(); float grundflaeche(); float mantelflaeche(); float oberflaeche(); float rechne_optimal(); void ausgabe(float erg);
int main(void) /*Mainfunktion*/ { int auswahl, antwort; /*Variablen deklarieren*/ float ergebnis;
do /*Programm Schleife*/ { /*auswahl bestimmen*/ do { auswahl=eingabe(); antwort=0;
switch(auswahl) { /*Grundfläche*/ case 1: ergebnis=grundflaeche(); break; /*Mantelfläche*/ case 2: ergebnis=mantelflaeche(); break; /*Oberfläche*/ case 3: ergebnis=oberflaeche(); break; /*Volumen*/ case 4: ergebnis=volumen(); break; case 5: ergebnis=rechne_optimal(); /*Optimal Berechnung*/ break;
default: printf("\nSie haben eine falsche Eingabe gemacht\n\n"); /*Fehleingabe abfangen bei ungültiger Zahl*/ antwort=1; break; } } while(antwort==1);
ausgabe(ergebnis); /*Ausgabefunktion*/
printf("\n\nWollen Sie das Programm erneut starten? \n1: Ja!\n0: Nein!"); /*Neustarteingabe*/ scanf("%i", &antwort); fflush(stdin); } while(antwort==1);
}
/*Funktionen*/
int eingabe() { int eingabe;
printf("\n\nBitte suchen Sie sich aus was Sie berechnen moechten\n\n"); printf("Fuer Grundflaeche die\t\t\t[1]\n"); printf("Fuer Mantelflaeche die\t\t\t[2]\n"); printf("Fuer Oberflaeche die\t\t\t[3]\n"); printf("Fuer Volumen die\t\t\t[4]\n"); printf("Fuer Minimal Material verbaucht die \t[5]\n"); scanf("%i",&eingabe); fflush(stdin); return(eingabe); }
float volumen() /*Volumenberechnung*/ { float hoehe, radius; /*Variablendeklaration*/ float const pi=3.14159265;
printf("\nBitte geben Sie die Hoehe an:\t"); /*Eingabe Höhe*/ scanf("%f", &hoehe); fflush(stdin); printf("\nBitte geben Sie den Radius an:\t"); /*Eingabe Radius*/ scanf("%f", &radius); fflush(stdin);
return(radius*radius*pi*hoehe); }
float grundflaeche() /*Grundflächenberechnung*/ { float radius; /*Variablendeklaration*/ float const pi=3.14159265;
printf("\nBitte geben Sie den Radius an:\t"); /*Eingabe Radius*/ scanf("%f", &radius); fflush(stdin);
return(radius*radius*pi); }
float mantelflaeche() /*Mantelflächenberechnung*/ { float hoehe, radius; /*Variablendeklaration*/ float const pi=3.14159265;
printf("\nBitte geben Sie die Hoehe an:\t"); /*Eingabe Höhe*/ scanf("%f", &hoehe); fflush(stdin); printf("\nBitte geben Sie den Radius an:\t"); /*Eingabe Radius*/ scanf("%f", &radius); fflush(stdin);
return(2.0*radius*pi*hoehe); }
float oberflaeche() /*Oberflächenberechnung*/ { float hoehe, radius; /*Variablendeklaration*/ float const pi=3.14159265;
printf("\nBitte geben Sie die Hoehe an:\t"); /*Eingabe Höhe*/ scanf("%f", &hoehe); fflush(stdin); printf("\nBitte geben Sie den Radius an:\t"); /*Eingabe Radius*/ scanf("%f", &radius); fflush(stdin);
return(2.0*radius*pi*hoehe+2*radius*radius*pi); }
float rechne_optimal(int volumen) /*Optimale Material Vebrauch*/ { float radius=1; float volumen1; float oberflaeche; float oberflaeche2; float pi=3.14; volumen1=volumen; do { oberflaeche=2*3.14*radius*radius+2*3.14*radius*(volumen1/(3.14*radius*radius)); radius=radius+0.01; oberflaeche2=2*3.14*radius*radius+2*3.14*radius*(volumen1/(3.14*radius*radius)); } while(oberflaeche>=oberflaeche2); return(radius); }
void ausgabe(float erg) /*Ausgabefunktion*/ { printf("\n\nDas Ergebnis ist: %f\n\n", erg); /*Ergebnisausgabe*/ } |