题目详情:编译运行多线程程序,提交编译和运行命令截图。
#include<stdio.h>
#include<pthread.h>
#define NUM 5
void *print_msg(void *);
int main()
{
pthread_t t1,t2;
pthread_create(&t1,NULL,print_msg,(void *)"hello");
pthread_create(&t2,NULL,print_msg,(void *)"world\n");
pthread_join(t1,NULL);
pthread_join(t2,NULL);
printf("t1,t2 finished\n");
return 0;
}
void *print_msg(void *m)
{
char *cp=(char *)m;
int i;
for(i=0;i<NUM;i++)
{
printf("%s",m);
fflush(stdout);
sleep(1);
}
return NULL;
}
题目详情:1-N求和
#include<stdio.h>
int fun(int i);
int main()
{
int sum=0;
int n;
printf("请输入N=");
scanf("%d",&n);
sum=fun(n);
printf("1-%d的求和为%d\n",n,sum);
}
int fun(int i)
{
if(i==1)
{ return 1;}
else
{ return i+fun(i-1);}
}
原文:https://www.cnblogs.com/fanxiaonan/p/12099105.html