作者:手机用户2602933971 | 来源:互联网 | 2023-10-17 10:58
2018.3.17
1. 一个数组中只有两个数字是出现一次,其他所有数字都出现了两次。 找出这两个数字,编程实现。
int main()
{int result[10] &#61; {0};int a[18] &#61; {0};int n;int i;int max &#61; 0;printf("Please input a number for counting: ");scanf("%d", &n);printf("Please input some numbers: ");for(i &#61; 0; i"%d", &a[i]);if(a[i]>max) max &#61; a[i];}while(n--){for(i &#61;0; i<&#61;max; i&#43;&#43;){if(a[n] &#61;&#61; i){result[i]&#43;&#43;;break;}}}for(i &#61; 0; i<&#61;max; i&#43;&#43;){ if(result[i] &#61;&#61; 1){printf("%d ", i);}}return 0;
}
2. 喝汽水&#xff0c;1瓶汽水1元&#xff0c;2个空瓶可以换一瓶汽水&#xff0c;给20元&#xff0c;可以喝多少汽水。编程实现。
#include
int main()
{int money &#61; 0;int count &#61; 0;scanf("%d", &money);count &#43;&#61; money;while(money /&#61; 2){count &#43;&#61; money; }printf("%d\n", count);return 0;
}
3. 模拟实现strcpy
#include
#include
#include
char *my_strcpy(char *des, const char *source)
{char *p &#61; des;const char *q &#61; source;assert(des);assert(source);while(*p&#43;&#43; &#61; *q&#43;&#43;){;}return p;
}int main(){char a[10] &#61; "abcdefg";char b[10];memset(b, 0, 10);my_strcpy(b, a);printf("%s\n", b);return 0;
}
4. 模拟实现strcat
#include
#include
char *my_strcat(char *des, const char *source)
{char *de &#61; des;const char *sou &#61; source;assert(des);assert(source);while(*de) de&#43;&#43;;while(*de&#43;&#43; &#61; *sou&#43;&#43;){;}
}int main()
{ char a[15] &#61; "Oh, my ";char *b &#61; "god!";my_strcat(a, b);printf("%s\n", a);return 0;
}