Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
#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;
        }
Posted
Updated 2-Oct-14 0:45am
v2
Comments
[no name] 2-Oct-14 6:35am    
Look closer to "totalSize *=size;" and think about the value of totalSize.
TheSniper105 2-Oct-14 6:46am    
sorry that was mistake when copy code i updated it now but the probleme still
[no name] 2-Oct-14 10:30am    
Strange mistake... copy&paste usually works fine ;)

Like Wes noted, read first something about the Basics and like Sergei suggested try using the Debugger.

You wrote nothing happens. Keep in mind it is a console application and to see your Screen Outputs you should add something like "scanf" before "return 0". Otherwise console app Close immediately.

Try to go on with above Information and come back if you still have Problems.
Sergey Alexandrovich Kryukov 2-Oct-14 6:39am    
What is wrong? It's not using the debugger.
—SA
TheSniper105 2-Oct-14 6:40am    
what do you mean ??

1 solution

try this link

Magic Square[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900