c语言题
来源:互联网 发布:手机自制铃声软件 编辑:程序博客网 时间:2024/04/28 16:06
c 语言各种补充题
1、随机生成100万个数据,数据范围[1 ,1000000],如果有重复数据,要求有提示;
// int array[1000000] = {0};
// for (int i = 0; i < 1000000; i++) {
// unsigned int random = arc4random() % 1000000;
// if (array[random] != 0) {
// printf("%d重复\n", random);
// }else {
// array[random] = random;
// printf("%d\n", random);
// }
// }
2、随机生成100个数据,数据范围[1, 100],要求不能有重复数据;
int array[100] = {0};
int count = sizeof(array) / sizeof(array[0]);
for (int i = 0; i < 100; i++) {
array[i] = i + 1;
}
for (int i = count - 1; i > 0; i--) {
unsigned int random = arc4random() % (i + 1);
int temp = array[random];
array[random] = array[i];
array[i] = temp;
}
for (int i = 0; i < count - 1; i++) {
printf("[%2d] : %d\n", i, array[i]);
}
3、随机生成一个数,这个数的范围在[10,20]或[80,90],要求用四种不同方法;
1 // int a = arc4random() % 20;
// if (a >= 0 && a <= 10) {
// printf("%d\n", a + 10);
// } else {
// printf("%d\n", a + 70);
// }
2 // int a = arc4random() % 2;
// int b = 0;
// switch (a) {
// case 0:
// b = arc4random() % (20 - 10 + 1) + 10;
// printf("%d\n", b);
// break;
// case 1:
// b = arc4random() % (90 - 80 + 1) + 80;
// printf("%d\n", b);
// break;
// }
3 // int a = arc4random() % (31 - 10 + 1) + 10;
// if (a >= 10 && a <= 20) {
// printf("%d\n", a);
// } else {
// printf("%d\n", a + 59);
// }
4 // int a = arc4random() % (20 - 10 + 1) + 10;
// switch (arc4random() % 2) {
// case 0:
// printf("%d\n", a);
// break;
// case 1:
// printf("%d\n", a + 70);
// break;
// }
4、系统随机输入一个数,要求这个数在[7,15]或[19,29]或[34,52]范围内;
// unsigned int random = arc4random() % 39;
// if (random < 9) {
// printf("%d\n", random + 7);
// } else if (random >= 9 && random < 20 ){
// printf("%d\n", random + 10);
// } else {
// printf("%d\n", random + 14);
// }
5、将字符串“a12b345c6d789e”,内的数字去掉,输出结果为“abcde”;
char a[] = "a12b345c6d78e";
int i = 0, j = 0;
while (a[i] != '\0') {
if (!(a[i] >= '\0' && a[i] <= '9') ){
a[j] = a[i];
j++;
}
i++;
}
a[j] = '\0’;
puts(a);
6、给出一个整数12345,
1)、先顺序单独的输出每一个数的值,
void printIntAsc(int n)
{
int count = countOfInt(n);
int x = 1;
for (int i = 0 ; i < count - 1; i++) {
x *= 10;
}
while (x > 0 ) {
printf("%d", n / x);
n %= x;
x /= 10;
}
}
2)、再逆序的输出每一个数的值
void printIntDesc(int n)
{
while (n > 0) {
printf("%d", n % 10);
n /= 10;
}
}
3)、写一个函数,,传进去 12345 返回出来54321
int reverseInt(int n)
{
int newnumber = 0 ;
while (n > 0 ) {
newnumber = newnumber * 10 + n % 10;
n /= 10;
}
return newnumber;
}
- 一道C语言题
- C语言测试题
- C语言笔试题
- C语言笔试题
- C语言笔试题
- c语言笔试题
- C语言一题
- c语言笔试题
- C语言测试题
- C语言迷题
- c语言谜题
- C语言谜题
- C语言迷题
- C语言IQ题
- C 语言谜题
- C语言题
- C语言谜题
- C语言题
- [Linux学习笔记]常用命令学习-01
- API自己练习
- Best Time to Buy and Sell Stock
- 很简单的事看得非常复杂
- 基于 HTTP 长连接的“服务器推”技术-Comet
- c语言题
- Spark入门到精通视频学习资料--第二章:Spark生态系统介绍,Spark整体概述与Spark编程模型(2讲)
- 用diff比较目录文件差异和patch备份源代码
- 案例:需求问题的解决方案
- hdu 4911 归并 求逆序对对数(Java实现)
- GCC4.7编译记录
- Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL
- linux学习笔记03-linux文件权限与目录配置
- 斯坦福Swift公开课上线 国内开发者已着手翻译