【C基础】练习

01

Description

 这是一道开启编程之路的入门题,要求是请输出 hello world

Input

不需要输入

Output

hello world

Sample Input 1   Sample Output 1

不需要        hello world

#include <stdio.h>
int main()
{
  printf("hello world");
  return 0;
}

02

Description

你的任务是计算a+b

Input

输入包含a和b,通过空格隔开

Output

需要输出a、b的和

Sample Input 1   Sample Output 1

1   4        5

#include <stdio.h>
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a + b);
}

 03

Description

读取一个65到122之间的整型数,然后以字符形式输出它,比如读取了97,输出字符a

Input

读取一个整型数,整型数 大于等于65,小于等于122

Output

输出整型数 在ASCII表中对应的字符

Sample Input 1   Sample Output 1

97          a

#include <stdio.h>

int main()
{
    int a;
    scanf("%d", &a);
    if (65 < a && a < 122)
    {
        printf("%c\n", a);
    }
    return 0;
}

 04

Description

判断某个年份是不是闰年,如果是闰年,请输出“yes”,否则请输出“no”

Input

输入一行,只有一个整数x (0<=x <=10000)

Output

输出只有一行字符

Sample Input 1   Sample Output 1

2000          yes

Sample Input 2   Sample Output 2
1999          no
#include <stdio.h>

int main()
{
    int x;
    scanf("%d", &x);
    if (x % 4 == 0 && x % 100 != 0 || x % 400 == 0)
    {
        printf("yes\n");
    }
    else {
        printf("no\n");
    }
    return 0;
}

 05

Description

读取一个整型数,字符,浮点数,分别到变量i,j,k中,然后将i,j,k直接相加并输出,小数点后保留两位小数,不用考虑输入的浮点数的小数部分超过了两位

Input

一个整型数,字符,浮点数

Output

i,j,k三个变量的求和值

Sample Input 1     Sample Output 1

  10  a  98.3      205.3

#include <stdio.h>

int main()
{
  int i;
  char j;
  float k;
  scanf("%d %c%f",&i,&j,&k);
  printf("%0.2f\n",i+j+k);
  return 0;
}

 

 

 

 

 

posted on 2022-07-18 11:26  默默努力就好  阅读(41)  评论(0)    收藏  举报