PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [C++] Wurzeln Ziehn



QpL
20.09.2007, 19:55
Hi,
Könnte mir bitte jemand sagen, wie ich eine Wurzel in C++ ziehe?
(steht nicht in meinem Buch und ich bräucht das eben für ein tool :D)

Menrout
20.09.2007, 20:01
Wenn du die Headerdatei Math.h includierst steht dir folgende Methode fürs Quadratwurzel ziehen eines Fließkommawertes zur Verfügung:

double sqrt(double a);

exodus407
20.09.2007, 20:06
falls du einen completen code willst :


#include <iostream.h>
#include <conio.h>
#include <math.h>


int main()
{
double zahl;

cin>>zahl;

zahl=sqrt(zahl);

cout<<zahl;

getch();
}

mfg exo

-[RiDER]-
20.09.2007, 20:27
falls du tiefer in die materie einsteigen willst, das lesen: http://www.matheboard.de/archive/16457/thread.html

MfG RiDER

|V|4|_|54
21.09.2007, 21:24
oder du bist primitiv und machst es so^^



#include<iostream.h>
#include<conio.h>
void main()
{ long double zahl1, zahl2, zahl3;
int zahl4, zahl5;
for(;;)
{ clrscr();
zahl2=0;
zahl3=0;
zahl4=0;
zahl5=0;
cout<<"created by IVI4US4\n\n\nGib bitte eine Zahl ein oder zum Beenden \"0\":\n";
cin>>zahl1;
if(zahl1==0)
{ break; }
if(zahl1<0)
{ zahl1=zahl1*-1;
zahl5++; }
for(;;)
{ if(zahl2*zahl2==zahl1)
{ break; }

if(zahl2*zahl2>zahl1)
{ zahl4++;
if(zahl4==15)
{ break; }
zahl2=zahl2-zahl3;
zahl3=zahl3/10; }
zahl2+=zahl3; }
if(zahl5==2)
{ cout<<"Die Wurzel aus "<<zahl1*-1<<" ist "<<zahl2<<"i\n"; }
if(zahl5==1)
{ cout<<"Die Wurzel aus "<<zahl1<<" ist "<<zahl2<<endl; }
getchar(); }}

Hamachi-1
15.10.2007, 13:30
der geht nicht -.-
hast ein fehler drine