1计算零件数
#include<stdio.h>
int main()
{
int total;
for (int i = 11; i < 23; i++)
{
total = i * 9 + 5;
if (total % 4 == 2 && total % 7 == 3)
{
printf("%d\n", total);
return 0;
}
}
return 0;
}
2走台阶
#include<stdio.h>
int step(int n);
int main()
{
int a;
a = step(10);
printf("Result=%d", a);
return 0;
}
int step(int n)
{
if (n == 1)
return 1;
if (n == 2)
return 2;
else
return step(n - 1) + step(n - 2);
}
3将数据按照奇偶排序
#include<stdio.h>
int main()
{
int old[10];
int new[10];
int temp;
int count = 0;
printf("Input 10 numbers:\n");
for (int i = 0; i < 10; i++)
{
scanf("%d", &old[i]);
}
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 10-i-1; j++)
{
if (old[j] > old[j + 1])
{
temp = old[j]; old[j] = old[j + 1]; old[j + 1] = temp;
}
}
}
for (int i = 0; i < 10; i++)
{
if (old[i] % 2 != 0)
{
new[count] = old[i];
count++;
}
}
for (int i = 0; i < 10; i++)
{
if (old[i] % 2 == 0)
{
new[count] = old[i];
count++;
}
}
printf("Output: ");
for (int i = 0; i < 9; i++)
printf("%d,", new[i]);
printf("%d\n", new[9]);
return 0;
}
4三色球分组
#include<stdio.h>
int main()
{
int red = 0;
int white = 0;
int black = 0;
int count = 0;
printf("The result:\n");
for (red = 1; red < 4; red++)
for (white = 1; white < 6; white++)
for (black = 0; black < 7; black++)
if (red + white + black == 8)
{
printf("red:%4d white:%4d black:%4d\n", red, white, black);
count++;
}
printf("sum=%4d\n", count);
return 0;
}
5同构数
#include<stdio.h>
int main()
{
int i;
for (i = 1; i < 100; i++)
{
if (i < 10)
{
if (i == (i * i) % 10)
printf("m=%3d\t\tm*m=%6d\n", i, i * i);
}
else
{
if (i == (i*i)%100)
printf("m=%3d\t\tm*m=%6d\n", i, i * i);
}
}
return 0;
}
网友评论