1.1
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
long fin = 1;
scanf("%d", &a);
for (int i = 0; i < a; i++)
{
fin = fin * (i + 1);
}
printf("%ld\n", fin);
system("pause");
return 0;
}
1.2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num, status, m, n = 1;
long fin = 0;
char ch;
do
{
scanf("%d", &m);
getchar();
for (int j = 1; j <= m; j++)
{
for (int i = 1; i <= j; i++)
{
n = n * i;
}
fin = fin + n;
n = 1;
}
printf("%ld\n", fin);
fin = 0;
n = 1;
} while ((ch = getchar()) != EOF);
system("pause");
return 0;
}
1.3
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j;
double e = 1, prs, num = 1;
for (i = 1; i < 1E3; i++)
{
for (j = 1; j <= i; j++)
{
prs = 1.0 / j;
num = num * prs;
prs = 1;
}
e = e + num;
num = 1;
}
printf("%f", e);
system("pause");
return 0;
}
1.4
#include <stdio.h>
#include <stdlib.h>
int main()
{
int j, k;
double e = 1, prs = 1, x, y;
scanf("%lf", &x);
for (j = 1; j <= 1e3; j++)
{
for (k = 1; k <= j; k++)
{
y = x / k;
prs *= y;
}
e += prs;
prs = 1;
}
printf("%f", e);
system("pause");
return 0;
}
2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int sign = -1, num = -1;
float pai1 = 0, pai2 = 1;
for (int i = 1; i <= 1e3; i++)
{
for (int j = 1; j <= i; j++)
{
sign *= num;
}
pai1 += (float)sign / (2 * i - 1);
sign = -1;
}
for (int i = 1; i <= 1e3; i++)
{
pai2 *= 4.0 * i * i / (2.0 * i - 1) / (2.0 * i + 1);
}
printf("No.1---%f\nNo.2---%f\n", 4 * pai1, 2 * pai2);
system("pause");
return 0;
}
3
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m, n, p, a = 1;
scanf("%d %d", &m, &n);
for (int i = 1; i <= (m < n ? m : n); i++)
{
if ((m % i) == 0 && (n % i) == 0)
{
a = i;
}
}
while (n != 0)
{
if (m > n)
{
p = n;
n = m % n;
m = p;
}
else if (n > m)
{
n = n % m;
}
}
printf("最大公约数为:\n%d %d", p, m);
system("pause");
return 0;
}
4
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 0, b = 1, c;
for (int i = 1; i <= 20; i++)
{
c = a + b;
a = b;
b = c;
printf("%d", c);
if (i % 8 == 0)
printf("\n");
else
printf("\t");
}
system("pause");
return 0;
}
5
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 1, b = 1, c;
float fin = 0;
for (int i = 1; i <= 20; i++)
{
c = a + b;
a = b;
fin += (float)c / b;
b = c;
}
printf("%f", fin);
system("pause");
return 0;
}
6
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, m, count1, count2 = 0;
scanf("%d %d", &n, &m);
for (int i = n; i <= m; i++)
{
count1 = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0)
count1++;
}
if (count1 == 2)
{
count2++;
}
}
printf("%d~%d之间,素数的个数为:%d", n, m, count2);
system("pause");
return 0;
}
7
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m, count = 0;
scanf("%d", &m);
for (int i = 1; i <= m; i++)
{
if (m % i == 0)
count++;
}
if (count != 2)
{
printf("%d=", m);
for (int i = 2; i <= m; i++)
{
if (m % i == 0)
{
printf("%d", i);
if (m / i != 1)
printf("*");
m /= i;
i = i - 1;
}
}
}
else
{
printf("它是一个素数!\n");
}
system("pause");
return 0;
}
8
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num = 1;
for (int i = 1; i < 10; i++)
{
num = (num + 1) * 2;
}
printf("摘了%d个桃", num);
system("pause");
return 0;
}
9
#include <stdio.h>
#include <stdlib.h>
int main()
{
int count;
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= 4; j++)
{
for (int k = 1; k <= 4; k++)
{
if (i != j && j != k && i != k)
{
printf("%d%d%d\t", i, j, k);
count++;
if (count == 12)
{
printf("\n");
}
}
}
}
}
printf("\n能组成%d个互不相同且无重复数字的三位数。\n", count);
system("pause");
return 0;
}
10
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num, x, y = 0;
scanf("%d", &num);
for (int i = 1; i <= 4; i++)
{
x = num;
for (int j = 4; j > i; j--)
{
x = x / 10;
}
x %= 10;
y += x;
printf("%d", x);
if (i != 4)
printf("+");
}
printf("=%d\n", y);
system("pause");
return 0;
}
11
#include <stdio.h>
#include <stdlib.h>
int main()
{
for (int i = 0; i < 10; i++)
{
///1
for (int j = 0; j <= i; j++)
{
printf("*");
}
for (int j = 9; j > i; j--)
{
printf(" ");
}
printf("\t");
//2
for (int j = 10; j > i; j--)
{
printf("*");
}
for (int j = 0; j < i; j++)
{
printf(" ");
}
printf("\t");
//3
for (int j = 0; j < i; j++)
{
printf(" ");
}
for (int j = 10; j > i; j--)
{
printf("*");
}
printf("\t");
//4
for (int j = 9; j > i; j--)
{
printf(" ");
}
for (int j = 0; j <= i; j++)
{
printf("*");
}
printf("\n");
}
system("pause");
return 0;
}
12
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a, b, count = 0;
srand((unsigned)time(NULL));
a = rand() % 10 + 1;
printf("——————猜数游戏——————\n———输入一个数字(1~10)———\n");
for (int i = 0; i < 6; i++)
{
scanf("%d", &b);
if (a == b)
{
printf("——————猜数正确——————\n");
count++;
break;
}
else if (a > b)
{
printf("——————猜数偏小——————\n你还有%d次机会\n", 5 - i);
}
else
{
printf("——————猜数偏大——————\n你还有%d次机会\n", 5 - i);
}
}
if (count != 1)
printf("——————你输了!——————\n");
else
printf("——————你赢了!——————\n");
system("pause");
return 0;
}
14
#include <stdio.h>
#include <stdlib.h>
int main()
{
double num = 0.5 / 1.42e8, fin = 0;
for (int i = 1; i <= 64; i++)
{
num *= 2;
fin += num;
}
printf("%f", fin);
system("pause");
return 0;
}
15
#include <stdio.h>
#include <stdlib.h>
int main()
{
double num = 24;
for (int i = 1626; i < 2010; i++)
{
num *= 1.08;
}
printf("%f", num);
system("pause");
return 0;
}