/* * heron.c * * Copyright 2014 Martin Putzlocher * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ #include int main(int argc, char **argv) { printf("--- Quadratwurzelberechnung nach HERON ---\n"); int r; double x; double y; // Daten einlesen printf("Bitte Radikand angeben: "); scanf("%d", &r); printf("Bitte Startwert angeben: "); scanf("%lf", &x); // Los geht's... printf("> Berechne Quadratwurzel von %d \n", r); // Beschriftung printf("> Schritt | Wert \n"); // Initialisierung Schleifenzaehler int i =0; // Beginn Schleife while((x-y)>=0.0){ // Andere Kantenlaenge y = r / x; // Mittelwert bilden -> neues x x = (x+y)/2.0; // Ausgabe printf("> %d | %3.50lf \n",i,x); // Inkrement i += 1; } return 0; }