小白如何快速入门C语言,牛客网入门编程带给你自信(前42道)

目录

一,前言

二,题目及答案

1,实践出真知

2,我是大V

3,有容乃大

4,小飞机

5,缩短二进制

6,十六进制转十进制

7,printf返回值

8,成绩输入输出

9,学生基本信息输入输出

10,字符金字塔

11,ASCII码

12,出生日期的输入输出

13,按照格式输入并交换输出

14,字符转ASCII码

15,计算表达式的值

16,计算带余除法

17,反向输出一个四位数

18,kiki算数

19,浮点数的个位数字

20,你能活多少秒

21,时间转化

22,总成绩和平均数的计算

23,计算体重指数

24,计算三角形的周长和面积

25,计算球体的体积

26,大小写的转换

27,2 的n次方的计算

28,kiki和酸奶

29,发布信息

30,输入学生信息

31,计算平均成绩

32,进制A+B

33,判断字母

34,健康评估

35,网购

36,变种水仙花

37,争夺前五名

38,竞选社长

39,你是天才吗

40,完美成绩

41, 及格分数

42,判断整数奇偶数

三,总结


一,前言

自己每天练习十道C语言编程入门题,我提供答案不一定是最优,仅供参考,本片提供前四十二道编程的答案,拒绝做伸手党,自己找出错误才能提升自我,题目具体内容参考牛客网,后续会继续更新。

二,题目及答案


1,实践出真知

#include<stdio.h>
int main()
{
    printf("Practice makes perfect!");
    return 0;
}

2,我是大V

#include<stdio.h>
int main()
{
    printf("v   v\n");
    printf(" v v\n");
    printf("  v");
    return 0;
}

3,有容乃大

#include<stdio.h>
int main()
{
 int a,b,c,d;
    a =sizeof(short);
    b =sizeof(int );
    c =sizeof(long );
    d =sizeof( long long);
    printf("The size of short is %d bytes.\n" , a );
    printf("The size of int is %d bytes.\n", b );
    printf("The size of long is %d bytes.\n", c );
    printf("The size of long long is %d bytes.", d );
    return 0;
}

4,小飞机

#include<stdio.h>
int main()
{
    printf("     **     \n");
    printf("     **     \n");
    printf("************\n");
    printf("************\n");
    printf("    *  *    \n");
    printf("    *  *    \n");
        return 0;
}    

5,缩短二进制

#include<stdio.h>
int main()
{
    printf("0%o 0X%X\n",1234,1234);
    return 0;
}

6,十六进制转十进制

#include<stdio.h>
int main()
{
   printf("%15d\n",0XABCDEF);
    return 0;
}

7,printf返回值

#include <stdio.h>
int main()
{
    printf("\n%d\n",printf("Hello world!"));
}

8,成绩输入输出

#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("score1=%d,score2=%d,score3=%d",a,b,c);
    return 0;
}

9,学生基本信息输入输出

#include<stdio.h>
int main()
{
    int a = 0;
    float b = 0;
    float c = 0;
    float d = 0;
    scanf("%d; %f, %f, %f\n", &a, &b, &c, &d);
    printf("The each subject score of  No. %d is %.2f, %.2f, %.2f.\n", a, b, c, d);  

    return 0;
}

10,字符金字塔

#include<stdio.h>
int main()
{
     char ch = getchar();
    for(int i = 1; i <= 5; i++)
    {
        for(int j = 1; j <= 5 - i; j++)
            putchar(' ');
        for(int j = 1; j <= i; j++)
        {
            putchar(ch);
            if(j != i)
                putchar(' ');
        }
        putchar('\n');
    }
}

11,ASCII码

#include<stdio.h>
int main()
{
    char a[] = {73,32,99,97,110,32,100,111,32,105,116,33};
    printf("%s",a);
    return 0;
}

12,出生日期的输入输出

#include<stdio.h>
int main()
{
    int year = 0,month =0,date = 0;
    scanf("%4d%2d%2d", &year,&month,&date);
    printf("year=%d\n",year);
    printf("month=%02d\n",month);
    printf("date=%02d\n", date);
    return 0;
}

13,按照格式输入并交换输出

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

14,字符转ASCII码

#include<stdio.h>
int main()
{
    char a = 0;
    scanf("%c",&a);
    printf("%d",a);
    return 0;
}

15,计算表达式的值

#include <stdio.h>
int main()
{
    int a = 40;
    int c = 212;
    int q=(-8+22) * a-10 +c /2;
    printf("%d",q);
    return 0;
}

16,计算带余除法

#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d",&a,&b);
    c = a / b;
    d = a % b;
    printf("%d %d", c,d);
    return 0;
}

17,反向输出一个四位数

#include<stdio.h>
int main()
{
    char a,b,c,d;
    scanf("%c%c%c%c",&a,&b,&c,&d);
    printf("%c%c%c%c",d,c,b,a);
    return 0;
}

18,kiki算数

#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d", &a, &b);
    c = (a + b) % 100;
    printf("%d",c);
    return 0;
}

19,浮点数的个位数字

#include<stdio.h>
int main()
{
    int a, c;
    float b;
    scanf("%f",&b);
    a = (int)b;
    c = a % 10;
    printf("%d",c);
    return 0;
}

20,你能活多少秒

#include<stdio.h>
int main()
{
    long age, b;
    scanf("%ld", &age);
    b = age * 31560000;
    printf("%ld", b);
    return 0;
}

21,时间转化

#include<stdio.h>
int main()
{
    int a;
    int b,c,d;
    scanf("%d", &a);
    b = a / 3600;
    c = (a % 3600) / 60;
    d = (a % 3600) % 60;
    printf("%d %d %d",b, c, d);
    return 0;
}

22,总成绩和平均数的计算

#include<stdio.h>
int main()
{
    float a, b, c;
    float sum = 0.00;
    float avage = 0.00;
    scanf("%f %f %f", &a, &b, &c);
    sum = a + b + c;
    avage = sum / 3.00;
    printf("%0.2f %0.2f", sum, avage);
    return 0;
}

23,计算体重指数

#include<stdio.h>
int main()
{
    int w,h;
    scanf("%d %d", &w,&h);
    float w2,h2,BMI;
    w2 = w;
    h2 = h / 100.0;
    BMI = 1.0 * w2 / (h2 * h2);
    printf("%.2f", BMI);
    return 0;
}

24,计算三角形的周长和面积

#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,c;
    float cir = 0.00;
    float area = 0.00;
    float p = 0;
    scanf("%d %d %d", &a,&b,&c);
    cir = a + b + c;
    p = cir / 2.0f;
    area = sqrt(p*(p-a)*(p-b)*(p-c));
    printf("circumference=%0.2f area=%0.2f", cir, area);
    return 0;
}

25,计算球体的体积

#include<stdio.h>
int main()
{
    double r = 0.0, V;
    scanf("%lf",&r);
    V = 4.0 / 3.0 * 3.1415926 * r * r *r; 
    printf("%0.3lf", V);
    return 0;
}

26,大小写的转换

#include<stdio.h>
int main()
{
    char ch = 0;
    while((ch = getchar()) != EOF)
    {
        if(ch >= 'A' && ch <= 'Z')
        {
            ch += 32;
        }
        putchar(ch);
    }
    return 0;
}

27,2 的n次方的计算

#include<stdio.h>
int main()
{
    int a;
    while(scanf("%d", &a) != EOF)
    {
        printf("%d\n",1 << a);
    }
    return 0;
}

28,kiki和酸奶

#include<stdio.h>
int main()
{
    int a=0, b=0, c=0, d;
    scanf("%d %d %d", &a,&b,&c);
   if(c % b == 0)
   {
        d = a - (c / b);
   }
    if(c % b !=0)
   {
        d = a - (c / b) - 1;
   }
    printf("%d", d);
    return 0;
}

29,发布信息

#include <stdio.h>
int main()
{
    printf("I lost my cellphone!");
    return 0;
}

30,输入学生信息

#include<stdio.h>
int main()
{
    printf("Name    Age    Gender\n");
    printf("---------------------\n");
    printf("Jack    18     man");
    return 0;
}

31,计算平均成绩

#include<stdio.h>
int main()
{
    float a,b,c,d,e,avage;
    scanf("%f %f %f %f %f", &a, &b, &c, &d, &e);
    avage = (a + b + c + d + e) / 5.0;
    printf("%0.1f", avage);
    return 0;
}

32,进制A+B

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

33,判断字母

#include<stdio.h>
int main()
{
    char a = 0;
    while(scanf("%c", &a) != EOF)
    {
         getchar();
        if((a >= 'a' && a <= 'z') || (a >='A' && a <= 'Z'))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

34,健康评估

#include<stdio.h>
int main()
{
    double weight,heigh,BMI;
    scanf("%lf %lf", &weight, &heigh);
    BMI = weight / (heigh * heigh);
    if(BMI >= 18.5 && BMI <= 23.9)
    {
        printf("Normal");
    }
    else
    {
        printf("Abnormal");
    }
    return 0;
}

35,网购

#include<stdio.h>
int main()
{
    float price,sum;
    int month,day,flag;
    scanf("%f%d%d%d",&price,&month,&day,&flag);
    if(month==11&&day==11)
    {
        sum=0.7*price;
        if(flag==1)
        {
            if(sum>=50)
                sum-=50;
            else 
                sum=0;
        }
    }
    else if(month==12&&day==12)
    {
        sum=0.8*price;
        if(flag==1)
        {
            if(sum>=50)
                sum-=50;
            else
                sum=0;
        }
    }
    else 
    {
        sum=price;
    }
    printf("%.2f",sum);
    return 0;
}

36,变种水仙花

#include<stdio.h>
int main()
{
    int a = 0;
    for(a = 10000; a <= 99999;a++)
    {
        int sum = 0;
        sum =(a / 10000)*(a % 10000) + (a /1000)*(a %1000) + (a / 100)*(a % 100) + (a / 10)*(a % 10);
    if(sum==a)
        printf("%d ", a);
    }
    return 0;
}

37,争夺前五名

#include<stdio.h>
int main()
{
    int n = 0, i = 0;
    scanf("%d", &n);
    int a[n];
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    int temp = 0, j = 0;
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - 1 -i; j++)
        {
            if (a[j] < a[j + 1])
            {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    printf("%d %d %d %d %d ", a[0], a[1], a[2], a[3], a[4]);
    return 0;
}

38,竞选社长

#include<stdio.h>
int main()
{
   int a_count = 0, b_count = 0;
   char ch = 0;
    while(scanf("%c", &ch) != EOF)
    {
        if(ch == '0')
            break;
        if(ch == 'A')
        {
            a_count++;
        }
        if(ch == 'B')
        {
            b_count++;
        }
    }
    if(a_count == b_count)
    {
        printf("E\n");
    }
    else if(a_count > b_count)
    {
        printf("A\n");
    }
    else
    {
        printf("B");
    }
    return 0;
}

39,你是天才吗

#include<stdio.h>
int main()
{
    int a;
    scanf("%d", &a);
    if(a >= 140)
    {
        printf("Genius");
    }
    return 0;
}

40,完美成绩

#include<stdio.h>
int main()
{
    int a = 0;
    scanf("%d", &a);
    if(a >= 90 && a <= 100)
    {
        printf("Perfect\n");
    }
    return 0;
}

41,及格分数

#include<stdio.h>
int main()
{
    int a;
     while(scanf("%d", &a) != EOF)
    {    
    if (a >= 60)
    {
        printf("Pass\n");
    }
    else
    {
        printf("Fail\n");
    }
    }
    return 0;
}

42,判断整数奇偶数

#include<stdio.h>
int main()
{
    int a;
    while(scanf("%d", &a) != EOF)
    {
        if(a % 2 == 0)
        {
            printf("Even\n");
        }
        else
        {
            printf("Odd\n");
        }
    }
    return 0;
}

三,总结

学习是一个漫长且枯燥的过程,不积跬步,无以至千里。

关注即可提高学习效率

0Warning(s),0Error(s).

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-孤单又灿烂的神-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值