Eğlenceye Davetlisiniz...

Yeni Başlayanlar İçin C++ Örnekleri



1. Yarıçapı girilen dairenin çevresini ve alanını hesaplayan program:
Kod:
#include <iostream>

using namespace std;

#define PI 3.14

int main(****)
{
float radius;
float circum, area;

cout << "Yaricapi yaziniz.";
cin >> radius;
circum = 2 * PI * radius;
area = PI * radius * radius;
cout << "Cevresi:" << circum << endl;
cout << "Alanı:" << area << endl;
system("PAUSE");
return EXIT_SUCCESS;
system("PAUSE");
}


2.Dereceden Denklemin Köklerini bulan program:

Kod:
#include <cstdlib>
#include <iostream>
#include <math.h> 

using namespace std;

int main(****)
{ 
float a, b, c;
float disc;
float x1, x2;

cout << "a, b ve c katsayilarini yaziniz.";
cin >> a >> b >> c;
disc = b * b - 4 * a * c;
if (disc < 0)
cout << "Gercel kok yok." << endl;
else {
if (disc == 0) {
x1 = -b / (2 * a);
cout << x1 << "noktasinda cakısan iki kok var." << endl;
} else {
x1 = (-b + sqrt(disc)) / (2 * a);
x2 = (-b - sqrt(disc)) / (2 * a);
cout << x1 << "ve" << x2
<< "noktalarinda iki gercel kok var." << endl;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}


3: Kullanıcının belirttiği işlemi yapan program:

Kod:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(****)
{
int num1, num2, result;
char op;

cout << "Islemi yaziniz.";
cin >> num1 >> op >> num2;
switch (op) {
case '+': result = num1 + num2;
break;
case '-': result = num1 - num2;
break;
case '*': result = num1 * num2;
break;
case '/': result = num1 / num2;
break;
case '%': result = num1 % num2;
break;
default: cout << "Boyle bir islem yok." << endl;
return EXIT_FAILURE;
}
cout << num1 << op << num2 << "İslemin sonucu:" << result << endl;
system("PAUSE");
return EXIT_SUCCESS;
}


İngiliz - Metrik birim dönüşümü yapan program:

Kod:
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(****)
{
int choice;
float inch, cm, f, c;

cout << "1.inch-cm" << endl;
cout << "2.f-c" << endl;
cout << "3.Cikis" << endl;
cout << "Seciminiz;";
cin >> choice;

switch (choice) {
case 1:
cout << "inch cinsinden uzunluk:";
cin >> inch;
cm = 2.54 * inch;
cout << cm << "cm" << endl;
break;
case 2:
cout << "f cinsinden sicaklik:";
cin >> f;
c = ( f - 32 ) * 5.0 / 9.0;
cout << c << "C" << endl;
break;
case 3:
system("PAUSE");
return EXIT_SUCCESS;
default:
cout << " Boyle bir islem yok." << endl;
return EXIT_FAILURE;

}
system("PAUSE");
return EXIT_SUCCESS;
}


Girilen 2 sayının obebini bulan program:


Kod:
#include <iostream>
#include <stdlib.h>

using namespace std;

int main (****)
{
int num1, num2;
int a, b, r=1;

cout << "Sayilari yaziniz:" << endl;
cin >> num1 >> num2;

if ( num1 > num2 ) {
a = num1;
b = num2;
} else {
a = num2;
b = num1;
}
while ( b > 0 ) {
r = a % b;
a = b;
b = r;
}
cout << num1 << "ve" << num2
<< "sayilarinin ebobu:" << a << endl;
system ("PAUSE");
return EXIT_SUCCESS;
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 yorum:

Yorum Gönder