本文介绍了任何人都可以重写C程序而不使用do while循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
int main()
{
int number = 0;
int pid,status;
printf("Please enter a number n");
scanf("%d", &number);
if(number < 0)
{
printf("Please enter a positive number, greather than 0 n");
scanf("%d", &number);
}
pid = fork();
if(pid < 0)
{
printf(" Unsuccessful to create Child Process n");
exit(-1);
}
else if(pid == 0)
{
do
{
if(number%2 != 0)
{
number = (number*3)+1;
}
else if(number%2 == 0)
{
number = number/2;
}
printf("%d n",number);
}while(number != 1);
}
else
{
printf("pid %d n",pid);
printf("Waiting on child process to finish n");
wait(&status);
}
return 0;
}
推荐答案
这篇关于任何人都可以重写C程序而不使用do while循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!