int main()
{
int i = 0;
int count = 0;
for (i = 1;i <= 100;i++)
{
if (i % 10 == 9)
count++;
if (i / 10 == 9)
count++;
}
printf("%d", count);
return 0;
}
2.计算1/1-1/2+1/3-1/4+....+1/99-1/100的值,打印出结果
int main()
{
int i = 0;
double sum = 0.0;
int flag = 1;
for (i = 1;i <= 100;i++)
{
sum = sum + flag * (1.0 / i);
flag = -flag;
}
printf("%lf", sum);
return 0;
}
3.求10个整数中的最大值
int main()
{
int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
int max = arr[0];
int i = 0;
for (i = 1;i <= 10;i++)
{
if (arr[i] > max)
max = arr[i];
}
printf("%d", max);
return 0;
4.打印9*9乘法口诀表
int main()
{
int i = 0;
for (i = 1;i <= 9;i++)
{
int j = 0;
for (j = 1;j <= i;j++)
printf("%d*%d=%-2d ", i, j, i * j);
printf("\n");
}
return 0;
}
1.数一下1到100的所有整数中出现了多少个数字9int main(){ int i = 0; int count = 0; for (i = 1;i <= 100;i++) { if (i % 10 == 9) count++; if (i / 10 == 9) count++; } printf("%d", count); return 0;}2.计算1/1-1/2+1/3-1/4+....+1/99-1/100的值,打印出结果int main