2个题目。来做做看…
1,有十把椅子。给三个人坐。每个人都必须隔开至少一个位置。有几种可能? 2,把一个圆十等分…就是在圆上会有相邻的点之间等距离的十个点…这十个点选其中三个组成一个三角形…问顿角三角形。锐角三角形。直角三角形…各多少个。
程序代码:#include <stdio.h>
void main()
{
int i,j,k,n=0,l=0,m=0;//直角.
for(i=1;i<=10;i++)
for(j=2;j<5;j++)
n++;
for(i=1;i<=10;i++)//锐角.
for(j=2;j<6;j++)
for(k=3;k<5;k++)
l++;
for(i=0;i<=10;i++)//钝角.
for(j=4;j<=5;j++)
for(k=5;k<=6;k++)
{
if(j==k) continue;
m++;
}
printf("直角个数=%d\n锐角个数=%d\n钝角个数=%d",n,l,m);
}
程序代码:#include <stdio.h>
#define SIZE 10
void show(int array[])
{
int count = 0;
static counter = 1;
printf("%d\t", counter++);
while ( count < SIZE )
{
if ( array[count] == 0 )
{//表示椅子
printf(" 椅");
}
else if ( array[count] == 1 )
{//表示此地 由甲坐
printf(" 甲");
}
else if ( array[count] == 2 )
{//表示此地 由乙坐
printf(" 乙");
}
else
{//表示此地 由丙坐
printf(" 丙");
}
++count;
}
printf("\n");
}
void array_cpy(int dist[], int sour[], int length)
{
while ( length-- )
{
dist[length] = sour[length];
}
}
void insert(int array[], int length, int position)
{//数组的长度 插入的位置
int i;
int p_position;
int temp[SIZE] = {0};
array_cpy( temp, array, SIZE );
for ( i = length; i>position; --i )
{
temp[i] = temp[i-1];
}
length = length + 1;
temp[position] = 0;
if ( length != SIZE )
{
for (p_position=0; p_position<length; ++p_position)
{
if ( temp[p_position] !=0 && p_position >= position-1 )
{
insert( temp, length, p_position+1);
}
}
}
else
{
show( temp );
}
}
void deal()
{
int array[SIZE] = {1, 0, 2, 0, 3, 0, 0, 0, 0, 0};
int length = 6; //表示初始的椅子数
int position;
for (position=0; position<length; ++position)
{
if ( array[position] != 0 )
{
insert( array, length, position+1 );
}
}
}
int main(void)
{
deal();
return 0;
}