Alıştırmalar Döngüler//
1.0 ile 10 arsındaki çift sayıları alt alta yazdırma..
#include<iostream>
using namespace std;
void main()
{ int a;
for(a=0;a<=10;a=a+2)
{if(a==10)continue; cout<<a<<endl;}
}
#include<iostream>
using namespace std;
void main()
{int a,n;
bas: cout<<"n degerini gir: ";cin>>n;
if(n<=0) goto bas;
for(a=0;a<=n;a=a+2)
cout<<a<<"\t";
}
#include<iostream>
using namespace std;
void main()
{int a,n,top=0;
bas:cout<<"n degerini gir: ";cin>>n;
if(n<=0) goto bas;
for(a=0;a<=n;a=a+2)
{top=top+a;}
cout<<"toplam= "<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{int a,top=0;
for(a=0;a<=10;a++)
{ if(a==5) continue;
top=top+a;}
cout<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{int x,sayi;double top=0;
for(x=1;x<=5;x++)
{cout<<x<<". sayiyi giriniz ";cin>>sayi;
top=top+sayi;}
cout<<"ortalama = "<<top/5<<endl;
}
#include<iostream>
using namespace std;
void main()
{int a,b,x;
for(b=1;b<=10;b++)
{ for(a=1;a<=10;a++)
{x=2*a-b;
cout<<"b= "<<b<<"\t"<<"a= "<<a<<"\t"<<"x= "<<x<<endl;
}}
}
#include<iostream>
using namespace std;
void main()
{double alan,cevre,r,pi=3.1419;
for(r=1;r<=10;r++)
{alan=r*pi*r;
cevre=2*pi*r;
cout<<"alan = "<<alan<<"\t"<<"cevre = "<<cevre<<"\t"<<"yarı cap = "<<r<<endl;}
}
////////////
#include<iostream>
using namespace std;
void main()
{double a,f;
for(a=0;a<=100;a=a+100)
{f=(a*10/18)+32;
cout<<"fahrenhayt= "<<f<<endl;
}
}
baslangıc ,bitiş değerlerini ve artış miktarını kullanıcıdan isteyen ve değerler arasında kalan sayıları yazan program..
#include<iostream>
using namespace std;
void main()
{double bas,son,artıs;
don: cout<<"baslangıc degerini gir";cin>>bas;
cout<<"bitis degerini gir";cin>>son; if(son<=bas) goto don;
cout<<"artıs miktarını gir";cin>>artıs;
for(bas;bas<son;bas=bas+artıs)
cout<<bas<<endl;
}
#include<iostream>
using namespace std;
void main()
{int a,b,carpım;
for(a=1;a<=10;a++)
{ for(b=1;b<=10;b++)
{ carpım=a*b;
cout<<"a= "<<a<<" b= "<<b<<" carpim= "<<carpım<<"\n";
}
}}
#include<iostream>
using namespace std;
void main()
{ int x,y,top=0;
cout<<"x degerini gir:";cin>>x;
cout<<"y degerini gir:";cin>>y;
if (x>y)
{for(++y;y<x;y++)
top=top+y;
cout<<"toplam= "<<top<<endl; }
else if(x==y)
{cout<<top<<endl;}
else
{for(++x;x<y;x++)
top=top+x;
cout<<"toplam= "<<top<<endl;
}}
ASAl sayi mi?
#include<iostream>
using namespace std;
void main()
{int n,sonuc=1,sayac=2;
cout<<"sayi gir:";cin>>n;
for(;sayac<n;sayac++)
{if(n%sayac==0)
{sonuc=0;break;}
}
if(sonuc==1)cout<<"asal sayi";else cout<<"asal sayi degil";
}
C++ programming
C++ programlama C programming
7 Ağustos 2015 Cuma
Döngülerle ilgili sorular
kullanıcının istediği kadar ekrana merhaba yazdıran program..
#include<iostream>
using namespace std;
void main()
{ int a,n;
cout<<"kac defa: ";cin>>n;
for(a=1;a<=n;a++)
{cout<<"Merhaba"<<"\t"<<endl;}
}
#include<iostream>
using namespace std;
void main()
{ int a=1,n;
cout<<"kac defa: ";cin>>n;
while(a<=n)
{cout<<"Merhaba"<<"\t"<<endl;
a++;}
}
#include<iostream>
using namespace std;
void main()
{ int a,n;
cin>>n;
for(a=1;a<=n;a++)
{cout<<a<<endl;}
}
#include<iostream>
using namespace std;
void main()
{ int a=1,n;
cout<<"n: ";cin>>n;
while(a<=n)
{cout<<a<<endl;a++;}
}
1 den n e kadar olan sayıların toplamı
#include<iostream>
using namespace std;
void main()
{ int n,a,top=0;
cin>>n;
for(a=1;a<=n;a++)
{top=top+a;}
cout<<top<<endl;
}
n faktoriyel
#include<iostream>
using namespace std;
void main()
{int s,n,top=1;
cout<<"kac faktoriyel: "; cin>>n;
for(s=1;s<=n;s++)
{top=top*s;}
cout<<"faktoriyel"<<"\t"<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{int n,s=1,top=1;
cout<<"kac faktoriyel ";cin>>n;
while(s<=n)
{top=top*s;s++;}
cout<<"faktoriyel="<<"\t"<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{
int x,y;
cout<<"x degerini gir: ";cin>>x;
cout<<"y degerini gir: ";cin>>y;
if(y>x)
{ for(x;x<=y;x++)
cout<<x<<endl;
}
else if(x==y)
{
cout<<"deger yok"<<endl;
}
else
{for(y;y<=x;y++)
cout<<y<<endl;}
}
girilen iki değer arasındaki sayıların toplamı
#include<iostream>
using namespace std;
void main()
{ int x,y,top=0;
cout<<"x degerini gir:";cin>>x;
cout<<"y degerini gir:";cin>>y;
if (x>y)
{for(y;y<=x;y++)
top=top+y;
cout<<"toplam= "<<top<<endl; }
else if(x==y)
{cout<<top<<endl;}
else
{for(x;x<=y;x++)
top=top+x;
cout<<"toplam= "<<top<<endl;
}}
#include<iostream>
using namespace std;
void main()
{ int a,n;
cout<<"kac defa: ";cin>>n;
for(a=1;a<=n;a++)
{cout<<"Merhaba"<<"\t"<<endl;}
}
#include<iostream>
using namespace std;
void main()
{ int a=1,n;
cout<<"kac defa: ";cin>>n;
while(a<=n)
{cout<<"Merhaba"<<"\t"<<endl;
a++;}
}
#include<iostream>
using namespace std;
void main()
{ int a,n;
cin>>n;
for(a=1;a<=n;a++)
{cout<<a<<endl;}
}
#include<iostream>
using namespace std;
void main()
{ int a=1,n;
cout<<"n: ";cin>>n;
while(a<=n)
{cout<<a<<endl;a++;}
}
1 den n e kadar olan sayıların toplamı
#include<iostream>
using namespace std;
void main()
{ int n,a,top=0;
cin>>n;
for(a=1;a<=n;a++)
{top=top+a;}
cout<<top<<endl;
}
n faktoriyel
#include<iostream>
using namespace std;
void main()
{int s,n,top=1;
cout<<"kac faktoriyel: "; cin>>n;
for(s=1;s<=n;s++)
{top=top*s;}
cout<<"faktoriyel"<<"\t"<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{int n,s=1,top=1;
cout<<"kac faktoriyel ";cin>>n;
while(s<=n)
{top=top*s;s++;}
cout<<"faktoriyel="<<"\t"<<top<<endl;
}
#include<iostream>
using namespace std;
void main()
{
int x,y;
cout<<"x degerini gir: ";cin>>x;
cout<<"y degerini gir: ";cin>>y;
if(y>x)
{ for(x;x<=y;x++)
cout<<x<<endl;
}
else if(x==y)
{
cout<<"deger yok"<<endl;
}
else
{for(y;y<=x;y++)
cout<<y<<endl;}
}
girilen iki değer arasındaki sayıların toplamı
#include<iostream>
using namespace std;
void main()
{ int x,y,top=0;
cout<<"x degerini gir:";cin>>x;
cout<<"y degerini gir:";cin>>y;
if (x>y)
{for(y;y<=x;y++)
top=top+y;
cout<<"toplam= "<<top<<endl; }
else if(x==y)
{cout<<top<<endl;}
else
{for(x;x<=y;x++)
top=top+x;
cout<<"toplam= "<<top<<endl;
}}
Döngü Tipleri
Bir işlemi belli bir sayıda veya belli bir şart gerçekleştiği sürece
veya belli bir şart gerçekleşene kadar tekrar eden kod yapısına döngü denir..
For Döngüsü
Bir işlemin veya döngünün tekrar sayısı belli ise for komutu kullanılır.
for döngüsünde;bir sayaç;bir şart ve sayacın artış durumunu belirleyen artış komutu bulunur..
Kullanımı
for(sayaç;şart;sayaç artışı) //örnek kod N defa Merhaba yazma.. 1den n e kadar sayı toplamı
int s,n; int s,top=0;
cin>>n; for(s=0;s<=10;s++)
{komut1; for(s=1;s<=n;s++) top=top+s;//döngü calıştığı sürece islem yapılır
komut2; cout<<"Merhaba C++"; cout<<"Toplam:"<<top;
komut3;
}
While Döngüsü:
Döngü sayısının belli olmadığı durumlarda kullanılır..Belirlenen şart sağlanıncaya kadar devam eder..
kullanımı: örenek kod:5 defa merhaba yazdırma 1 den 5 e kadar olan sayıların top
while(şart) // int s=1; int s=1,top=0;
// while(s<=5) while(s<=1)
{ işlem1; //{cout<<"merhaba"<<endl;s++;} {top=top+s;s++}cout<<"Toplam="<<top;
işlem2;
işlem3;
}
Do-While Döngüsünün Kullanımı
Önce işlem yapılır Daha sonra Şart kontrol Edilir..
kullanımı int s=1;
do do
{ işlemler; cout<<"merhaba"<<endl;
s++;
}while(sart); while(s<=1);
veya belli bir şart gerçekleşene kadar tekrar eden kod yapısına döngü denir..
For Döngüsü
Bir işlemin veya döngünün tekrar sayısı belli ise for komutu kullanılır.
for döngüsünde;bir sayaç;bir şart ve sayacın artış durumunu belirleyen artış komutu bulunur..
Kullanımı
for(sayaç;şart;sayaç artışı) //örnek kod N defa Merhaba yazma.. 1den n e kadar sayı toplamı
int s,n; int s,top=0;
cin>>n; for(s=0;s<=10;s++)
{komut1; for(s=1;s<=n;s++) top=top+s;//döngü calıştığı sürece islem yapılır
komut2; cout<<"Merhaba C++"; cout<<"Toplam:"<<top;
komut3;
}
While Döngüsü:
Döngü sayısının belli olmadığı durumlarda kullanılır..Belirlenen şart sağlanıncaya kadar devam eder..
kullanımı: örenek kod:5 defa merhaba yazdırma 1 den 5 e kadar olan sayıların top
while(şart) // int s=1; int s=1,top=0;
// while(s<=5) while(s<=1)
{ işlem1; //{cout<<"merhaba"<<endl;s++;} {top=top+s;s++}cout<<"Toplam="<<top;
işlem2;
işlem3;
}
Do-While Döngüsünün Kullanımı
Önce işlem yapılır Daha sonra Şart kontrol Edilir..
kullanımı int s=1;
do do
{ işlemler; cout<<"merhaba"<<endl;
s++;
}while(sart); while(s<=1);
Karar Yapıları Örnek Sorular
Konsoldan okunan bir sayının 10 değerine göre durumu (büyük,küçük,eşit)
#include<iostream>
using namespace std;
void main ()
{ int x;
cout<<"x:";cin>>x;
if(x<10)
cout<<"x kucuktur 10'dan"<<endl;
else if(x>10)
cout<<"x buyuktur 10'dan"<<endl;
else
cout<<"x esittir 10'a "<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int x,y;
cout<<"x:";cin>>x;
cout<<"y:";cin>>y;
if(x<y)
cout<<"x kucuktur y"<<endl;
else if(x>y)
cout<<"x buyuktur y"<<endl;
else
cout<<"x esittir y"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double ort,x,y;//x vize y final
cout<<"vize notu gir: ";cin>>x;
cout<<"final notu gir: ";cin>>y;
ort=(x*4)/10+(y*6)/10;
if(ort>=50)
cout<<"gectiniz"<<"\t"<<ort<<endl;
else
cout<<"kaldiniz"<<"\t"<<ort<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"x:";cin>>x;
if(x<0 || x>100 )
cout<<"hayir"<<endl;
else
cout<<"evet"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"x:";cin>>x;
if(x>0 && x<100 )
cout<<"hayir"<<endl;
else
cout<<"evet"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"kac derece : ";cin>>x;
if(x<0)
cout<<"Soguk"<<endl;
else if(x>15)
cout<<"sicak"<<endl;
else
cout<<"ilik"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int x,y;
cout<<"x : ";cin>>x;
cout<<"y : ",cin>>y;
bas:
x=x+1;
if(x<y)
{cout<<x<<endl;
goto bas;}
else(y<x);
y++;
cout<<y<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int a,b,top=0;
cin>>a>>b;
art:if(a<b)
a++;
top=top+a;
cout<<top<<endl; goto art;
}
#include<iostream>
using namespace std;
void main()
{ int n,sayi,sayac=0,top=0;
cout<<"sayi adeti:";cin>>n;
oku:
cout<<"sayi giriniz: ";cin>>sayi;
top=top+sayi;
sayac=sayac+1;
if (sayac<n)goto oku;
cout<<"ortalama:"<<"\t"<<(top/n)<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int x;
cout<<"x:";cin>>x;
if(x<10)
cout<<"x kucuktur 10'dan"<<endl;
else if(x>10)
cout<<"x buyuktur 10'dan"<<endl;
else
cout<<"x esittir 10'a "<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int x,y;
cout<<"x:";cin>>x;
cout<<"y:";cin>>y;
if(x<y)
cout<<"x kucuktur y"<<endl;
else if(x>y)
cout<<"x buyuktur y"<<endl;
else
cout<<"x esittir y"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double ort,x,y;//x vize y final
cout<<"vize notu gir: ";cin>>x;
cout<<"final notu gir: ";cin>>y;
ort=(x*4)/10+(y*6)/10;
if(ort>=50)
cout<<"gectiniz"<<"\t"<<ort<<endl;
else
cout<<"kaldiniz"<<"\t"<<ort<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"x:";cin>>x;
if(x<0 || x>100 )
cout<<"hayir"<<endl;
else
cout<<"evet"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"x:";cin>>x;
if(x>0 && x<100 )
cout<<"hayir"<<endl;
else
cout<<"evet"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x;
cout<<"kac derece : ";cin>>x;
if(x<0)
cout<<"Soguk"<<endl;
else if(x>15)
cout<<"sicak"<<endl;
else
cout<<"ilik"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int x,y;
cout<<"x : ";cin>>x;
cout<<"y : ",cin>>y;
bas:
x=x+1;
if(x<y)
{cout<<x<<endl;
goto bas;}
else(y<x);
y++;
cout<<y<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ int a,b,top=0;
cin>>a>>b;
art:if(a<b)
a++;
top=top+a;
cout<<top<<endl; goto art;
}
#include<iostream>
using namespace std;
void main()
{ int n,sayi,sayac=0,top=0;
cout<<"sayi adeti:";cin>>n;
oku:
cout<<"sayi giriniz: ";cin>>sayi;
top=top+sayi;
sayac=sayac+1;
if (sayac<n)goto oku;
cout<<"ortalama:"<<"\t"<<(top/n)<<endl;
}
Sayac kullanımı:
Önce sayı okunur sayı okunduktan sonra sayac değeri 1 artar eğer girilen sayi 5 ise sayac değeri yazılır
aksi takdirde yeni bir sayi okunur.
#include<iostream>
using namespace std;
void main()
{
double sayi,sayac=0;
oku:
cout<<"sayi:";cin>>sayi;
sayac=sayac+;
if(sayac==5)
cout<<"sayac degeri:"<<sayac;
else
goto oku;
}
1 den n e kadar olan sayıların yazılması;
#include<iostream>
using namespace std;
int main()
{ long int n,sayi=0;
cin>>n;
art:
sayi=sayi+1;
if(sayi<=n)
{cout<<"sayi"<<"\t"<<sayi<<endl;
goto art;}
return 0;
}
1 den n e kadar olan çif sayıların yazılımı
#include<iostream>
using namespace std;
void main ()
{
int s,n;
s=0;
cout<<"n deger gir";cin>>n;
art:
s=s+2;
if(s<n)
{
cout<<s<<endl;
goto art;
}
}
kullanıcının istediği sayi kadar girilen sayiların toplamı..
#include<iostream>
using namespace std;
void main()
{
int adet,sayi,sayac=0,top=0;
cout<<"sayi adeti";cin>>adet;
oku:
cout<<"sayi giriniz";cin>>sayi;
top=top+sayi;
sayac=sayac+1;
if (sayac<adet) goto oku;
cout<<"toplam="<<"\t"<<top;
}
#include<iostream>
using namespace std;
void main()
{ double s=0,n,top=0;
cout<<"n degerini gir:";cin>>n;
art:
s=s+1;
top=top+s;
if (s<n) goto art;
cout<<"toplam="<<top<<"\t"<<endl;
}
Faktöriyel hesabı:
#include<iostream>
using namespace std;
void main ()
{ double s=0,n,top=1;
cout<<"kac faktoriyel gir:";cin>>n;
bas:
s=s+1;
top=top*s;
if(s<n) goto bas;
cout<<"faktoriyel="<<top<<"\t"<<endl;
}
Şart Yapıları
Örnek:Geçti kaldı programı...
#include<iostream>
using namespace std;
void main ()
{
double ort;
cout<<"ortalamani gir:";cin>>ort;
if (ort<50)
{cout<<"kaldin!!"<<endl;}
else if(ort<=65)
{cout<<"orta"<<endl;}
else if (ort<=80)
{cout<<"iyi"<<endl;}
else
{cout<<"pekiyi"<<endl;}
}
(?):Operatörü
if else gibi çalısır.bir sart kontrol edilir..eğer şart sağlanırsa islem1 gerceklesmezse islem2gerceklestirilir
(sart)? islem1:islem2
örnek
int x,y;
cout<<"x:";cin>>x;
y=(x<10)?0:10//x<10 ise y=0 aksi takdirde y=10
cout<<y;
Switch Komutu :
if - else if komutu ile aynı calısır.Eğer şartlardan biri gerçekleşmezse,en sonunda belirtilen işlemin yapılmasını sağlar.
switch(değişken)
{ case deger1: //değişken bu değere sahipse
islem1; //buradaki islem yapılır..
break; //switch komutundan çıkılır..
case deger2:
islem2;
break;
default: //eğer yukarıdaki şarrtlardan herhangi biri çalışmazsa
islem3: //buradaki islem yapılır..
}
Örnek:Kullanıcıdan günü isteyip hangi gün olduğunu ekrana çıkaran program :
#include<iostream>
using namespace std;
void main ()
{ int x;
cout<<"hangi gün:";cin>>x;
switch(x)
{ case 1: cout<<"pazartesi ";break;
case 2: cout<<"salı ";break;
case 3: cout<<"carsamba ";break;
case 4: cout<<"persembe ";break;
case 5: cout<<"cuma ";break;
case 6: cout<<"cumartesi ";break;
case 7: cout<<"pazar ";break ;
}
}
Dallanma komutu (goto)ve etiket kullanılmsı:
kodların takibini ve okunmasını zorlaştırdığı ve yapısal programlamaya aykırı olduğu için
pek tercih edilmez..
goto komutunun çalışabşlmesi için öncelikle bir etiket oluşturulmalıdır.
etiket belli bir satıra verilen isimdir..
Etiket oluşturulduktan sonra,belli bir şart sağlandığında program etiketin olduğu satıra gönderilir..
kullanımı:
komut 1;
komut 2;
etiket:
komut 3;
komut 4 ;
goto etiket;//etiketin olduğu satıra git..
örnek komut
int x ,kare;
gir: //gir isimli etiket
<<cout"Sayi:";cin>>x;
if(x<0)
goto gir; //gir satırına geri gider
kare=x*x;
cout<<"Kare="<<kare;
Siteye 18 yaşından küçükse uyarı yazısı gönderen program:
#include<iostream>
using namespace std;
void main ()
{
int yas;
cout<<"yasınızı giriniz:";cin>>yas;
if(yas<18)
{cout<<"yasiniz kucuk!!"<<endl;}
cout<<"siteye giriniz"<<endl;
}
#include<iostream>
using namespace std;
void main ()
{ double x,kare;
bas: cout<<"pozitif sayi giriniz";cin>>x;
kare=x*x;
if(x<0)
{cout<<"pozitif sayi giriniz!!!"<<endl;
goto bas;}
cout<<"Kare="<<kare<<endl;
}
Dairenin alan ve cevresi;
#include<iostream>
using namespace std;
void main ()
{
double r,alan,cevre;
double pi; pi=3.14;
gir: cout<<"yarı cap giriniz";cin>>r;
alan=pi*r*r;
cevre=2*pi*r;
if (r<0)
goto gir;
cout<<"alan="<<alan<<"\t"<<"cevre="<<cevre<<endl;
}
Dikdörtgenin alan ve cevresi
#include<iostream>
using namespace std;
void main ()
{
double a,b,alan,cevre;
bas: cout<<"a:";cin>>a;
if(a<=0) goto bas;
gir: cout<<"b:";cin>>b;
if (b<=0) goto gir;
alan=a*b;
cevre=2*(a+b);
cout<<"alan="<<alan<<"\t"<<"cevre="<<cevre<<endl;
}
Girilen iki sayının durumunu veren program:
#include<iostream>
using namespace std;
void main ()
{
double a,b;
cout<<"a:";cin>>a;
cout<<"b:";cin>>b;
if(a<b)
cout<<"a kucuktur b"<<endl;
else if(b<a)
cout<<"b kucuktur a"<<endl;
else
cout<<"a esittir b"<<endl;
}
Geçti kaldı Programı:
#include<iostream>
using namespace std;
void main()
{
double i,j,ort;
{bas: cout<<"ilk notu gir:";cin>>i;
if(0<i || i>100)
goto bas; }
{gir: cout<<"ikinci notu gir:";cin>>j;
if (0<j || j>100)
goto gir;}
ort=(i+j)/2;
cout<<"ortalama="<<ort<<endl;
if(ort<50)
cout<<"kaldiniz!!"<<endl;
else
cout<<"gectiniz"<<endl;
}
Cmath Kütüphanesi
CMATH ( MATEMATİK) KÜTÜPHENESİ:
1. C++ dilinde matematiksel fonksiyonların aktiflenmesi için cmath kütüphanesi #include <cmath> şeklinde eklenmelidir.
2. Aynı kütüphane c dilinde math.h ile aktif edilir. math.h kütüpanesi c++ dilinde de çalışır.
3. Kütüphanede kullanılan sayısal değerler, float veya double tipinde tanımlanmalıdır. Tamsayı şeklinde tanımlanırsa hata verirler.
4. Matematiksel eşitlikleri yazarken parantezlere özellikle dikkat edilmelidir.
pow(x,y)
x üssü y demektir. pow(x,0.5)=sqrt(x) dir.
sqrt(x)
x in karekökü demektir.
fabs(x)
x in mutlak değeri demektir.
exp(x)
e üssü x demektir. Burada e=2.71... dir.
sin(x) , cos(x)
radyan olarak x sayısının sinüs ve kosinüs değerlerini verir.
tan(x) , cot(x)
radyan olarak x sayısının tanjant ve kotanjant değerlerini verir.
asin(x) , acos(x)
radyan olarak x sayısının arcsinüs ve arccosinüs değerlerini verir.
atan(x) , acot(x)
radyan olarak x sayısının arctanjant ve arckotanjant değerlerini verir.
log10(x)
10 tabanında x in logaritmasını verir.
log(x)
ln(x) anlamına gelir.
Örnek : Kullanıcı tarafından girilen x değerine göre ((𝒙+𝟑)* 𝒆^𝟒− 𝟐*𝒙+𝒔𝒊𝒏𝒙)/(𝝅* 𝒍𝒏𝒙 +𝟓𝒙 ) işleminin sonucunu hesaplayıp ekrana yazdıran c++ programını yazınız.
#include <iostream>
#include <cmath>
using namespace std;
void main ()
{ double x,sonuc; double pi_sayisi=3.14;
cout<<"x:";
cin>>x;
sonuc=((x+3)*exp(4.)-2*x+sin(x))/(pi_sayisi*(log(x)+5*x));
cout<<"sonuc = "<<sonuc<<endl;
}
Kaydol:
Yorumlar (Atom)