1.写了个1--100的,你自己写一个输入一个数的试试!!!
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,n;
cout<<"1~100间的质数有:"<<endl;
for(n=2;n<=100;n++)
{
for(i=2;i<=sqrt(n);i++)
if(n%i==0)
break;
if(i>sqrt(n))
cout<<n<<" ";
}
cout<<endl;
system("pause");
return 0;
}
2.写了个判断两个条件的,你来写两个条件的
#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"please input x : ";
cin>>x;
if(x < 1)
y = -x;
else if(x > 1)
y = x;
cout<<"y = "<<y<<endl;
system("pause");
return 0;
}
3.运用if()语句来写,将输入的三个数,两两比较
4.用if()与switch()
希望对你有帮助
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,n;
cout<<"1~100间的质数有:"<<endl;
for(n=2;n<=100;n++)
{
for(i=2;i<=sqrt(n);i++)
if(n%i==0)
break;
if(i>sqrt(n))
cout<<n<<" ";
}
cout<<endl;
system("pause");
return 0;
}
2.写了个判断两个条件的,你来写两个条件的
#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"please input x : ";
cin>>x;
if(x < 1)
y = -x;
else if(x > 1)
y = x;
cout<<"y = "<<y<<endl;
system("pause");
return 0;
}
3.运用if()语句来写,将输入的三个数,两两比较
4.用if()与switch()
希望对你有帮助