100 likes | 113 Views
C Dili Temel Örnekler. 1den 50ye kadar dizilerin sayma. # include < stdio.h > # include < stdlib.h > main() { int i,matrix [50]; for (i=0;i<=49;i++){ matrix [i]=2*i+1; printf ("%d<br>", matrix [i]);} system (" pause "); }. 10 lu dizi. # include < stdio.h >
E N D
1den 50ye kadar dizilerin sayma • #include<stdio.h> • #include<stdlib.h> • main() { • inti,matrix[50]; • for(i=0;i<=49;i++){ • matrix[i]=2*i+1; • printf("%d\n",matrix[i]);} • system("pause"); • }
10 lu dizi • #include<stdio.h> • #include<stdlib.h> • intfind(int x[]); • #define N 10 • main() { • intgrades[N]={23,54,9,78,96,55,34,21,7,8}; • intmin; • min=find(grades); • printf("Themin element of theArray is=%d",grades); • intfind(int x[]); • { • inti,ek; • ek=x[0]; • for(i=1;i<N;i++){ • if(x[i]<ek) • ek=x[i]; } • return ek; • } • system("pause"); }
Bir sayinin karesi • #include<stdio.h> • #include<stdlib.h> • int karesi(int); • main(){ • intx,y; • printf("Karesi alinacaksayiyi giriniz:"); • scanf("%d",&x); • y=karesi(x); • printf("Sayinin karesi %d'dir.",y); • system("pause");} • int karesi(int a){ • int b; • b=a*a; • return b; • }
Çemberin alan çevresi • #include<stdio.h> • #include<stdlib.h> • #include<math.h> • floatarea(float); • floatcircumference(float); • float pi=3.1416; • main(){ • floata,b; • a=area(10.0); • b=circumference(10.0); • printf("Area=%f,circumference=%f\n",a,b); • system("pause"); • } • floatarea(floatradius){ • return(pi*radius*radius); } • floatcircumference(floatradius){ • return(2*pi*radius); }
Dizi ortalaması • #include<stdio.h> • #include<stdlib.h> • main(){ • intgrades[5], total=0,k; • floatavg; • for(k=0;k<5;k++){ • printf("%d element=",k+1); • scanf("%d", &grades[k]); } • for(k=0;k<10;k++){ • total=total+grades[k]; } • avg=total/5,0; • printf("Average of grades=%f",avg); • system("pause"); • }
Faktöryel • #include<stdio.h> • #include<stdlib.h> • long factorial(long); • main() { • printf("%d\n",factorial(5)); • system("pause"); • } • long factorial(long number) • { • if(number<=0) • return 0; • else • return(number*factorial(number-1)); • }
Örnek • #include<stdio.h> • #include<stdlib.h> • main(){ • inta,b,c,d,e; • a=10; • b=4,3; • c=4,8; • d='A'; • e=4,3+4,8; • printf("a=%d\n",a); • printf("b=%d\n",b); • printf("c=%d\n",c); • printf("d=%d\n",d); • printf("e=%d\n",e); • printf("b+c=%d\n",b+c), • system("pause"); }
Örnek1 • #include<stdio.h> • #include<stdlib.h> • main(){ • floata,b,c,d,e,f; • a=1/3; • b=1/30; • c=1,0/3; • d=1,0/3,0; • e=(float)1/3; • f=(float)(1/3); • printf("1 dividedby 3 is %f\n",a); • printf("1 dividedby 30 is %f\n",b); • printf("1,0 dividedby 3 is %f\n",c); • printf("1,0 dividedby 3,0 is %f\n",d); • printf("\n Thefloatcasting of\n"); • printf("1 dividedby 3 is %f\n",e); • printf("\n f equals %f\n",f); • system("pause"); }
Zar atma • #include<stdio.h> • #include<conio.h> • #include<stdlib.h> • voiddice(void); • main(){ • printf("Pressanykeytothrowdice,'q' keytoquit...\n"); • while(getch()!='q'){ • dice(); • } • system("pause"); • } • voiddice(void) { • printf("Youget %d onemorethrow?\n",rand()%6+1); • }