c语言 面试题


     

     //经典7

    //星期一   Monday

    //星期二   Tuesday

    //星期三   Wednesday

    //星期四   Thursday

    //星期五   Friday

    //星期六   Saturday

    //星期日   sunday

    //请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续判断第二个字母

    char week1;

    char week2;

    printf("星期一   Monday \n星期二   Tuesday \n星期三   

Wednesday  \n星期四   Thursday  \n星期五   Friday  \n星期六   Saturday   \n星期日   

sunday\nplease enter a letter\n");

    scanf("%c",&week1);

    switch(week1)

    {

        case('M' 'm'):printf("the answer is Monday\n");

            break;

        case'W':printf("the answer is Wednesday\n");

            break;

        case('F' 'f'):printf("the answer is Friday\n");

            break;

       case('S' 's'):

        {

            printf("please enter the second letter\n");

            scanf("%c",&week2);

            getchar();

            if(week2 == ('a' 'A'))

                printf("the answer is Saturday\n");

            else

                if(week2 == ('u' 'U'))

                    printf("the answer is Sunday\n");

                else

                    printf("there is no answer\n");

        }

            break;

        case('T' 't'):

        {

            printf("please enter the second letter\n");

            scanf("%c",&week2);

            getchar();

            if(week2 == ('U' 'u'))               printf("the answer is Tuesday\n");

            else               if(week2 == ('H' 'h'))

                printf("the answer is Thursday\n");

            else

              printf("there is no answer\n");

        }

            break;

        default:

            printf("there is no correct answer\n");

            break;

    }

     

    // 经典8

    //有1000000个数,每个数取值范围是0-999999找出其中重复的数,重复次数

    int a[1000000] = {0}, b[1000000] = {0}, count = 0;

    for(int i = 0 ; i < 1000000 ; i ++){

        a[i] = arc4random()%1000000;

        b[a[i]]++;

    }

    for (int j = 0 ; j < 1000000; j++) {

        if(b[j] > 1){

            count++;

            printf("重复数是%d \n",j);

        }

    }


你可能感兴趣的:(C语言,经典)