# How do you write a program to find magic numbers?

#include<stdio.h>

unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) {

unsigned sum, col;

sum = 0;

for (col=0; col<width; ++col)

sum += sq[row*width+col];

return sum;

}

unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) {

unsigned sum, row;

sum = 0;

for (row=0; row<width; ++row)

sum += sq[row*width+col];

return sum;

}

unsigned sum_diag (unsigned* sq, const unsigned width) {

unsigned sum, row, col;

sum = 0;

for (row=0, col=0; row<width; ++row, ++col)

sum += sq[row*width+col];

return sum;

}

unsigned sum_anti (unsigned* sq, const unsigned width) {

unsigned sum, row, col;

sum = 0;

for (row=0, col=width-1; row<width; ++row, --col)

sum += sq[row*width+col];

return sum;

}

bool is_magic (unsigned* sq, const unsigned width) {

unsigned magic, row, col;

magic = sum_row (sq, width, 0);

for (row=1; row<width; ++row)

if (magic!=sum_row(sq, width, row))

return false;

for (col=0; col<width; ++col)

if (magic!=sum_col(sq, width, col))

return false;

if (magic!=sum_diag(sq, width))

return false;

if (magic!=sum_anti(sq, width))

return false;

return true;

}

int main () {

const unsigned width = 3;

unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}};

unsigned row, col;

printf ("Square:\n\n");

for (row=0; row<width; ++row) {

for (col=0; col<width; ++col) {

printf ("%d ", a[row][col]);

}

printf ("\n");

}

printf ("\n");

if (is_magic((unsigned*)&a, width))

printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0));

else

printf ("The square is not magic\n");

return 0;

}

### How do you write Square program using vb?

write a vb program to find the magic square Read More

### How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers Read More

### How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers Read More

### Write a c program to find out the prime numbers between 1 to 500?

write a program to find prime number between 1 to500 Read More

### Write a c program to find GCD of n numbers using recursion?

Is this a question? If it is, the answer is: 'yes, do write'. Read More

### How to find phone numbers of Magic Jack customers?

You must go to pirates bay and download the program babbotupkong and then one that is running go to magic jack.com and click contacts. Once there the program will take over. Read More

### Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer Read More

### Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity. Read More

### How do you write c program to find sum of two numbers?

You add numbers as follows: sum = a + b; Read More

### Write a C program to find the square of two numbers?

Please visit http://talentsealed.blogspot.com/2009/10/to-find-sqaure-of-numbers-using-c.html for the answer. Read More

### Write a program to find the sum of squares of the given number?

Algorithm and Flowcharts for a program to compute the sum of the squares of the numbers for a given range used for loop Read More

### How do you write a c program to find maximum and minimum of a set of numbers?

How do you write a c program to find maximum and minimum number in a given array? Read More

### How do you write a C program to find all the prime numbers between 1 and 1000 inclusive?

Sieve of eratothanes is a popular one. Read More

### Write a program to input two numbers and interchange there value using the third variable Give anawers in Basic method?

write a c program to find out whether the character presses through keyboard is a digit or not (using conditional operator) Read More

### Mca vtu notes for 1st sem?

Write a simple program to find out how many of the numbers from 1 to 10 is greater than 4. Read More

### Write a C program to find sum of odd numbers from 1to 100?

printf ("%d\n", (1+99)/2*50). Read More

### Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head. Read More

### Write a Program in c to find palindrome numbers between any two numbers?

please somebody should help me answer this question..I have a project on it even! It seems almost impossible at the moment. Read More

### How do you write a program to find out the square and cube of first ten natural numbers in gw basic?

First you will need to have some basic programming knowledge. You can use this to help make the program that is needed. Read More

### Write a program to input 10 numbers in an array find and print their sum and average mean?

Open a computer program like Visual Basic, Java, or C#, and then create an object and label it as an array. Input your 10 numbers into the object, then loop through each object in the array to find the sum, average, and mean by writing code in the program. Read More

### Write a program to find the grade obtained by the students of a class using structure?

Write a program to find the grade obtained by the students of a class Read More

### Write c sharp program to find sum of two numbers?

public int findSum(int n1, int n2) { return n1 + n2; } Read More

### Write a c program to find eigenvalue of a matrix?

Yes, do write. That's what you always have to do when you have got a homework-program. Read More

### Write a program to find out the total marks a five subject?

write a program accepts the marks of three subjects and find the total using suitable function. Read More

### Write a c program to find simple interest?

write a program in c to calculate simple interest for 5 years Read More

### Write an assembly program to find the biggest among two numbers?

Each processor type has its own assembly language. Are you looking for something generic, or for a particular processor? Read More

### How do you write a c program to find the biggest of two numbers using ternary operator?

printf ("Biggest: %d\n", N>M ? N : M); Read More

### How do you write a c program to find biggest among two numbers using conditional operator?

int max (int a, int b) { return a>b?a:b; } Read More

### Write a program to find the smaller of two numbers using javascript code?

Just use a series of ifs to check whether a < b, a > b or a == b. Read More

### How do you find out the annual sales numbers for Magic the Gathering?

go to wizards of the cost.com Read More

### Write a c program to find Volume and surface area of cube?

Write a c program to compute the surface area and volume of a cube Read More

### How do you write a C program to find the GCD and LCM. write the flowchart and algorithm of the above program?

This question is not a question. You are supposed to do your homework yourself. Read More

### Write a program to find gcd using recursive method in java?

simple program for recursion in java Read More

### Where can you find a list of 4 digits numbers?

Write down the numbers from 1000 to 9999. Read More

### How can you write a program to find the mean resistance in c language given the values of 8 resistances?

"Mean" usually means "average", so you just add the numbers together, then divide by 8. Read More

### Write an algorithm to find sum of n given numbers?

write algorithem to find the sum of given n number Read More

### How do you write a program to find out the percentage of given numbers using the structure in C?

Count all the given numbers then count all the numbers of a given value. Divide one by the other and multiply by 100. For instance, if there are 50 numbers in total and 5 of them have the value 42, then the percentage of numbers with the value 42 is 5 / 50 * 100 = 10%. Read More

### How do you write a C program to find the total and average for seven subjects?

To write a C program to find the total and average for seven subjects, sum the seven subjects to get the total. Divide the total by seven to get the average. Read More

### Write programme for sum of number given?

write a program to find the sum of squares up to 50 Read More

### Write a C program to find the cosine and sine?

Sure, do write. The attached wikipedia-entry will help. Read More

### How do you write a program to find the sum of n numbers in an array?

In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; } In Java: // This program adds all numbers in the array int sum = 0; for (int i = 0; i < myArray.length(); i++) { sum += myArray[i]; } In Java: // This program adds all numbers in the array int sum = 0; for (int… Read More

### Write a recursive function in C to find sum of even numbers from 2 to 50?

Write a recursive function in C to find sum of even numbers from 2 to 50? Read More

### Write a c program to find the product of two numbers without using operator?

I guess you meant 'without multiplication operator'. Try to use this: a*b = exp (ln (a) + ln(b)) Read More