首页 > 代码库 > 160809307 张浩飞

160809307 张浩飞

#include<stdio.h> 
void zy1()
{
    int a;
    printf("五级制成绩");
    char score;
    scanf("%c",&score);
    switch (score)
    {
        case A:
              printf("90~100");
              break;
        case B:
              printf("80~89");
              break; 
        case C:
              printf("70~79");
              break;
        case D:
              printf("60~69");
              break;
        case E:
              printf("0~59");
              break; 
    }   
} 
void zy2()
{
    int a;
    printf("请输入题目序号1-9:\n\t1.C语言基本数据类型及其占用的内存空间大小分别是:\n\t2.算数运算符有:+-*/% ++ --\n\t3.关系运算符有:> <    ==  >=  <=  !=   <>\n\t4.逻辑运算符的优先顺序是:! &&  ||\n\t5.赋值运算符有:= +=  -=  *=  /=  %=\n\t下面代码的输出结果是什么?请解释原因。\n\t6.\n\tchar c=132;\n\t printf(“%d”,c);\n\t7.\n\tint a=-7;\n\t printf(“%d”,a>>1);\n\t8.\n\tint a=7;\n\tint b=8;\n\tprintf(“%d”,a&b);\n\t9.\n\tint a=7;\n\tint b=8;\n\tprintf(“%d”,a^b);\n\n请选择小题");
    scanf("%d",&a);
    switch(a)
    {
        case 1:
        printf("1.C语言基本数据类型及其占用的内存空间大小分别是:int:4字节,short[int]:2字节,long[int]:4字节,unsigned[int]:4字节,unsigned short[int]:2字节,unsigned long[int]:4字节,char:1字节,float:4字节,double:8字节。");
        break;
        case 2:
        printf("2.算数运算符有:+,?,*,/,%,++,??。");
        break;
        case 3:
        printf("3.关系运算符有:>,<,==,>=,<=,!=,<>。");
        break;
        case 4:
        printf("4.逻辑运算符的有限顺序是:!,&&,||。");
        break;
        case 5:
        printf("5.赋值运算符有:=,+=,-=,*=,/=,%=。");
        break;
        case 6:
        printf("6.char c=132;printf(\"%d\",c);解:char的范围为-127~128,132超出范围,132变为二进制是10000100,因为在计算机中0为正1为负所以该数为负数,而负数需要取反加一,所以该数为-01111011+1=-01111100,输出结果为-124。");
        break;
        case 7:
        printf("7.int a=7;printf(\"%d\",a?1);\n解:7:00000000 00000000 00000000 00000111\n-7:11111111 11111111 11111111 11111001(取反加一)\na>>1:111111111 11111111 11111111 1111100(右移一位)\n-00000000 00000000 00000000 00000100(取反进一)\n所以向右移1位为-4.");
        break;
        case 8:
        printf("8.int a=7;int a=8;printf(\"%d\",a&b);\n解:a=7:00000000 00000000 00000000 00000111\nb=8:00000000 00000000 00000000 00001000\n因为没有相同为1的项\n所以输出值为0.");
        break;
        case 9:
        printf("9.int a=7;int b=8;printf(\"%d\",a^b);\n解:a=7:00000000 00000000 00000000 00000111\nb=8:00000000 00000000 00000000 00001000\n00000000 00000000 00000000 00001111\n所以输出值为15.\n");
        break;
    }
}

void zy3()
{
    int a;
    printf("倒三角形");    
    printf("**********\n");
    printf("*********\n");
    printf("********\n");
    printf("*******\n");
    printf("******\n");
    printf("*****\n");
    printf("****\n");
    printf("***\n");
    printf("**\n");
    printf("*\n");
}

    void zy4()
{
    int a;
    printf("猜数字");
    printf("请猜一个整数\n你的猜测是:");
    int predefined=rand()%100;
    int a;
    scanf("%d",&a);
    int b;
    for(b=1;b<=10;b++)
    {
        if(predefined==a)
        {
            printf("恭喜你猜对啦"); 
        }
        else if(predefined<a)
        {
            printf("猜大了再猜:");
            scanf("%d",&a); 
        }
        else
        {
            printf("猜小了再猜:");
            scanf("%d",&a) ;
        }
        //scanf("%d",&a);
    }
    }
void zy5() 
{
    int a;
    printf("最大公倍数和最小公约数");
    {
    int a,b,i,min,max;    
    scanf("%d%d",&a,&b);
     max = 1;
    for(i=2;i<=a;i++)
    {
        if(a%i==0 && b%i==0)
            max = i;
    }
     min = a*b;
    for(i=a*b-1;i>=a;i--)
    {
        if(i%a==0 && i%b==0)
            min = i;
    }
     printf("%d\n%d\n",max,min);    
     return 0;
}
        int choice;
    printf(         "作业及答案查询系统\n");
    printf(         "1.第一次作业\n");
    printf(         "2.第二次作业\n");
    printf(         "3.第三次作业\n");
    printf(         "4.第四次作业\n");
    printf(         "5.第五次作业\n");
    printf(    "请选择:");
    scanf("%d",&choice);
    switch(choice)
    {   
        case 1:
          zy1();
         break; 
        case 2:
          zy2();
        break;
        case 3:
          zy3();
         break;
        case 4:
          zy4();
         break;
        case 5:
          zy5();
         break;
            
    }
    
}

 

160809307 张浩飞