循环15~17
来源:互联网 发布:淘宝店铺如何快速升钻 编辑:程序博客网 时间:2024/06/05 23:55
循环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;
}
- 循环15~17
- 循环17~21
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 5 Longest Palindromic Substring
- Junit(5)趁热打铁
- CircuitBreakingException[[FIELDDATA] Data too large, data for [proccessDate] would be larger than li
- LeetCode144-Binary-Tree-Preorder-Traversal
- c#—细说多线程(3)
- 循环15~17
- 页面跳转 和虚拟键盘的自动隐藏
- LeetCode145-Binary-Tree-Postorder-Traversal
- BZOJ2734: [HNOI2012]集合选数|状压DP
- UVa 455 Periodic Strings
- LeetCode102-Binary-Tree-Level-Order-Traversal
- selenuim-webdriver注解之@FindBy、@FindBys、@FindAll的区别
- 剑指Offer-二维数组中的查找
- UVa 227 Puzzle