answersLogoWhite

0


Best Answer

/*This program takes a square matrix from user and check whether it's a Magic Square or not. */

#include<stdio.h>

#include<conio.h>

int num[10][10],sum[21],r,c,i=0,x;

void read_matrix()

{ for(r=0;r<x;r++)

{ for(c=0;c<x;c++)

{ printf("Enter the value of matrix[%d][%d] :",r,c);

scanf("%d",&num[r][c]);

}

}

}

void calculate_sum()

{ int sum_row,sum_col=0,ctr=0;

for(r=0;r<x;r++)

{ sum_row = 0;

for(c=0;c<x;c++)

{ printf("\t%d",num[r][c]);

sum_row = sum_row + num[r][c];

}

sum[ctr] = sum_row;

ctr++;

printf(":: %d",sum_row);

printf("\n");

}

while(i<x)

{ printf("\t::");

i++;

}

printf("\n");

for(c=0;c<x;c++)

{sum_col = 0;

for(r=0;r<x;r++)

sum_col = sum_col + num[r][c];

sum[ctr] = sum_col;

ctr++;

printf("\t%d",sum_col);

}

for(r=0,c=0;r<x;r++,c++)

sum[2*x] = sum[2*x] + num[r][c];

for(r=0,c=x-1;r<x;r++,c--)

sum[2*x+1] = sum[2*x+1] + num[r][c];

}

char check_matrix()

{ char c;

for(i=0;i<2*x+1;i++)

{ if(sum[i] == sum[i+1])

c = 'Y';

else

{ c = 'N';

break;

}

}

return c;

}

void main()

{ char c;

clrscr();

printf("Enter d no. of rows or cols u want in your matrix :");

scanf("%d",&x);

read_matrix();

calculate_sum();

c = check_matrix();

if(c=='Y')

printf("\nThis matrix is a Magic Square");

else

printf("\nThis matrix is not a Magic Square");

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to determine whether or not the given square is a magic square?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


How do you write a C program to check whether the number is odd or even Ps-using DEV complier?

To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.


How do you write Square program using vb?

write a vb program to find the magic square


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


Write a c program to accept a numbers and generate square root cube and exponential values?

write a c program to accept a number and generate a square root cube and exponential values


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


How will you determine if it is a perfect square trinomial?

Write it in the form ax2 + bx + c. It is a perfect square if b2 = 4ac


Write a program which randomly creates letters and determine whether they are vowels or consonant using?

I still love Jerald sna tumaas grades ko lalong lalo na average ko po.... amen...


How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method.


Write a program in qbasic to make a hut using print statemant?

a triangle then a square :)


How do you write a c program to find square of a no using call by value?

int square (int N) return N*N;