最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

097.四方定理

IT圈 admin 1浏览 0评论

097.四方定理

#include<stdio.h>
void verify_four_squares(int number)
{int i,j,k,l;for(i=1;i<number/2;i++)         /*试探法。试探i,j,k,k的不同值*/for(j=0;j<=i;j++)for(k=0;k<=j;k++)for(l=0;l<=k;l++)if(number==i*i+j*j+k*k+l*l)    /*若满足定理要求则输出结果*/{printf(" >> %d=%d*%d+%d*%d+%d*%d+%d*%d\n",number,i,i,j,j,k,k,l,l);return;}
}
void main()
{int number=1;clrscr();puts("*****************************************************");puts("* This program is to verify Theorem of Four Squares.*");puts("* That is all natural numbers can be represented as *");puts("* sum of no more than 4 squares of the numbers.     *");puts("*****************************************************");while(number!=0){printf(" >> Please input a number to verify(0 to quit): ");scanf("%d",&number);      /*输入任一整数*/if(number==0)break;printf(" >> ------ Results of verification: ------------\n");verify_four_squares(number);printf(" >> ---------------------------------------------\n");}puts("\n Press any key to quit...");getch();
}

097.四方定理

#include<stdio.h>
void verify_four_squares(int number)
{int i,j,k,l;for(i=1;i<number/2;i++)         /*试探法。试探i,j,k,k的不同值*/for(j=0;j<=i;j++)for(k=0;k<=j;k++)for(l=0;l<=k;l++)if(number==i*i+j*j+k*k+l*l)    /*若满足定理要求则输出结果*/{printf(" >> %d=%d*%d+%d*%d+%d*%d+%d*%d\n",number,i,i,j,j,k,k,l,l);return;}
}
void main()
{int number=1;clrscr();puts("*****************************************************");puts("* This program is to verify Theorem of Four Squares.*");puts("* That is all natural numbers can be represented as *");puts("* sum of no more than 4 squares of the numbers.     *");puts("*****************************************************");while(number!=0){printf(" >> Please input a number to verify(0 to quit): ");scanf("%d",&number);      /*输入任一整数*/if(number==0)break;printf(" >> ------ Results of verification: ------------\n");verify_four_squares(number);printf(" >> ---------------------------------------------\n");}puts("\n Press any key to quit...");getch();
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论