今天练习了n项求和,统计素数求和,99乘法表
#include<stdio.h>
int main()
{
double fz = 2;
double fm = 1;
int N;
double sum = 0;
scanf_s("%d", &N);
for (int i = 1; i <= N; i++)
{
sum = sum + fz / fm;
double temp = fz;
fz = fz + fm;
fm = temp;
}
printf("%.2lf", sum);
return 0;
}
#include<stdio.h>
int main()
{
int M;
scanf_s("%d", &M);
int N;
scanf_s("%d", &N);
int a = 0;
int sum = 0;
for (int i = N; i <= M; i++)
{
int count = 0;
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
count++;
break;
}
/*if(count == 0)
{
printf("%d\n", i);
break;
}
这个判断不能放在里面,比如i=13,j=2
i%j!=0,此时会直接运行到第二个if,因为count==0
实际上奇数一开始和2相除,他们的余数都不为0,所以count不会++,
导致count==0,此时会直接运行到第二个if,并break,
所以运行程序时什么都没有
*/
}
if (count == 0)
{
printf("%d\n", i);
a++;
sum += i;
}
}
#include<stdio.h>
int main()
{
for (int i = 1; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d*%d=%d\t", i, j, i * j);
}
printf("\n");
}
return 0;
}
标签:8.2,语言,int,double,scanf,include,main,sum
From: https://blog.csdn.net/fhgfyrsg/article/details/140878176