循环15~17
2015-08-27 21:20
260 查看
循环15
#include<iostream>
bool just(long n);
int main()
{
using namespace std;
long a, b; int count = 0; long sum = 0;
cout << "Enter 2 integer between 1 and 500 :";
cin >> a >> b;
for (int i = a; i < b + 1; i++)
{
if (just(i))
{
count++;
sum += i;
}
}
cout << count << ' ' << sum << endl;
return 0;
}
bool just(long n)
{
if (n == 2)
return true;
else if (n % 2 == 0)
return false;
int mark = 0;
for (int i = 3; i < n / 2 + 1; i += 2)
{
if (n % i == 0)
mark = 1;
}
if (mark == 0)
return true;
else
return false;
}
循环16
#include<iostream>
int main()
{
using namespace std;
int n; int sum = 1;
cout << "Enter eat day ,between 2 to 10:"; cin >> n;
for (int i = 2; i < n + 1; i++)
{
sum = 2 * (sum + 1);
}
cout << sum << endl;
return 0;
}
循环17
#include<iostream>
int main()
{
using namespace std;
int one; char ch; int two;
cout << "Enter your quation :";
cin >> one;
while (cin >> ch &&ch!='=')
{
cin >> two;
switch (ch)
{
case'+':one = one + two; break;
case'-':one = one - two; break;
case'*':one = one*two; break;
case'/':
{if (two == 0)
break;
else
one = one / two; break; }
default:
cout << "Error .\n";
}
}
cout << one << endl;
return 0;
}
#include<iostream>
bool just(long n);
int main()
{
using namespace std;
long a, b; int count = 0; long sum = 0;
cout << "Enter 2 integer between 1 and 500 :";
cin >> a >> b;
for (int i = a; i < b + 1; i++)
{
if (just(i))
{
count++;
sum += i;
}
}
cout << count << ' ' << sum << endl;
return 0;
}
bool just(long n)
{
if (n == 2)
return true;
else if (n % 2 == 0)
return false;
int mark = 0;
for (int i = 3; i < n / 2 + 1; i += 2)
{
if (n % i == 0)
mark = 1;
}
if (mark == 0)
return true;
else
return false;
}
循环16
#include<iostream>
int main()
{
using namespace std;
int n; int sum = 1;
cout << "Enter eat day ,between 2 to 10:"; cin >> n;
for (int i = 2; i < n + 1; i++)
{
sum = 2 * (sum + 1);
}
cout << sum << endl;
return 0;
}
循环17
#include<iostream>
int main()
{
using namespace std;
int one; char ch; int two;
cout << "Enter your quation :";
cin >> one;
while (cin >> ch &&ch!='=')
{
cin >> two;
switch (ch)
{
case'+':one = one + two; break;
case'-':one = one - two; break;
case'*':one = one*two; break;
case'/':
{if (two == 0)
break;
else
one = one / two; break; }
default:
cout << "Error .\n";
}
}
cout << one << endl;
return 0;
}
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)
- 1006. 换个格式输出整数(PAT Basic)
- 1007. 素数对猜想(PAT Basic)
- 1008. 数组元素循环右移问题
- 1009. 说反话(PAT Basic)
- 1011. A+B和C(PAT Basic)