这两道题要求是用函数!不要用指针!我们还没学指针那!劳烦大家多多指教!
1、程序包含一个主函数和一个函数fun(),函数fun()的功能是:把主函数中输入的字符串str2接在字符串str1的后面。例如,str1=“How do”,str2=“you do”,输出结果为“How do you do?”.2、请编写函数fun,其功能是:计算并输出给定数组(长度为9)中每两个相邻元素的平均值的平方根之和。
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void fun(char *src,char *dec)
{
int len = strlen(src);
char *p = dec;
int i = 0;
while(*p)
{
src[len+i] = *p++;
i++;
}
src[len+i] = '\0';
}
int main()
{
char a[100] = "sdfas";
char b[100] = "123456";
fun(a,b);
printf("%s\n",a);
return 0;
}不用指针我真的不会 如果是在主函数里面可以不用指针 但是子函数我就不会不用指针了

程序代码:#include <stdio.h>
#include <stdlib.h>
char a[100];
char b[100];
void fun(void)
{
printf("%s %s?\n", a, b);
}
int main()
{
gets(a);
gets(b);
fun();
return 0;
}
程序代码:#include <stdio.h>
#include <math.h>
int ar[9] = {878,68,78,576,97,47,876,575,7};
int fun() {
int i, sum=0;
for (i=1; i < 9; ++i) {
sum += sqrt((ar[i-1]+ar[i])/2);
}
return sum;
}
int main(void)
{
printf("%d\n", fun());
return 0;
}
程序代码:#include <stdio.h>
#define MAX 1024 //字符串最大长度
void fun( char str1[], char str2[] )
{
int i=0,j=0;
while( str1[i] != '\0' )
i++;
while( str2[j] != '\0' ){
str1[i++]=str2[j];
j++;
}
str1[i]='\0';
}
int main()
{
char str1[MAX],str2[MAX/2];
printf("Please input the 1st string:");
gets(str1);
printf("Please input the 2nd string:");
gets(str2);
fun(str1,str2);
printf( "result:%s\n",str1 );
return 0;
}