小写英文字符变大写字符
#include <iostream>
using namespace std;
int main()
{
char c_lower;
cin>>c_lower;
///////////begin////////
char c_upper;
if (c_lower <= 'z' && c_lower >= 'a')
{
c_upper = c_lower + 'A' - 'a';
}
else
{
c_upper = c_lower;
}
///////////end//////////
cout<<c_upper;
return 0;
}
阶乘求和
#include <iostream>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
long int sum;
//////////begin//////////
if (m >= n)
{
cout << "输入错误";
return 0;
}
int tmp = 1;
sum = 0;
for (int i = 1; i <= m; i ++)
{
tmp *= i;
}
for (int i = m + 1; i <= n + 1; i ++)
{
sum += tmp;
tmp *= i;
}
/////////end///////////
cout<<sum;
return 0;
}
两个数的最大公约数
#include <iostream>
using namespace std;
int main()
{
int n1, n2;
cin >> n1 >> n2;
//////////begin///////////
if (n1 < n2)
{
int a = n1;
n1 = n2;
n2 = a;
}
while (n1 % n2 != 0)
{
n1 = n1 % n2;
int c = n1;
n1 = n2;
n2 = c;
}
int c = n1;
n1 = n2;
n2 = c;
//////////end///////////
cout << n1;
return 0;
}
找“完数”的个数
#include <iostream>
using namespace std;
//////////begin//////////
int getNumber(int);
/////////end///////////
int main()
{
int n;
cin >> n;
cout<<getNumber(n);
return 0;
}
//////////begin//////////
int getNumber(int n)
{
int cnt = 0;
for (int i = 2; i <= n; i ++)
{
int tot = 0;
for (int j = 1; j <= i / 2; j ++)
{
if (i % j == 0)
{
tot += j;
}
}
if (tot == i)
{
cnt ++;
}
}
return cnt;
}
/////////end///////////