2023-10-17 18:40来源:m.sf1369.com作者:宇宇
void clear()
{
HntMoveList *pTemp = first;
while (first != NULL)/猛渣樱/循环释放节点梁宴内存枝丛
{
pTemp = first;
first = first->next;
free(pTemp);
}
}
void hanoi(int n, char from, char temp, char to)
{
static int istep = 0;
if (n == 1)
{
printf(第%d步:%c->%c, from, to, istep);
istep++;
return;
}
else
{
hanoi(n-1, from, to, temp);
printf(第%d步:%c->%c, from, to, istep++);
hanoi(n-1, temp, from, to);
}
}
为什么要用链表呢
既然是链表,就弄个循环,一个节点一个节点的释放。
做一个判断语句肢滚逗
void ss()
{
if(a>0&&a<1000)
{
b=sqrt(a);
printf(sqrt=%f历卖,b);
return 1;
}
else(a<0&&a>1000)
{
printf(输入数值超出范围,请重新输入:);
scanf(%d,&a);
return 0;
}
}
void main()
{
int a=0;
float b=0;
printf(备岁请输入数值:);
scanf(%d,&a);
while(!ss());
while(1);
}
#include stdafx.h
#include <iostream>
#include <stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int n;
std::cout<吵携<升数伏please put in a data that less than 1000?<<毕链endl;
std::cin>>n;
while(n>1000)
{
cin.clear();//清除输入
cout<<please put in a data less than 1000 again ?<<endl;
std::cin>>n;
}
std::cout<<n;
system(PAUSE);//中断
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
改慧unsigned n;
scanf(%d,&n);
while(n>1000)//大于1000,就让它进入循环继续输入
{
scanf(%d族歼渣,&n);
}
printf(%.2lf\n,sqrt(n));
return 兆悄0;
}
这样此茄李,但是得纳樱自己找个条件调成循环森迟。
while(1)
{
输入n;
if(n<1000 & n>0)
n开方;
}