前言
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;
}
Output:
Name: Mike Chen
Country: USA
二、 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;
}
Output:
The sum of 5.6 and 7.8 is 13.4
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
------------------------------------
Output:
The area of circle(radius=5) is **.**
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) .
Output1:
Input a number: 123
The reverse of the said number:321
Output2:
Input a number: -210
The reverse of the said number:-12
总结
以上就是本文全部内容,你学会了吗?



