12.28作业

0.

int a,b,c;  

a=1;b=1;c=1;

a=++b + ++c;

printf("\n%d,%d,%d",a,b,c);//a=4,b=2,c=2

a=b++  + c++;

printf("\n%d,%d,%d",a,b,c);//a=4,b=3,c=3

a=++b || c++;(逻辑运算符规则)

printf("\n%d,%d,%d",a,b,c);//a=1,b=4,c=3

a=b-- && --c;  

printf("\n%d,%d,%d",a,b,c);//a=1,b=3,c=2

a=b>c?b++:c++;  

printf("\n%d,%d,%d",a,b,c);//a=3,b=4,c=2

(红字体是答案)

1.

#include

int main(int argc, const char *argv[])

{

double a, b;

char c;

scanf(“%lf%c%lf”,&a,&c,&b);

switch(c)

{

case'+':printf("%f\n",a+b);break;

case'-':printf("%f\n",a-b);break;

case'*':printf("%f\n",a*b);break;

case'/':printf("%f\n",a/b);break;

default:printf("输出错误\n");

}

}

2.

#include

int main(int argc, const char *argv[])

{

int a,b,c;

scanf(“%d%d%d”,&a,&b,&c);

if(a+b>c&&a+c>b&&b+c>a)

{

if(a==b||b==c||a==c)

{

    if(a==b&&b==c)

{

      printf(“是等边三角型\n”);

}

         else

{

 printf(“是等腰三角型\n”); 

}

     }

else

{

printf(“是普通三角型\n”);

}

else

{

    printf(“不是三角型\n”);

}

return 0;

}

3.

#include

int main(int argc, const char *argv[])

{

int num=0,ge=0,shi=0,bai=0;

scanf(“%d”,&num);

ge=a%10;
shi=a%100/10;
bai=a/100;

  if(num>=0&&num<10)

  {

     if(a/2==0)

     {

        printf(“输入的数是一位数且是偶数\n”);

     }

     else

     {

        printf(“输入的数是一位数且是\n”);

     }

  }

      if(num>=10&&num<100)

      {

         if(ge%shi==0)

         {

            printf(“输入的数是位数且个位数能被十位数整除\n”);

         }

         else

         {

            printf(“输入的数是位数且个位数不能被十位数整除\n”);

         }

              if(num>=100&&num<1000)

              {

                  if(ge*ge*ge+bai*bai*bai+shi*shi*shi==a)

                     {

                         printf("是百位数且是水仙花数\n");

                     }

                  else

                     {

                         printf("是百位数且是水仙花数\n");

                     }

  }

return 0;

}

4.

#include

int main(int argc, const char *argv[])

{

char ch;

scanf(“%c”,&a);

if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))

{

   if(ch>='A'&&ch<='Z')

   {

      putchar(ch+32);

   }

          if(ch>='a'&&ch<='z')

          {

             putchar(ch-32);

          }

else

{

   printf(不是字母\n);

}

}

return 0;

}

5.

#include

int main(int argc, const char *argv[])

{

int day=0,year=0,m=0;

scanf("%d%d%d",&year,&m,&day);

switch(m)

{

    case 12:{

                if(day>31)

{

                printf("输入错误\n");

                }

        day =day+30;break;}

    case 11:

        day =day+31;break;

    case 10:

        day =day+30;break;

    case 9 :

        day =day+31;break;

    case 8 :

        day =day+31;break;

    case 7 :

        day =day+30;break;

    case 6 :                                                                                                            

        day =day+31;break;

    case 5 :

        day =day+30;break;

    case 4 :

        day =day+31;break;

    case 3 :

        day =day+28;break;

    case 2:

        day =day+31;break;

    case 1 :

        day=day;break;

}

if(year%4==0&&year%100!=0||year%400==0)

{

        if(m>2&&m<=12)

{

            day+=1;

        printf("是闰年且是这一年的第%d天\n",day);

        }

        else if(m>0&&m<=2)

{

            printf("是闰年且这是这一年的第%d\n",day);

        }

        else

            printf("输入错误\n");

}

else

{

        if(m>0&&m<=12){

    printf("是平年且这一年的第%d\n",day);

        }

        else

 {

        printf("输入错误\n");

        }

    }

    return 0;

}

你可能感兴趣的:(c语言,c++)