いくつかの中学校の数学の問題

4076 ワード

/*
    100       ,
              
      ,      
       
*/

void test_37()
{
	double hight = 100;
	double lenth = 100;
	for (int i = 1; i <= 10; ++i)
	{
		hight = hight / 2;//           
		lenth += hight * 2;
	}
	printf("        %f ,
%f
", lenth, hight); }
/*
 100~999               :
         ,          
*/
void num_trans_char(int num,char *ch)
{
	for (int i = 0; num != 0; ++i)
	{
		ch[i] = num % 10;
		num = num / 10;
	}
}
void test_41()
{
	//10^2  ~  31^2
	char ch[3] = { 0 };//  100~999     
	int num = 0;
	for (int i = 10; i < 32; ++i)
	{
		num = i*i;
		num_trans_char(num, ch);
		if (ch[0] == ch[1] || ch[0] == ch[2] || ch[1] == ch[2])//         
			printf("%d
", num); } }
/*
        ,           
                 
  225625=475^2,             
*/
void num_trans_char(int num, int *ch)
{
	int j = 5;
	for (int i = 0; num != 0; ++i,--j)
	{
		ch[j] = num % 10;
		num = num / 10;
	}
}
int ch_trans_num(int ch[])
{
	int num = 0;
	int len = sizeof(ch)/sizeof(ch[0]);
	for (int i = len - 1,j=0; i >= 0; --i,++j)
	{
		num += ch[i] * pow((double)10, j);
	}
	return num;
}
void test_42()
{//317^2      ~   1000^2
	// 10^2   ~  32~2
	int ch[6] = { 0 };
	int low = (int)sqrt((double)100000);
	int high = (int)sqrt((double)999999);
	int num = 0;
	int tmp1[3] = { 0 }, tmp2[3] = { 0 };
	
	
	for (++low; low < high; ++low)
	{
		bool flag = true;
		double num1 = 0, num2 = 0;
		num = (int)pow((double)low, 2);//       		
		num_trans_char(num, ch);//     
		int j = 0;
		for (int i = 0; i < 3; ++i,++j)
		{
			tmp1[i] = ch[j];
		}//        
		{
			for (int i = 2, j = 0; i >= 0; --i, ++j)
			{
				num1 += tmp1[i] * pow((double)10, j);
			}
		}//     
		num1 = sqrt((double)num1);
		for (int i = 1; i < 32; ++i)//            
		{
			if (num1 != i)
				flag = false;
			else
			{
				flag = true;
				break;
			}
				
		}
		if (flag == false)
			continue;
		for (int i = 0; i < 3; ++i, ++j)
		{
			tmp2[i] = ch[j];
		}//        
		{
			for (int i = 2, j = 0; i >= 0; --i, ++j)
			{
				num2 += tmp2[i] * pow((double)10, j);
			}
		}//     
		num2 = sqrt((double)num2);
		for (int i = 1; i < 32; ++i)//            
		{
			if (num2 != i)
				flag = false;
			else
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			printf("%d
", num); } } }

もっと簡単な方法がある
void test_true_42()
{
	long i, n, n1, n2, n3, n4;
	for (i = 100000; i <= 999999; ++i)
	{
		n = (long)sqrt((double)i);
		if (i == n*n)//           
		{
			n1 = i / 1000;//   
			n2 = i % 1000;//   
			n3 = (long)sqrt((double)n1);
			n4 = (long)sqrt((double)n2);
			if (n1 == n3*n3&&n2 == n4*n4)
			{
				printf("%d
", i); } } } }
/*
     
                          
             26     880
         
*/
void test_43()
{
	int candy[20] = { 0 };
	int first = 0, count = 0;
	int n1, n2, n3, n4;
	for (int i = 0; i < 26; ++i)//    
	{
		for (int j = 1; j < 20; ++j)
		{
			n1 = i;
			n2 = n1 + j;
			n3 = n2 + j;
			n4 = n3 + j;
			if (((n1 + n2 + n3 + n4) == 26) && (n1*n2*n3*n4) == 880)
			{
				first = i;
				count = j;
			}
		}
		
	}
	for (int i = 0; i < 20; ++i)
	{
		printf("%d\t", first + (count*i));
	}
}
/*
                     
  25^2=625
 10000        
*/
void num_trans_ch(int num, int *ch)
{
	for (int i = 0; num != 0; ++i)
	{
		ch[i] = num % 10;
		num = num / 10;
	}
}
void test_45()
{
	int ch[10] = { 0 };
	for (int x = 0; x < 1000; ++x)
	{	
		int num = x*x;	
		num_trans_ch(num, ch); 
		int wei=0;
		if (x / 100 != 0)//3  
		{
			for (int i = 0; i < 3; ++i)//   
			{
				wei += ch[i] * pow((double)10, i);
			}
		}
		else if (x / 10 != 0)//2
		{
			for (int i = 0; i < 2; ++i)
			{
				wei += ch[i] * pow((double)10, i);
			}
		}
		else if (x / 1 != 0)//1
		{
			for (int i = 0; i < 1; ++i)
			{
				wei += ch[i] * pow((double)10, i);
			}
		}
		if (wei == x)
			printf("%d*%d=%d
", x, x, num); } }