C语言编程 求指导 1.定义两个字符数组s1、s2,并用赋初值的方法把两个字符串”Compute
发布网友
发布时间:2022-05-30 01:04
我来回答
共4个回答
热心网友
时间:2023-09-11 22:55
1.
#include <stdio.h>
#include <string.h>
#include <assert.h>
char* cat(char* des, char* src)
{
char* p;
assert(des != NULL);
assert(src != NULL);
p = des + strlen(des);
while (*p++ = *src++);
return des;
}
int main()
{
char s1[100] = "Computer";
char s2[100] = "Language";
cat(s1, s2);
printf("%s\n", s1);
return 0;
}
2.
#include <stdio.h>
#include <ctype.h>
int main()
{
char s[] = "C is a general purpose, proceral, imperative computer \
programming language developed in 1972 by Dennis Ritchie at the \
Bell Telephone Laboratories for use with the Unix operating system.";
int up, low, num, space, dot;
char* p = s;
up = low = num = space = dot = 0;
while (*p)
{
if (isupper(*p))
up++;
else if (islower(*p))
low++;
else if (isdigit(*p))
num++;
else if (' ' == *p)
space++;
else if (',' == *p)
dot++;
p++;
}
printf("大写字母: %d\n", up);
printf("小写字母: %d\n", low);
printf("数字: %d\n", num);
printf("空格: %d\n", space);
printf("逗号: %d\n", dot);
return 0;
}
3.
#include <stdio.h>
#include <assert.h>
char* copy(char* des, char* src)
{
char* p = des;
assert(des != NULL);
assert(src != NULL);
while (*p++ = *src++);
return des;
}
int main()
{
char s1[100];
char s2[] = "abcdefg";
copy(s1, s2);
printf("%s\n", s1);
return 0;
}
热心网友
时间:2023-09-11 22:55
这几个题楼主就好好自己做吧。它们可是面试常见问题之一哦!
十个公司的面试题中就有九个公司喜欢出这种题目。
热心网友
时间:2023-09-11 22:56
第一题
#include<string>
#include<iostream>
using namespace std;
int main()
{
string s1="Computer",s2="Language";
cout<<s1+s2;
}
热心网友
时间:2023-09-11 22:57
楼主工程大的吧。。。。。