5.23再看一遍

时间:2022-12-25 19:51:16

printf
#include <stdio.h>
int main ()
{
         int a=125 ;
                 printf("%10d",a);
                 return 0;
}

#include <stdio.h>
int main ()
{
         int a=125 ;
                 printf("%-10d",a);
                 return 0;
}

#include <stdio.h>
int main ()
{
         float a=125.25 ;
                 printf("%.2f\n",a);
                 return 0;
}

打印float的整数部分
#include <stdio.h>
int main ()
{
         float a=125.25 ;
                 printf("%.0f\n",a);
                 return 0;
}


#include <stdio.h>
int main ()
{
         int a=5,b=3,c=25,d=12;
                 float qu;
                 int re,in ,de;
                 qu=a/b;
                 re=a%b;
                 in=++c;
                 de=--d;
                 printf("wei %f\n",qu);
                 printf("yushu wei %d\n",re);
                 printf("jia 1 hou wei %d\n",in);
                 printf("jian 1 hou wei %d\n",de);
                 return 0;
}

#include<stdio.h>
int main ()
{
      int  num;
          printf("\n请输入一个整数:");
          scanf("%d",&num);
          if((num%2)==0)
             printf("%d是偶数;\n",num);
          else
             printf("%d是奇数;\n",num);
          return 0;
}


#include<stdio.h>
int main ()
{
   int num ;
   printf("\n输入一个数字:");
   scanf ("%d",&num);
   if((num%5)==0)
   printf("\n该数能被5整除\n");
   else
   printf("\n该数不能被5整除\n");
}

13
#include <stdio.h>
int main()
{
  int a=1,b=13;
  if(a++||b--)
  printf("%d",b);
  return 0;
}


#include <stdio.h>
int  main()

    float rate1,rate2,rate3; 
    double discount,total; 
    printf("\n请输入第一种商品的价格:"); 
        scanf("%f",&rate1); 
        printf("\n请输入第二种商品的价格:");
        scanf("%f",&rate2);
        printf("\n请输入第三种商品的价格:");
        scanf("%f",&rate3);
        total=rate1+rate2+rate3;
        if((rate1>50)||(rate2>50)||(rate3>50)||(total>100))
        {       
        discount=0.15*total;    
        total=total-discount;   
        printf("\n折后总价为:%6.2f\n",total);
        }
        else    
        printf("\n总价为:%6.2f\n",total);
    return 0;

}

#include <stdio.h>
int main()
{
    int year;
        printf("输入你要判断的年份\n");
        scanf("%d",&year);
        if((year%4)==0&(year%100!=0)||(year%400)==0)
           printf("是闰年");
        else
           printf("不是闰年");
    return 0;
}