Pages

Wednesday, 27 July 2011

Program C++ Persamaan kuadrat


Persamaan kuadrat menggunakan looping while

/*program menghitung persamaan kuadrat while looping*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
main(void)
{
int a,b,c;
float X1,X2,D;
char karakter;
awal:
clrscr();
gotoxy(15,10);printf("Program Menghitung Akar Persamaan Kuadrat");
gotoxy(17,12);printf("silahkan masukan nilai a,b,dan c, :\n");
gotoxy(28,14);printf("nilai a:");scanf("%d",&a);
gotoxy(28,15);printf("nilai b:");scanf("%d",&b);
gotoxy(28,16);printf("nilai c:");scanf("%d",&c);
D=b*b-4*a*c;
while(a,b,c!=0)
                {
                X1=((-b+D)/2*a);
                X2=((-b-D)/2*a);
                gotoxy(21,17);printf("Hasil Persamaan Kuadrat: \n");
                gotoxy(28,18);printf("X1=%3.2f\n", X1);
                gotoxy(28,19);printf("X2=%3.2f\n", X2);
                break;
                }
                gotoxy(21,21);printf("tekan Y atau y untuk kembali");
                karakter=getche();
                while ((karakter=='y') || (karakter=='Y'))
                goto awal;
                clrscr();
}

No comments:

Post a Comment