//1、随机产生20个[10 , 50]的正整数存到数组中,并求数组中的所有元素最大值、最小值、平均值以及各元素之和,及第二大值。
/*
int a[20] = {0};
for (int i = 0; i < 20; i ++) {
a[i] = arc4random() % 41 + 10;
printf("%d ", a[i]);
}
int max = 0, min = a[0], secondMax = 0, sum = 0;
float avg = 0.0;
for (int i = 0; i < 20; i ++) {
max = max > a[i] ? max : a[i];
}
for (int i = 0; i < 20; i ++) {
if (a[i] < max && a[i] > secondMax) {
secondMax = a[i];
}
min = min < a[i] ? min : a[i];
sum += a[i];
}
avg = sum / 20.0;
printf("\nmax = %d min = %d avg = %f sum = %d secondMax = %d", max, min, avg, sum, secondMax);
*/
// 2.编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词。
/*
char a[] = "asdgf gs ysgfyg aygrfjksdf jfg sygfwygrf";
int i = 0, maxlength = 0, length = 0, lengthInde = 0;
while (a[i] != '\0') {
if (a[i] != ' ') {
length ++;
} else if(length > maxlength){
maxlength = length;
lengthInde = i - maxlength;
length = 0;
}
if(length > maxlength && a[i] == ' '){
maxlength = length;
lengthInde = i - maxlength;
}
i ++;
}
printf("%d", maxlength);
printf("\n%d", lengthInde);
printf("\n");
i = 0;
// while (a[i] !='\0') {
// if (i >= lengthInde && i < maxlength + lengthInde) {
// printf("%c", a[i]);
// }
// i ++;
for (i = lengthInde; i < lengthInde + maxlength; i ++) {
printf("%c", a[i]);
}
*/
//3、耶稣有13个门徒,其中有一个就是出卖耶稣的叛徒,请用排除法找出这位叛徒:13人围坐一圈,从第一个开始报号:1,2,3,1,2,3...。凡是报到“3”就退出圈子,最后留在圈子内的人就是出卖耶稣的叛徒。请找出它原来的序号。
/*
int a[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int num = 13, i = 0, count = 0;
while (num > 1) {
if (a[i] > 0) {
count ++;
if (count == 3) {
a[i] = 0;
count = 0;
num --;
}
}
i ++;
if (i > 12) {
i = 0;
}
}
for (int i = 0; i < 13; i ++) {
if (a[i] != 0) {
printf("%d", a[i]);
}
}
*/
//4.将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
/*
int a[10] = {0}, b[12] = {0}, c[22] = {0};
for (int i = 0; i < 10; i ++) {
a[i] = arc4random() % 21 + 10;
printf("%d ", a[i]);
}
printf("\n");
for (int i = 0; i < 12; i ++) {
b[i] = arc4random() % 21 + 10;
printf("%d ", b[i]);
}
printf("\n");
for (int i = 0; i < 9; i ++) {
for (int j = 0; j < 9 - i; j ++) {
if (a[j] > a[j + 1]) {
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (int i = 0; i < 10; i ++) {
printf("%d ", a[i]);
}
printf("\n");
for (int i = 0; i < 11; i ++) {
for (int j = 0; j < 11 - i; j ++) {
if (b[j] > b[j + 1]) {
int temp = b[j];
b[j] = b[j + 1];
b[j + 1] = temp;
}
}
}
for (int i = 0; i < 12; i ++) {
printf("%d ", b[i]);
}
printf("\n");
int k = 0, i = 0, j = 0;
while (i < 10 && j < 12) {
if (a[i] > b[j]) {
c[k] = b[j];
k ++;
j ++;
} else {
c[k] = a[i];
k ++;
i ++;
}
}
while (i < 10) {
c[k] = a[i];
k ++;
i ++;
}
while (j < 12) {
c[k] = b[j];
k ++;
j ++;
}
for (int m = 0; m < 22; m ++) {
printf("%d ", c[m]);
}
*/
//5.有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
/*
float a = 2, b = 1,fra = 0, sum = 0;
for (int i = 0; i < 20; i ++) {
fra = a / b;
int temp = a;
a = a + b;
b = temp;
sum += fra;
}
printf("%f", sum);
*/
//6,给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
/*
printf("请输入一个不多余5位正整数:");
int a = 0, i = 0;
scanf("%d", &a);
int b = a;
while (b) {
i ++;
b = b / 10;
}
printf("%d", i);
printf("\n");
for (int j = 0; j < i; j ++) {
printf("%d", a % 10);
a = a / 10;
}
*/
//7.,一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
/*
printf("输入一个5位数:");
int a = 0;
scanf("%d", &a);
if (a % 10 == a / 10000 && ((a / 10) % 10) == ((a / 1000) % 10))
{
printf("a是回文数");
} else {
printf("a不是回文数");
}
*/