1 Kasım 2010 Pazartesi

C dilinde if-else ve switch-case yapısı örneği

 if-else ve switch-case yapısınu kullanarak kullanıcıdan doğum tarihinin gün ve ayını alarak burcunu bulan program...
---------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <sTdlib.h>
main()
{
    int ay,gun;
    printf("Dogum tarihinizin ayini giriniz="); scanf("%d",&ay);
    printf("Dogum tarihinizin gununu giriniz="); scanf("%d",&gun);
    if (gun<0 || gun>31 || ay<0 || ay>12)
        printf("YANLIS GIRIS YAPTINIZ");
    switch (ay)
    {
        case 1:
            if (gun>=1 && gun<=20)
                {
                    printf("OGLAK"); exit(0);
                }
            else
                {
                     printf("KOVA"); exit(0);
                }
       
case 2:
            if (gun>=1 && gun<=19)
                {
                    printf("KOVA"); exit(0);
                }
            else
                {
                     printf("BALIK"); exit(0);
                }
        case 3:
            if (gun>=1 && gun<=20)
                {
                    printf("BALIK"); exit(0);
                }
            else
                {
                     printf("KOC"); exit(0);
                }
        case 4:
            if (gun>=1 && gun<=20)
                {
                    printf("KOC"); exit(0);
                }
            else
                {
                     printf("BOGA"); exit(0);
                }
        case 5:
            if (gun>=1 && gun<=20)
                {
                    printf("BOGA"); exit(0);
                }
            else
                {
                     printf("İKİZLER"); exit(0);
                }
        case 6:
            if (gun>=1 && gun<=21)
                {
                    printf("İKİZLER"); exit(0);
                }
            else
                {
                     printf("YENGEC"); exit(0);
                }
        case 7:
            if (gun>=1 && gun<=22)
                {
                    printf("YENGEC"); exit(0);
                }
            else
                {
                     printf("ASLAN"); exit(0);
                }
        case 8:
            if (gun>=1 && gun<=23)
                {
                    printf("ASLAN"); exit(0);
                }
            else
                {
                     printf("BASAK"); exit(0);
                }
        case 9:
            if (gun>=1 && gun<=23)
                {
                    printf("BASAK"); exit(0);
                }
            else
                {
                     printf("TERAZI"); exit(0);
                }
        case 10:
            if (gun>=1 && gun<=23)
                {
                    printf("TERAZI"); exit(0);
                }
            else
                {
                     printf("AKREP"); exit(0);
                }
        case 11:
            if (gun>=1 && gun<=22)
                {
                    printf("AKREP"); exit(0);
                }
            else
                {
                     printf("YAY"); exit(0);
                }
        case 12:
            if (gun>=1 && gun<=21)
                {
                    printf("YAY"); exit(0);
                }
            else
                {
                     printf("OGLAK"); exit(0);
                }

    }
}