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

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

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

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

前言

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


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

一、display your name and your country/province:

Output:

Name:           Mike Chen

Country:        USA

#include 

int main()
{
    printf("Name:ttMegreznCountry:	ChinanProvince:tShanghai");
    return 0;
}

 

二、 add two numbers and display its sum

Output:

The sum of 5.6 and 7.8 is 13.4

#include 

int main()
{
    float a, b, sum;
    a=5.6F, b=7.8F, sum=a+b;
    printf("The sum of %.1f and %.1f is %.1fn",a,b,sum);
    return 0;
}
 三、show the messages below

Output:

------------------------------------

Province      Area(km2)   Pop.(10K)

------------------------------------

Anhui         139600.00   6461.00

Beijing        16410.54   1180.70

Chongqing      82400.00   3144.23

Shanghai        6340.50   1360.26

Zhejiang      101800.00   4894.00

------------------------------------

#include 
#include 

int main()
{
    printf("------------------------------------n");
    printf("Province      Area(km2)   Pop.(10K)n");
    printf("------------------------------------n");
    printf("Anhui         139600.00   6461.00n");
    printf("Beijing        16410.54   1180.70n");
    printf("Chongqing      82400.00   3144.23n");
    printf("Shanghai        6340.50   1360.26n");
    printf("Zhejiang      101800.00   4894.00n");
    printf("------------------------------------n");
    return 0;
}
 四、calculate area of a circle having its radius (r = 5)

Output:

The area of circle(radius=5) is **.**

#include 

int main()
{
    float radius, circumference;
    radius=5.0;
    circumference=2*3.141592*radius;
    printf("The area of circle(radius=5) is %f",circumference);
    return 0;
}
五、swaps two numbers

Output:

Input value for x & y: 5 7

Before swapping the value of x & y: 5 7

After swapping the value of x & y: 7 5

( you’d better not use the third variable) .

#include 

int main()
{
    int x,y;
    printf("Input value for x & y: ");
    scanf("%d%d",&x,&y);
printf("Before swapping the value of x & y:%d %dn",x,y);
x=x+y
y=x-y
x=x-y
    printf("After swapping the value of x & y:%d %dn",x,y);
    return 0;
}
六、reverse and print a given integer number whose absolute value greater than 99 and less than 1000.

Output1:

Input a number: 123

The reverse of the said number:321

Output2:

Input a number: -210

The reverse of the said number:-12

#include 

int main()
{
    int m,x,y,z;
    scanf("%d",&m);
    x=m/100%10;
    y=m/10%10;
    z=m%10;
            printf("%dn",z*100+y*10+x);
    return 0;
}

 


总结

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

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

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

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