|
我想让程序不断可以输入数字运行,关闭窗口才退出程序。就像前两个程序一
1.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int i,num,ans;
while (true)// 反复计算循环while (1)
{
i=1;
ans=0;
cout<<" 输入一个整数:";
cin>>num;
while (i<=num)
{
ans = ans + i;
i++;
}
cout <<"1+2+3+4.....+"<<num<<"="<<ans<<endl;
}
return 0;
}
2.
#include <iostream>
using namespace std;
int main()
{
int year;
//cin>>year; //不能加在这里会出现死循环
while (true) //反复循环计算
{
cin>>year;
if (year%4==0) //if(!(year%4))
//if(!(year%4))
{
if(!(year%100)&& year%400)
cout<<year<<" 年bu为润年"<<endl;
else
cout<<year<<" 年为闰年"<<endl;
}
else
cout<<year<<"年不为闰年"<<endl;
}
return 0;
}
3.这个应该怎么写才正确???求指教!!!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int a,b,i;
cin>>a>>b;
//while (1)//进入无限循环
for (i=a;i<=b;i++)
{
if (i%3 !=0)
continue;
cout<<i<<" ";
}
return 0;
}
|
上一篇: 最后红色所添加的代码导致蓝屏,想问一下为什么下一篇: JS初始化问题
|