Answer Posted / sneh nagaonkar
/*Program to takes the the data of a 3x3 matrix and check if the given matrix is magic
square or not*/
#include <stdio.h>
#include <conio.h>
int num[3][3];
int sum[8];
int r,c,i;
/*Function to take the value in matrix from user*/
void read_matrix()
{
for(r=0;r<3; r++)
{
for(c=0;c<3; c++)
{
printf("Enter value for %d %d::",r,c);
scanf("%d",&num[r][c]);
}
}
}
/*Function to print matrix and get the sum of rows,cols and diaglons*/
void print_calc_rows_cols()
{
int sum_row,sum_col,ctr=0;
/*Print the Matrix and get the sum of rows*/
for(r=0;r<3; r++)
{
sum_row=0;
for(c=0;c<3; 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");
}
printf("\t::\t::\t::\n");
/*Get the sum of columns*/
for(c=0;c<3;c++)
{
sum_col=0;
for(r=0;r<3;r++)
sum_col=sum_col+num[r][c];
sum[ctr]=sum_col;
ctr++;
printf("\t%d",sum_col);
}
printf("\n");
/*Get the sum of diagnols*/
sum[6]=num[0][0]+num[1][1]+num[2][2];
sum[7]=num[0][2]+num[1][1]+num[2][0];
}
/*Function to Check the sum of rows,cols and diagnols*/
char check_matrix()
{
char c;
for(i=0;i<3; i++)
{
if(sum[i]==sum[i+1])
c='y';
else
{
c='n';
break;
}
}
return c;
}
void main()
{
char c;
clrscr();
read_matrix();
print_calc_rows_cols();
c=check_matrix();
/*Print the result*/
if(c=='y')
printf("\nThis Matrix is a Magic Square");
else
printf("\nThis Matrix is Not a Magic Square");
getch();
}
| Is This Answer Correct ? | 10 Yes | 4 No |
Post New Answer View All Answers
3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...
How to swap two ASCII numbers?
write a function that reverse the elements of an array in place.The function must accept only one pointer value and return void.
Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.
1+1/2!+1/3!+...+1/n!
Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++
How can I Draw an ellipse in 3d space and color it by using graph3d?
Code for Easily Using Hash Table?
solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)
Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?
write a program using virtual function to find the transposing of a square matrix?
Performance Algorithm A performs 10n2 basic operations and algorithm B performs 300 lg n basic operations. For what value of n does algorithm B start to show its better performance?
i don't know about working of nested for loop can any one help me
find level of following tree (state, parent) " J,D I,D H,C E,B F,B G,C B,A D,A C,A A,& K,E L,E L,F M,F N,G O,H P,I P,H Q,I R,J S,K U,P T,L
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.