In The Name Of Allah

Programming1-Sila Baca dan beri comment atau fahami dengan betul2. .INSYAALLAH

Sunday 10 March 2013

introduction to Array

Contoh cara nak buat C program untuk array :


#include<stdio.h>

void main()
{
    int c;
    int num;
    int c_1_50,c_51_100,c_101_150,c_151_200;

    c_1_50=c_51_100=c_101_150=c_101_150=c_151_200=0;

    printf("Masukkan 30 integer [1 hingga 200] :\n");

    for(c=1;c<=30;c++)
    {
        printf("integer %d :",c);
        scanf("%d",&num);

    if(num>=1 && num <=200)
    {
        if(num>=1 && num <=50)
        {
            c_1_50++;
        }

        else if(num>=51 && num<100)
        {
            c_51_100++;
        }

        else if(num>=101 && num<150)
        {
            c_101_150++;
        }

        else if(num>=151 && num<200)
        {
            c_151_200++;
        }
        else
        {
            printf("wrong input\n");

        }
    }
    else
    {

        printf("Salah input. .mesti 1 hingga 200 sahaja\n");
        c--;
    }

    }

    printf("1   hingga 50 \t\t:%d\n",c_1_50);
    printf("51  hingga 100\t\t:%d\n",c_51_100);
    printf("101 hingga 150\t\t:%d\n",c_101_150);
    printf("151 hingga 200\t\t:%d\n",c_151_200);
    printf("total \t\t\t :%d\n",c_1_50+c_51_100+c_101_150+c_151_200);
}

Dan kat sini contoh video untuk introduction to array  dan exersices kat atas ni ;

https://www.youtube.com/watch?v=uJi2__5woc4&feature=em-share_video_user

1 comment:

  1. em tuk array nie, .dia akan display cara yang lebih mudah tuk c program. .

    ReplyDelete