Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have code to create a magic square, which can be seen below. However, I\'m on

ID: 3624626 • Letter: I

Question

I have code to create a magic square, which can be seen below. However, I'm on linux and cannot use conio.h, which therefore means I cannot use the getch() keyword. Any ideas to fix the problem?

#include<stdio.h>
#include<conio.h>
int main()
{
int a[20][20],r,c,br,bc,k,n;

printf("Enter the Order of Magic Square(Odd): ");
scanf("%d",&n);
for(r=0;r<n;r++)
for(c=0;c<n;c++)
a[r][c]=0;
r=0;
c=n/2;
for(k=1;k<=n*n;k++)
{
a[r][c]=k;
br=r++;
bc=c++;
r=(r+1)%n;
c=(c+1)%n;
if(a[r][c]!=0)
{
c=bc;
r=br-1;
if(r<0)r=n-1;
}
}
printf("The Magic Square... ");
for(r=0;r<n;r++)
{
for(c=0;c<n;c++)
printf(" %d",a[r][c]);
printf(" ");
}
getch();
return 0;
}

Explanation / Answer

in linux no need to use conio.h and getch();

u can simply comment them or remove them in linux :)

compile c program in linux using gcc

it generate a.out file

run that file simly by typing ./a.out in terminal.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote