EXAMPLE 1 BİR N ELEMANININ DİZİ ŞEKLİNDE YAZILIMI #include<stdio.h> #include
int i,N,A[100]; void main() { printf("Dizinin eleman sayisini girin="); scanf("%u",&N); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); } for(i=1;i<=N;i++) { printf("A(%u)=%d",i,A[i]); } }
EXAMPLE 2 BİR N ELAMAN SAYISI GİRİYORUZ BU DİZEYE KADAR OLAN SAYILARI TOPLA VE ORTALAMA ALINIZ
#include<stdio.h> #include int i,N,T,A[100]; void main() {
Dizinin eleman sayisini girin=4 A(1)=45 A(2)=60 A(3)=35 A(4)=56
printf(" Dizinin eleman sayisini girin="); Toplam=196 Ortalama=49 scanf("%u",&N); for(i=1;i<=N;i++) { T=0; printf("\nA(%u)=",i); scanf("%d",&A[i]); T=T+A[i];printf("\n"); } printf("Toplam=%d\n",T);printf("\n"); printf("Ortalama=%d\n",T/N);printf("\n"); } Tekrar eden li #include<stdio.h> #include #include<stdlib.h> int i,N,T,A[100],k; void main() { k: printf("Eleman sayisini girin="); scanf("%u",&N); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); T=T+A[i]; } printf("\t\ttoplam=%d\n",T); printf("\t\tortalama=%d\n",T/N); goto k; }
EXAMPLE 3 VERİLEN İKİ DİZİNİN TOPLAMINI DİĞER DİZİNİN İÇİNDE TOPLAMA PROGRAMI
#include<stdio.h> #include #include<stdlib.h> int i,N,T,A[100],B[100],C[100]; void main() { printf("Eleman sayisini girin="); scanf("%u",&N); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); } for(i=1;i<=N;i++) { printf("\nB(%u)=",i); scanf("%d",&B[i]); } for(i=1;i<=N;i++) { C[i]=A[i]+B[i]; printf("\t\tC(%u)=%d\n",i,C[i]); } }
Dizinin eleman sayisini girin=4 A(1)=15 A(2)=20 A(3)=10 B (1)=41 B(2)=25 B(3)=30 C(1)=56 C(2)=45 C(3)=40
EXAMPLE 4
#include<stdio.h> #include int i,N,enk,enkyer,enb,enbyer,A[100]; void main() { printf("dizinin eleman sayisi="); scanf("%u",&N); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); enk!=A[1]; (A[1] e eşit olmadığı için enkuçuk değeri 0 alır) enkyer=1; enb=A[1]; enbyer=1; } for ( i=2;i<=N;i++) { if(A[i]<enk){enk=A[i];enkyer=i;} if(A[i]>enb){enb=A[i];enbyer=i;} } printf("en kucuk eleman %d dir ve %i: siradadir\n",enk,enkyer); printf("en buyuk eleman %d dir ve %i: siradadir\n",enb,enbyer); }
EXAMPLE 4
#include<stdio.h> #include int i,N,enk,enkyer,enb,enbyer,A[100]; void main() { printf("Dizinin eleman sayisi="); scanf("%u",&N); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); enk=A[1]; enkyer=1;
Dizinin eleman sayisini girin=4 A(1)=45 A(2)=4 A(3)=75 A(4)=932 En küçük eleman 4 dur 2. sıradadır. En büyük eleman 932 dir 4.sıradadır.
enb=A[1]; enbyer=1; } for ( i=1;i<=N;i++) { if(A[i]<enk){enk=A[i];enkyer=i;} if(A[i]>enb){enb=A[i];enbyer=i;} } printf("\t\aEn kucuk eleman %d dir ve %i. siradadir.\n",enk,enkyer); printf("\t\aEn buyuk eleman %d dir ve %i. siradadir.\n",enb,enbyer); }
#include<stdio.h> #include int i,j,N,fv,A[100]; void main() { printf("eleman sayisi="); scanf("%u",&N); printf("\n"); for(i=1;i<=N;i++) { printf("\nA(%u)=",i); scanf("%d",&A[i]); printf("\n"); } for(i=1;i<=(N-1);i++) { for(j=(j+1);j<=N;j++){ if(A[j]
} printf("sirali dizi=\n"); for(i=1;i<=N;i++) { printf("A(%u)=%d\n",i,A[i]); } }
MATRİS YAPISI
#include<stdio.h rel="nofollow"> void main() { int sayi[2][3]={1,2,3,4,5,6}; int x,y; for(x=0;x<2;x++) { for(y=0;y<3;y++) printf("%4d",sayi[x][y]); printf("\n"); } }
#include<stdio.h> int i,j,N,A[100][100]; void main() { printf("N i girin=\n"); scanf("%d",&N); for(i=0;i
1
2 3
4
5
6
#include<stdio.h> void main() { int x[3][2][2]; int i,j,k; for(i=0;i<3;i++) for(j=0;j<2;j++) for(k=0;k<2;k++) x[i][j][k]=i+j+k; for(i=0;i<3;i++) for(j=0;j<2;j++) for(k=0;k<2;k++) printf("A(%d%d%d)=%d\n",i,j,k,x[i][j][k]); }
FİLE DOSYA İŞLEMİNİ REHBER ADI ALTINDA YAZAN PROGRAM
#include<stdio.h> #include struct kayit_alani { char ad[25]; char adres[40]; char tel[12]; } kayit; FILE *dosya; void main() { dosya=fopen("REHBER.TXT","a+"); printf("Adi-Soyadi:"); scanf("%s",&kayit.ad); printf("Adresi:");
scanf("%s",&kayit.adres); printf("Telefonu:"); scanf("%s",&kayit.tel); fwrite(&kayit,sizeof(kayit),1,dosya); fclose(dosya); }
#include<stdio.h> boşluklarıda kabuledr #include struct kayit_alani { char ad[25]; char adres[40]; char tel[12]; } kayit; FILE *dosya; void main() { dosya=fopen("REHBER.TXT","a+"); printf("Adi-Soyadi:"); gets("%s",&kayit.ad); printf("Adresi:"); gets("%s",&kayit.adres); printf("Telefonu:"); gets("%s",&kayit.tel); fwrite(&kayit,sizeof(kayit),1,dosya); fclose(dosya); }
LİSTİN OF DATA KAYIT ETTİKLERİMİZİ OKUMA #include<stdio.h> #include struct kayit_alani { char ad[25]; char adres[40]; char tel[12]; } kayit; FILE *dosya; int i,ks; void main() { dosya=fopen("REHBER.TXT","r"); fseek(dosya,0,2); ks=ftell(dosya)/sizeof(kayit); for(i=1;i
#include<stdio.h> #include struct kayit_alani { char ad[25]; char adres[40]; char tel[12]; } kayit; FILE *dosya; int no,ks; void main() { dosya=fopen("REHBER.TXT","r"); fseek(dosya,0,2); ks=ftell(dosya)/sizeof(kayit); do { printf("Aranan kayit no:"); scanf("/u",&no); no--; }while((no<0) || (no>=ks)); fseek(dosya,no*77,0); fread(kayit.ad,25,1,dosya); fread(kayit.adres,40,1,dosya); fread(kayit.tel,12,1,dosya); printf("\n%s %s %s\n",kayit.ad,kayit.adres,kayit.tel); fclose(dosya); }
SAYILARIN YİNELEME YAPAN PROGRAM Ekran gorüntüsü
#include<stdio.h> #include<stdlib.h> #include<math.h> void yinele(int); void main() { int sayi; sayi=7; yinele(sayi); } void yinele(int deger) { deger=deger-1; printf("%d\n",deger); if(deger>0) yinele(deger); printf("%d\n",deger); }
6 5 4 3 2 1 0 0 1 2 3 4 5 6
YİNELEME İLE FAKTORİYEL HESABI #include<stdio.h> #include<stdlib.h> #include<math.h> int faktoriyel(int N) { if(N==0)return 1; return N*faktoriyel(N-1); } void main() { int N; printf("N sayisini giriniiz="); scanf("%d",&N); printf("Sonuc=%d\n",faktoriyel(N)); }
Ekran gorüntüsü Nsayisinigiriniz=5 Sonuc=120
SAYİ TAHMİNİ YAPMA PROGRAMI() #include<stdio.h> #include #include<stdlib.h> int BS,guess,s,Tahmininiz; void main() { giris: rand(); BS=rand()%100; s=0; do { printf("Tahmininiz:"); scanf("%u",&guess); s++; if(guess>BS) printf("\t\tdecrease\n"); if(guess
Ekran gorüntüsü Tahmininz=65 İncrease Tahmininiz=75 Decrease 70 conguralations
goto giris; }
#include<stdlib.h> #include<stdio.h> void main() { int a=4, b=7; int *pa,*pb; printf("a=%d,b=%d\n",a,b); pa=&a; pa=&b; *pa=*pa+10; *pb=*pb+10; printf("a=%d,b=%d",a,b); }
Ekran gorüntüsü Tahmininz=65 İncrease Tahmininiz=75 Decrease 70 conguralations
SAYILARI SIRALAMA #include<stdio.h> #include<math.h> void degis(long *,long *); void main() { long a,b,c; printf("Birinci sayi="); scanf("%d",&a); printf("Ikinci sayi="); scanf("%d",&b); printf("Ucuncu sayi="); scanf("%d",&c); if(a
KAREKTER BULMA #include #include<stdio.h> #include<string.h> void degis(long *,long *); void main() { char ch,cumle[45],*ptr; printf("Birinci cumle girin:"); gets(cumle); printf("aranacak harfi girin:"); ch=getche(); ptr=strchr(cumle,ch); printf("\n cumlenin basladiği adres %u dir\n",cumle); printf("Karsilsilan ilk %c karakteri %u adresindedir.\n",ch,ptr); printf("pozisyonu ise %d",ptr-cumle+1); }
Üçgenin alanı /* loop1*/ #include<stdio.h> float a,h,area; void main() { printf("Kenar uzunlugu girin:"); scanf("%f",&a); printf("yukseklik:\n\n"); scanf("%f",&h); area=a*h/2; printf("\n ucgenin alani="%f",area); }
EXAMPLE 2 #include<stdio.h> #include #include<math.h> const float PI=3.14; float a,b,aci,area; void main() { printf("\na="); scanf("%f",&a); printf("\nb="); scanf("%f",&b); printf("\naci="); scanf("%f",&aci); area=a*b*sin(3.14*aci/180)/2; printf("\n\narea=%0.2f\n\n\n",area); }
EXAMPLE 3
#include<stdio.h> #include #include<math.h> float a,b,c; void main() { giris: printf("\nBirinci Kenar:"); scanf("%f",&a); printf("\nİkinci Kenar:"); scanf("%f",&b); c=sqrt(a*a+b*b); printf(" \nHypothenus=%0.2f\n\n",c); goto giris; }
EXAMPLE 4
#include<stdio.h> #include #include<math.h> float h,Vo,t,x,V,Vy; void main() { printf("\nYuksekligi girin:"); scanf("%f",&h); printf("\nIlk hizi girin:"); scanf("%f",&Vo); t=sqrt(2*h/9.8); Vy=9.8*t; V=sqrt(Vo*Vo+Vy*Vy); x=Vo*t; printf("\n\nUcus zamani=%0.2f",t); printf("\n\nYatayda alacagi yol=%0.2f",x); printf("\n \nYere carpma hizi:%0.2f\n\n\n",V); }
EXAMPLE 5 #include<stdio.h> #include int i,N; float T; void main() { printf("N'i Girin:"); scanf("%u",&N); T=0; for(i=1;i<=N;i++) T=T+i*i; printf("\nTOPLAM=%0.0f\n\n",T); }
(EXAMPLE 6) COMBİNASYON BULMA
#include<stdio.h> #include int i,n,r; float f1,f2,f3,k; void main() { giris: f1=1;f2=1;f3=1; printf("\n n=");scanf("%u",&n); printf("\n r=");scanf("%u",&r); for(i=1;i<=n;i++) { f1=f1*i; if(i<=r)f2=f2*i; if(i<=(n-r))f3=f3*i; } k=f1/(f2*f3); printf("\nsonuc=%0.2f\n\n",k); goto giris; }
EXAMPLE 7
#include<stdio.h> #include #include<math.h> int a,b; void main() { giris: printf("\n a=");scanf("%d",&a); printf("\n b=");scanf("%d",&a); if(fmod(a,b)==0) printf("%dsayisi%d sayisina tam bolunuyor",a,b); else printf("%dsayisi%d sayisina tam bolunuyor",a,b); goto giris; }
EXAMPLE 7 #include<stdio.h> #include #include<math.h> int a,b; void main() { printf("\n a=");scanf("%d",&a); printf("\n b=");scanf("%d",&a); if(fmod(a,b)==0) printf("%dsayisi%d sayisina tam bolunuyor",a,b); else printf("%dsayisi%d sayisina tam bolunuyor",a,b); }
EXAMPLE 8 #include<stdio.h> #include #include<math.h> void main() { giris: int a; printf("\nBir tansayi girin=");scanf("%i",&a); if(floor (a/2)==float(a/2)) printf("Cift"); else printf("Tek"); goto giris; }
EXAMPLE 9 (EXACT DİVİDERS) (TAM BÖLENLERİ BULMA)
#include<stdio.h> #include #include<math.h> int a,i; void main() { giris: printf("Tamsayi girin="); scanf("%u",&a); for(i=1;i<=a;i++) if(fmod(a,i)==0) printf("%u\n",i); goto giris; }
EXAMPLE 10 #include<stdio.h> #include float x,y; void main() { giris: printf("x=");scanf("%f",&x); if(x<0) y=1; else if (0<=x && x<=2)y=x; else if (2<x && x<=4)y=3; else y=4-x; printf("f(x)=%0.2f\n\n",y); goto giris }
EXAMPLE 11 #include<stdio.h> #include #include<stdlib.h> int BS,guess,s; void main() { giris: randomize(); BS=random(99)+1; s=0; do { printf(Tahmininiz:); scanf("%u",&guess); s++; if(guess>BS) printf("decrease"); if(guess
EXAMPLE 12 #include<stdio.h> #include #include<math.h> int x,N,i; float T,F; void main() { printf("Terim sayisi="); scanf("%u",&N); printf("\nx="); scanf("%d",&x); T=1,F=1; for(i=1;i<=N;i++) { F=F*i; T=T+pow(x,i)/F; } printf("\nSeri acilimiyla e(x)=%0.2f\n",T); printf("\nKomutla e(x)=%0.2f\n\n\n",exp(x)); }
EXAMPLE 13 #include<stdio.h> #include int i,j,k; float T,F; void main() { printf("Tamsayilar="); for(i=0;i<=9;i++) for(j=1;j<=9;j++) for(k=1;k<=9;i++) if((i+j+k)==3) printf("%u",100*i+10*j+k); }
#include<stdio.h> void main() { float dx=0.001,integral=0.x=-3; while(x<=5){ integral+=(3*x*x+2*x+5)*dx; x+=dx; } printf("%f",integral); }
EXAMPLE 14
#include<stdio.h> #include #include<stdlib.h> int i,s,x,a1; char guess[1],*letter; void main() { randomize(); x=random(26)+65; *harf=char(x); for(i=1;i<1=0;i++) { printf("guess"); gets(guess); if(stremp(guess,letter)==0) printf("%utahminde ok",i); goto a1;} printf("10 kakkiniz bitti."); a1; }
EXAMPLE 15(Karakok alma) #include<stdio.h> #include #include<math.h> void main() { float N,y; printf("N sayisi girin="); scanf("%f",&N); y=pow(N,1/2);
(boyle girilmesi hatalı çunku ondalıklı
değil) printf("%f\n",y); y=pow(N,1.0/2); printf("%f.0\n",y); y=pow(N,1/2.0); printf("%f.0\n",y); }
#include<stdio.h> #include #include<math.h> void main() { int a=3,b=4; float f; f=pow((a+b),3)+(a*b)/(pow(a,4)-b); printf("%.0f",f); }
EXAMPLE 16
#include<stdio.h> void yaz(int a,int b) { printf("%d %d\n",a,b); } void main() { int x=5 , y=7; yaz(x,y); yaz(x+5,x+y); }
EXAMPLE 17 #include<stdio.h> long toplam(long,long); void main() { long x,y; x=1500;y=4500; printf("%d+%d=%d\n",x,y,toplam(x,y)); } long toplam(long a,long b) { long t=a+b; return(t); }
EXAMPLE 19 #include <stdio.h> void degis(long,long); void main() { long a,b,c; printf ("a yi girin=");scanf("%d",&a); printf ("b yi girin=");scanf("%d",&b); printf ("c yi girin=");scanf("%d",&c); if (a
printf("%d %d %d\n\n",a,b,c); } void degis(long x,long y) { long g; g=x; x=y; y=g; }
EXAMPLE 20(1 ile 2 arasında 0.1 artış ile toplam
#include <stdio.h> #include <math.h> double fonk(float z) { float f=5*z+sqrt(4*z)-(z/2.0); return (f); } void main() { float x=0; do{ x=x+0.1; printf("%3.1f %10.5f\n",x,fonk(x)); } while (x<2.0); }
EXAMPLE 21(taban değiştirme)
#include <stdio.h> #include <math.h> float log2(float); void main(){ float x; printf("sayi yi girin="); scanf ("%f",&x); printf("sonuc=%f\n\n",log2(x)); } float log2(float x)
f 5x 4 x
x 2)
{ return(log(x)/log(2)); }
EXAMPLE 22(SAYIYI MUTLAK DEERDEN BİŞE) #include <stdio.h> #include <stdlib.h> void main() { int x=-1576; printf("%d sayisinin mutlak degeri%d",x,abs (x); }
EXAMPLE 23(YUVARLAMA) #include <stdio.h> #include <math.h> int main(void) { double x=5.7,y=5.3,z=5.2; double t=-5.3; printf("x=%lf ceil(x)=%lf\n",x,ceil(x)); printf("y=%lf ceil(y)=%lf\n",y,ceil(y)); printf("z=%lf ceil(z)=%lf\n",z,ceil(z)); printf("t=%lf ceil(t)=%lf\n",t,ceil(t)); printf("x=%lf floor(x)=%lf\n",x,floor(x)); printf("y=%lf floor(y)=%lf\n",x,floor(y)); printf("z=%lf floor(z)=%lf\n",x,floor(z)); printf("t=%lf floor(t)=%lf\n",x,floor(t)); }
EXAMPLE 11(BUHATASIZ OLAN) #include<stdio.h> #include #include<stdlib.h> int BS,guess,s,Tahmininiz; void main() { giris:
rand(); BS=rand()%100; s=0; do { printf("Tahmininiz:"); scanf("%u",&guess); s++; if(guess>BS) printf("\t\tdecrease\n"); if(guess