16-11-11 1601班上机作业

1、编写一个程序,要求用户输入两个数字。在程序使用一个或多个scanf()函数调用接收这些数字之后,用程序检查这些数字。如果第一个键入的数字大于第二个数字则输出消息“The first number is greater than the second”,否则输出消息“The first number is not greater than the second”.

#include<stdio.h>
int main()
{
    float a,b;
    scanf("%f %f",&a,&b);
    if(a>b) printf("The first number is greater than the second\n");
    else printf("The first number is not greater than the second\n");
    return 0;
}

2、输入3个数a,b,c,要求按由小到大的顺序输出。(注意:以下代码为C++)

#include<iostream>
#include<cstdlib>
#include<cstdio>
int main()
{
    using namespace std;
    float a[3];
    int i,j,k;
    float temp;
    scanf("%f %f %f",&a[0],&a[1],&a[2]);
    for(i=0;i<3;i++)
    {
        k=i;
        for(j=i;j<3;j++)
        {
            if(a[j]<a[k]) k=j;
        }
        temp=a[i];
        a[i]=a[k];
        a[k]=temp;
    }
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
    return 0;
}

3、编写一个程序,用scanf()函数接收一个字符并确定这个字符是否是一个小写字母。如果输入的字符是一个小写字母,显示消息“The character just entered is a lowercase letter”,如果输入的字符不是一个小写字母,显示消息“The character just entered is not a lowercase letter”。

#include<stdio.h>
int main()
{
    char a;
    scanf("%c",&a);
    if(a>='a'&&a<='z') printf("The character just entered is a lowercase letter\n");
    else printf("The character just entered is not a lowercase letter\n");
    return 0;
}

4、有一个函数 X (X<1)
y= 2X-1 (1≤X<10)
3X-11 (X≥10)
要求输入x值,输出y值。(注意:以下代码为C++)

#include<iostream>
#include<cstdlib>
#include<stdio.h>
int main()
{
    using namespace std;
    float x,y;
    scanf("%f",&x);
    if(x<1) y=x;
    else if(x>=1&&x<=10) y=2*x-1;
    else y=3*x-11;
    cout<<y<<endl;
    return 0;
}

5、输入百分制成绩,要求输出成绩等级’A’,’B’,’C’,’D’,’E’。90分以上为’A’,80-89分为’B’,70-79分为’C’, 60-69分为’D’,60分以下为’E’

#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d",&a);
    b=a/10;
    switch(b)
    {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
        printf("E\n");
        break;
    case 6:
        printf("D\n");
        break;
    case 7:
        printf("C\n");
        break;
    case 8:
        printf("B\n");
        break;
    case 9:
    case 10:
        printf("A\n");
        break;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值