C++基础练习1

  1 /*
  2 //读入一个双精度浮点数,保留12位小数输出这个浮点数。
  3 #include<iostream>
  4 #include <iomanip>
  5 using namespace std;
  6 int main()
  7 {
  8   double a;
  9   cin >> a;
 10   cout << setprecision(12) << fixed << a << endl;
 11 }*/
 12 //给定一个字符,用它构造一个底边长5个字符,高3个字符的等腰字符三角形。
 13 /*
 14 #include <iostream>
 15 using namespace std;
 16 int main()
 17 {
 18   char a;
 19   cin >> a;
 20   cout << "  " << a << endl;
 21   cout << " " << a << a << a << endl;
 22   cout << a << a << a << a << a << endl;
 23   return 0;
 24 }*/
 25 //分别定义int,short类型的变量各一个,并依次输出它们的存储空间大小(单位:字节)
 26 /*
 27 #include <iostream>
 28 using namespace std;
 29 int main()
 30 {
 31   cout << sizeof(int) <<" "<< sizeof(short) << endl;
 32   return 0;
 33 }*/
 34 //输入一个除空格以外的可见字符(保证在函数scanf中可使用格式说明符%c读入),输出其ASCII码。
 35 /*
 36 #include <iostream>
 37 #include<cstdio>
 38 using namespace std;
 39 int main()
 40 {
 41   char a;
 42   cin >> a;
 43   int b = a;
 44   cout << b;
 45   //printf("%d", a);
 46   return 0;
 47 }*/
 48 //输入一个ASCII码,输出对应的字符。
 49 /*
 50 #include<iostream>
 51 using namespace std;
 52 int main()
 53 {
 54   short int a=0;
 55   cin >> a;
 56   cout <<(char)a<<endl;
 57   return 0;
 58 }*/
 59 //将一个整型变量的值赋给一个布尔型变量,再将这个布尔型变量的值赋给一个整型变量,得到的值是多少?
 60 /*
 61 #include <iostream>
 62 using namespace std;
 63 int main()
 64 {
 65   int x, y;
 66   bool a;
 67   cin >> x;
 68   a = x;
 69   y = a;
 70   cout << y<<endl;
 71 }*/
 72 //给定3个整数a、b、c,计算表达式(a+b)/c的值。
 73 /*
 74 #include<iostream>
 75 using namespace std;
 76 int main()
 77 {
 78   short a, b, c;
 79   cin >> a >> b >> c;
 80   cout << (a + b)/c << endl;
 81   return 0;
 82 }*/
 83 //两个整数a和b分别作为分子和分母,既分数 a/b ,求它的浮点数值(双精度浮点数,保留小数点后9位)
 84 /*
 85 #include<iostream>
 86 #include <iomanip>
 87 using namespace std;
 88 int main()
 89 {
 90   int a, b;
 91   cin >> a >> b;
 92   cout << setprecision(9) << fixed << (double)a / b << endl;
 93   return 0;
 94 }*/
 95 //甲流并不可怕,在中国,它的死亡率并不是很高。请根据截止2009年12月22日各省报告的甲流确诊数和死亡数,计算甲流在各省的死亡率。
 96 //输入仅一行,有两个整数,第一个为确诊数,第二个为死亡数。
 97 /*
 98 #include<iostream>
 99 #include <iomanip>
100 using namespace std;
101 int main()
102 {
103   int a, b;
104   cin >> a >> b;
105   cout<< setprecision(3) << fixed << ((double)b/a)*100<<"%" << endl;
106   return 0;
107 }*/
108 //给出圆的半径,求圆的直径、周长和面积。
109 /*
110 #include<iostream>
111 #include <iomanip>
112 using namespace std;
113 int main()
114 {
115   float r, pi = 3.14159;
116   cin >> r;
117   cout << setprecision(4) << fixed << 2 * r << " " << 2 * r*pi << " " << pi * r*r << endl;
118   return 0;
119 }*/
120 /*
121 #include<iostream>
122 #include<iomanip>
123 using namespace std;
124 int main()
125 {
126   double r, d, c, s, pi;
127   pi = 3.14159;
128   cin >> r;
129   cout << setiosflags(ios::fixed) << setprecision(4);
130   cout << 2 * r << " " << 2 * pi*r << " " << pi * r*r << endl;
131   return 0;
132 }*/
133 //将一个三位数反向输出
134 /*
135 #include<iostream>
136 using namespace std;
137 int main()
138 {
139   int a;
140   cin >> a;
141   int x = a % 10;
142   int y = a / 10 % 10;
143   int z = a / 100;
144   cout << x<<y<<z << endl;
145   return 0;
146 }*/
147 //你买了一箱n个苹果,很不幸的是买完时箱子里混进了一条虫子。
148 //虫子每x小时能吃掉一个苹果,假设虫子在吃完一个苹果之前不会吃另一个,
149 //那么经过y小时你还有多少个完整的苹果?
150 /*
151 #include<iostream>
152 using namespace std;
153 int main()
154 {
155   int n = 0, x = 0, y = 0;
156   cin >> n>> x>> y;
157   if (y%x == 0)
158   {
159     cout << n - y / x << endl;
160   }
161   else
162   {
163     cout << n - y / x - 1 << endl;
164   }
165   return 0;
166 }*/
167 //给出一个等差数列的前两项a1,a2,求第n项是多少
168 /*
169 #include<iostream>
170 using namespace std;
171 int main()
172 {
173   int a1=0, a2=0, n=0;
174   cin >> a1 >> a2 >> n;
175   cout << a1 + (n - 1)*(a2 - a1) << endl;
176   return 0;
177 }*/

 

posted @ 2020-11-21 18:55  丁帅帅dss  阅读(381)  评论(0)    收藏  举报