Posts

Showing posts from October, 2013

Switch Case Operations

Image
Today I want to write about switch-case statement in c. This statement is a totaly saver in some situation. However, It has a tricky point and before using that you should learn that tricky point. I want to explain it with an example code : #include <stdio.h> main() { int Grade = 'A'; switch( Grade ) { case 'A' : printf( "Perfect\n" ); case 'B' : printf( "Good\n" ); case 'C' : printf( "OK\n" ); case 'D' : printf( "Danger\n" ); case 'F' : printf( "Pr

Letter Grade Calculater

Image
 I write a program which calculate the letter grade.  It is also simple program. I started to use dynamic  memory allocation with this program.    Here is the code : #include <stdio.h> #include <stdlib.h> void pass(double *a,int b,char *c) {     int i;     double d=0;     for(i=0;i<b;i++)     {         d+=a[i];     }     d/=(double)b;     if(d<101&&d>89)     *c='A';     else if(d<90&&d>79)     *c='B';     else if(d<80&&d>69)     *c='C';     else if(d<70&&d>59)     *c='D';     else if(d<60&&d>0)     *c='F';     else     *c='E'; } int main() {     int num,i;     double *grades;     char note;     printf("Enter the number of grades\n");     scanf("%d",&num);     grades=(double *)calloc(num,sizeof(double));     for(i=0;i<num;i++)     {         printf("Enter a numeric grade between 0-100\n");         scanf(&q

Matrix Problems in C

In lab courses we tried to build a program which solves the matrix equation ( transpose, addition, multiplication). Here is the simple sample of the code it could be the first step for you. If  you can try by yourself, it will be good for you.   #include <stdio.h> #include <stdlib.h> #include <string.h> void scalar_mul(int dz[3][2],int k) {     int i,j;     for(i=0;i<3;i++)     {         for(j=0;j<2;j++)         {             dz[i][j]*=k;         }     } } void add(int dz[3][2],int dz1[3][2],int toplam[3][2]) {     int i,j;     for(i=0;i<3;i++)     {         for(j=0;j<2;j++)         {             toplam[i][j]=dz[i][j]+dz1[i][j];         }     } } void transpose(int dz[3][2],int swap[2][3]) {     int i,j;     for(i=0;i<3;i++)     {         for(j=0;j<2;j++)         {             swap[j][i]=dz[i][j];         }     } } int main() {     int matrix1[2][3]={{1,0,0},{0,0,1}},i,j,matrix2[3][2]={{-1,3},{6,-6},{-3,-1}},transpos[2][3];     int matrix3[3][2]={{

IEEExtreme Coding Competition 7.0

Image
We attended International IEEExtreme Coding Competition 7.0 . Today I write the code that we write in competition Problem_Aj. That problem mainly easy but it has some tricky points :)  Here is the code : #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() {     int i,num,*p,v=0;     //printf("Enter the piece value\n");     scanf("%d",&num);     p=(int*)malloc(num*sizeof(int));     //printf("Enter the slope value\n");     for(i=0;i<num;i++)     {         scanf("%d",&p[i]);         printf(" ");     }     for(i=0;i<num;i++)     {         v+=p[i];         if(v<0)         {             v=0;         }     }     printf("%d\n",v);     return 0; }

String Yapısı

Image
String yapısını gördükten sonra basit bir program ile pekiştirme yapabilirsiniz mesela bir isim girdisi alınsın ve bu ismi tersten yazan bir çıktı verilsin Kod: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() {     char ad[10],adt[10],*p,*pt;     int i,uz;     printf("Adinizi Giriniz\n");     gets(ad);     uz=strlen(ad);     printf("Ismin harf sayisi ==> %d\n",uz);     p=&ad[uz-1];     pt=adt;     printf("%Ismin Tersten Yazilisi ===>  ");     for(i=0;i<uz;i++)     {         printf("%c",*p);         *pt=*p;         pt+=1;         p-=1;     }     printf("\n");     pt=adt;     for(i=0;i<uz;i++)     {         printf("%s\n",pt);         pt++;     }     p=&ad[uz];     for(i=0;i<uz;i++)     {         p--;         printf("%s\n",p);            }     system("PAUSE");     return 0; }  

Perfect Number Finder

Image
  Perfect Number Finder sample code. Here is the code: #include<stdio.h> int main(){   int n,i=1,toplam=0;   printf("Mukemmel sayi olup olmadigini kontrol etmek istediginiz sayiyi girin\n");   scanf("%d",&n);   while(i<n){       if(n%i==0)            toplam=toplam+i;           i++;   }   if(toplam==n)       printf("%d sayisi mukemmel sayi\n",i);   else       printf("%d sayisi mukemmel sayi degil\n",i);   return 0; }

Asal Sayı Hesaplama Programı

 Asal sayı hesaplama programı  Kod : #include <stdio.h> int i,c,d; int main() { for(i=2;i<=1000;i++) { d=1; for (c=2;c<i;c++) { if (i%c==0) {d=0;} } if (d==1) {printf("%d\n",i);} } system("PAUSE"); return 0; }

Floyd Üçgeni

Image
Bu program girilen bir satır sayısı değerine göre Floyd Üçgeni oluşturmaktadır  Kod: # include <stdio.h> int main() {     int a,b,c,sayi=1;         printf("satir sayisini giriniz");     scanf("%d",&c);         for (a=1;a<=c;a++){         for (b=1;b<=a;b++){             printf("%d ",sayi);             sayi++;         }         printf("\n");     }     system("PAUSE");     return 0; }            Çıktısı :  

Kelvin-Fahrenheit-Celcius Dönüştürme Programı

C'de Basit Kelvin-Fahrenheit-Celcius Dönüştürme Programı (Formüle Göre) printf ve scanf kullanarak yazılmıştır. Not: system("cls"); ekranda ki yazıları temizler. #include <stdio.h> float K,F,C,a,b; int main(){     printf("Hangi Birimi Kullanmak Isterseniz Basinda ki Rakami Girin\n");     printf("1\tKelvin\n2\tFahrenheit\n3\tCelcius\n");     scanf("%f",&a);     system("cls");     if(a==1){         printf("1\tFahrenheit\n2\tCelcius\n");         printf("Cevirmek Istediginiz Birimin Basinda ki Rakami Girin\n");         scanf("%f",&b);         system("cls");         printf("Kelvin Degerini Girin\n");         scanf("%f",&K);         system("cls");         if(b==1){             F=K-459.67;             printf("°F ==> %f",F);}             else if(b==2){                 C=K-273.15;                 printf("°C ==>

Programlama Macerası

Program yazmaya C ile başladım ama C çok mu etkili bir yazılım dili diye sorarsanız kesinlikle değil. Başlangıç olarak basit programlarla başladım ve bunları da paylaşmak istedim yavaş yavaş kendimi de geliştirmeye çalışıyorum yeni programlarla görüşmek üzere :)

C'de Basit Bir ATM Programı Yazma

Programlamaya yeni başlıyanlar için sadece printf ve scanf kullanarak yazılan basit bir ATM programı :) #include<stdio.h> int parola=1905,number,a; float kalan=100.00,cek,yat; main() {parola_gir:     printf("---parolayi giriniz---\n"); scanf("%d",&parola); if(parola==1905){     basla:     printf("---Para Cekmek Icin 1'e Basiniz Para Yatirmak Icin 2'ye Basiniz\n");     scanf("%d" , &a);     if(a==1){     printf("---Bakiye ==> %2f---", kalan );     printf("---cekmek istediginiz degeri giriniz---\n");     scanf("%f", &cek);        if(cek<=kalan){     kalan-=cek;     printf("---Bakiye ==> %f---", kalan) ;     for( ; ; ){     printf("---cikmak icin 0(sifir)'a basin devam etmek icin herhangi bir rakam giriniz---\n");     scanf("%d",&number);     if(number==0){     return 0;}     else     goto basla;}}         else {     pri