栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

C语言零基础入门习题(四)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言零基础入门习题(四)

前言

        C语言是大多数小白走上程序员道路的第一步,在了解基础语法后,你就可以来尝试解决以下的题目。放心,本系列的文章都对新手非常友好。


Tips:题目是英文的,但我相信你肯定能看懂

一、Mr. Wang wants to give some apples in a box to some children, if everyone can get apple, and the number of apples for every children are different, how many apples should there be at least in this box?

Here is a sample run:

Enter the number of children: 8

The minimum number of apples: 36

#include 

int main()
{
    int a,b;
    printf("Enter the number of children: ");
    scanf("%d",&a);
    b = (1+a) * a / 2;
    printf("The minimum number of apples: %d",b);
    return 0;
}

二、Write a program that prompts the user to enter two float point data and calculate the remainder.

Here is a sample run:

Enter the formula: 73.263 % 0.9973

73.263000 % 0.9973000 = 0.460100

#include 

int main()
{
    double a,b,c;
    printf("Enter the formula: ");
    scanf("%lf %% %lf",&a,&b);
    c=a-(int)(a/b)*b;
    printf("%lf %% %lf = %lf",a,b,c);
    return 0;
}
三、Write a program to add two fractions, the user enters both fractions at the same time, separated by a plus sign:

Here is a sample run:

Enter two fractions separated by a plus sign: 5/6+3/4

The sum is 38/24

#include 

int main()
{
    int a,b,c,d;
    printf("Enter two fractions separated by a plus sign: ");
    scanf("%d/%d+%d/%d",&a,&b,&c,&d);
    printf("The sum is %d/%d",a*d+b*c,d*b);
    return 0;
}
四、IPv4 can be stored in memory, such as 192.168.1.1 needs 11 bits, but if you convert it into hexadecimal format, it will be c0a80101, need eight bits only. Please input a legal IP address (four decimal numbers less than 255 separated by period sign), and print the corresponding hexadecimal format.

Here is a sample run:

Enter your IP address: 192.168.0.1

c0a80001

#include 

int main()
{
    int a,b,c,d;
    printf("Enter your IP address: ");
    scanf("%d.%d.%d.%d",&a,&b,&c,&d);
    printf("%02x%02x%02x%02x",a,b,c,d);
    return 0;
}
五、For a positive integer n, divide n into the sum of two nonnegative integers and make the product of these two nonnegative integers as large as possible. What is the maximum product of these two nonnegative integers?

Here is a sample run:

7

12

6

9

#include 

int main()
{
    int a,b;
    scanf("%d",&a);
    if (a%2==0)
        b=a*a/4;
    else
        b=(a+1)*(a-1)/4;
    printf("%d",b);
    return 0;
}
六、Design a calculator visualizes process of multiplying in columns, you need to input an expression like 87*65, the number should be positive integer less than 100, and show the column multiplication according to the sample run.

Here is a sample run:

Enter your multiplication expression: 89*13

   89

*  13

-----

  267

  89

-----

1157

#include 

int main()
{
    int a,b,c,d;
    printf("Enter your multiplication expression: ");
    scanf("%d*%d",&a,&b);
    printf("%5dn",a);
    printf("*%4dn",b);
    printf("-----n");
    printf("%5dn",a*(b%10));
    printf("%4dn",a*(b/10));
    printf("-----n");
    printf("%5dn",a*b);
    return 0;
}


总结

以上就是本文全部内容,你学会了吗?

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/995975.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号