#include
#include
inline int cmpNum(const void *a, const void *b)
{
return *(int*)a-*(int*)b;
}
void print_info(int iArray[], int iNum)
{
int i = 0;
for (i = 0; i < iNum; i++)
{
printf("%d ", iArray[i]);
}
printf("\n\n");
}
void primeNumber(int iArray[],int iNum)
{
printf("素数:");
int i = 0;
for (i = 0; i < iNum; i++)
{
int j = 2;
int iFlag = 0;
for (j = 2; j < iArray[i]-1; j ++)
{
if (iArray[i] % j == 0)
{
iFlag +=1;
continue;
}
}
if (iFlag <= 0)
printf("%d ", iArray[i]);
}
printf("\n");
}
void Narcissus(int iArray[],int iNum)
{
int i = 0;
printf("水仙花数:");
for (i = 0; i < iNum; i++)
{
int iTmp = iArray[i];
int iMode = 0;
int iSum = 0;
while(1)
{
iMode = iTmp % 10;
iSum += iMode*iMode*iMode;
if (iTmp < 10)
break;
iTmp /= 10;
}
if (iSum == iArray[i])
printf("%d ", iArray[i]);
}
printf("\n\n");
}
void triangle(int iArray[],int iNum)
{
int i,j,k;
for (i = 0; i < iNum - 2; i++)
{
int a = iArray[i]*iArray[i];
for (j = 1; j < iNum-1; j++)
{
int b = iArray[j]*iArray[j];
for (k = 2; k < iNum; k++)
{
int c = iArray[k]*iArray[k];
if (a+b==c || a+c==b || b+c == a)
{
printf("%d %d %d\n", iArray[i], iArray[j], iArray[k]);
}
}
}
}
printf("\n\n");
}
int main()
{
int iArray[] = {5,12,153,407,123,79,13,23,99,20};
int iNum = sizeof(iArray) / sizeof(iArray[0]);
/* 排序 */
qsort(iArray, iNum, sizeof(iArray[0]), cmpNum);
print_info(iArray, iNum);
/* 素数 */
primeNumber(iArray, iNum);
/* 水仙花数 */
Narcissus(iArray, iNum);
/* 勾股数 */
triangle(iArray, iNum);
return 0;
}
#include
int paixu(int a[],int i);
int sushu(int i);
int shuixianhuashu(int i);
int gougushu(int a[],int i);
int main()
{
int i = 0;
char c = 0;
int a[10] = {0};
for(i = 0;i < 10;i ++)
scanf("%d",a+i);
while(1)
{
scanf("%c",&c);
if(c == 'q')
break;
switch(c)
{
case '1':
paixu(a,10);
break;
case '2':
for(i = 0;i < 10;i ++)
if(sushu(a[i]))
printf("%d\t",a[i]);
break;
case '3':
for(i = 0;i < 10;i ++)
if(shuixianhuashu(a[i]))
printf("%d\t",a[i]);
break;
case '4':
gougushu(a,10);
break;
default:
printf("输入错误");
}
}
}
int paixu(int a[],int i)
{
int m,n;
for(m = 0;m < i-1; m ++)
for(n = m+1;n < i; n++)
if(a[m] < a[n])
a[m] = a[m] + a[n] - (a[n] = a[m]);
for(m = 0; m < i;m ++)
prinft("%d\t",a[m]);
return 0;
}
int sushu(int i)
{
int m = 2;
for(;m < i/2;m ++)
{
if(i%m == 0)
return 0;
}
return 1;
}
int shuixianhuashu(int i)
{
int m[14];
int n = 0,j = i;
do{
m[n++] = j%10;
}while(j/=10);
for(j = 0;j < n;j ++)
{
i-= m[j]* m[j] * m[j];
}
if(i)
return 0;
return 1;
}
int gougushu(int a[],int i)
{
int m,n,j;
for(m = 0;m for(n = m+1;n for(j = m+1;j if(a[m]*a[m] + a[n]*a[n] == a[j] * a[j] ||
a[m]*a[m] + a[j]*a[j] == a[n] * a[n] ||
a[j]*a[j] + a[n]*a[n] == a[m] * a[m])
printf("%ld\t%ld\t%ld\n",a[m],a[n],a[j]);
return 0;
}