PTA c语言分享(第二弹:实验2 选择结构)

大家好,欢迎来到我的学习空间:

 1.

#include <stdio.h>
#include <math.h>
int main()
{
    double x,result;
    scanf("%lf",&x);
    
   
    if(x>=0) 
    {result=pow(x,0.5);}
    if(x<0)
    {    
    result=pow(x+1,2)+2*x+1.0/x;
    }
        printf("f(%.2lf) = %.2lf",x,result);
   return 0;
}

2.

#include <stdio.h>
#include <math.h>
int main()
{
    int N,i;
    scanf("%d",&N);
    
   
    i=N%5;
    if(i==1||i==2||i==3){printf("Fishing in day %d",N);}
    if(i==0||i==4){printf("Drying in day %d",N);}
       
   return 0;
}

3.

#include <stdio.h>
int main()
{
    int a,b,h,f,fen;
    scanf("%4d %4d",&a,&b);
    
   
    if(b%100<a%100) 
    {f=b%100+60-a%100;
      h=b/100-1-a/100;}
    else{    
    f=b%100-a%100;
         h=b/100-a/100;
    }
        printf("%02d:%02d",h,f);
}

4.

#include <stdio.h>
#include <math.h>
int main()
{
    int x,y,h;
    char ch;
    scanf("%d %c %d",&x,&ch,&y);
    if(ch=='+')
    {h=x + y;
    printf("%d",h);}
    else if(ch=='-')
    {h=x - y;
    printf("%d",h);}
    else if(ch=='*')
    {h=x * y;
    printf("%d",h);}
    else if(ch=='/')
    {h=x / y;
    printf("%d",h);}
    else if(ch=='%')
    {h=x % y;
    printf("%d",h);}
    else {printf("ERROR");}
   return 0;
}

5.

#include <stdio.h>
#include <math.h>
int main()
{
    
    char ch;
    scanf("%c",&ch);
    if(ch>='0'&&ch<='9')
    {
    printf("This is a digit.");}
    else if(ch>='A'&&ch<='Z')
    {
    printf("This is a capital letter.");}
    else if(ch>='a'&&ch<='z')
    {
    printf("This is a small letter.");}
    
    else {printf("Other character.");}
   return 0;
}

6.

#include <stdio.h>
#include <math.h>
int main()
{
    
    int x;
    scanf("%d",&x);
    if(x>=60)
    {
    printf("C语言成绩合格。");}
   
    else {printf("C语言成绩不合格。");}
   return 0;
}

7.

#include <stdio.h>
#include <math.h>
int main()
{
    
    int year,month,date,day1=0,day2;
    scanf("%4d-%d-%d",&year,&month,&date);
    
    
    switch(month){
    
    case 12:day1+=30;
    case 11:day1+=31;
    case 10:day1+=30;
    case 9:day1+=31;
    case 8:day1+=31;
    case 7:day1+=30;
    case 6:day1+=31;
    case 5:day1+=30;
    case 4:day1+=31;
    case 3:
    if(year%4==0&&year%100!=0||year%400==0)
    {day1+=29;}
    else{day1+=28;}
    case 2:day1+=31;
    case 1:day1+=date;}
    
    if(year%4==0&&year%100!=0||year%400==0)
    {day2=366+1-day1;
    printf("还有%d天到新年",day2);}
   
    else {day2=365+1-day1;
        printf("还有%d天到新年",day2);}
   return 0;
}

8.

#include <stdio.h>
#include <math.h>
int main()
{   int p,w,s;
    double f,d;
    scanf("%d %d %d",&p,&w,&s);
    
   
    if(s<250) 
    {   d=0;}
    else if(s>=250&&s<500) 
    {   
       d=0.02;}
    else   if(s>=500&&s<1000) 
    {  d=0.05;}
     else if(s>=1000&&s<2000) 
    {   d=0.08;}
     else if(s>=2000&&s<3000) 
    {   d=0.1;}
    else{d=0.15;}
    f=p*w*s*(1-d);
    printf("freight=%.2lf",f);
   return 0;
}

今天的分享就到此告一段落了!!!

很高兴能在这里分享我的历程,仅做分享!!!

感兴趣的小伙伴可以留下你们的一键三连吗(●'◡'●)!!!

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值