魔方问题 [英] magic square problem
本文介绍了魔方问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi2all我尝试使用c编程语言解决魔术方问题
但是当我运行代码时没有发生什么问题
这是我的代码
1-我要求用户输入魔方的大小
2-循环总大小
3-获得1号位置
4-也获得其他数字的位置
hi2all i try to solve magic square problem using c programming language
but when i run code nothing happened what is wrong
here is my code
1- i ask user to enter size of magic square
2- loop through total size
3- get the position of number 1
4- also get the position of other numbers
#include<stdio.h>
#include<conio.h>
int main()
{
int col,row,i,size,totalSize;
printf("please enter size of magic box\n");
scanf("%d",&size);
totalSize =size * size;
printf("total magic square size %d\n",totalSize);
for(i=1;i<=totalSize;i++)
{
if(i==1)
{
row =1;
col=(size+1)/2;
}else if(((i-1) % size) == 0){
row++;
}else{
row--; col--;
if(row == 0)
row = size;
if(col == 0)
col = size;
}
gotoxy(col,row);
printf("%d",i);
}
return 0;
}
推荐答案
试试这个链接
Magic Square [ ^ ]
这篇关于魔方问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文