NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Write a note in
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,rows,col,diagonal_1=0,diagonal_2=0,m,n,k=0,sum_rows=0,sum_col=0,flag=0;
printf("Enter number of rowsn");
scanf("%d",&rows);
col=rows;
int a[rows][col];
if(rows%2!=0)
{
m=0;
n=rows-1;
//Taking input for Magic Square
printf("Enter Magic Square Numbers Horizontallyn");
//If 8 1 6
// 3 5 7
// 4 9 2
//Then Enter from 8 to 6 and then 3 to 7 and then 4 to 9
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The given Matrix isn");
for(i=0;i<rows;i++)
{
for(j=0;j<col;j++)
{
printf("%dt",a[i][j]);
}
printf("n");
}
//Finding Sum for 2 Diagonals
for(i=0;i<rows;i++)
{
diagonal_1+=a[i][i];
diagonal_2+=a[m][n];
m++;
n--;
}
printf("Sum of diagonal 1 is %dn",diagonal_1);
printf("Sum of diagonal 2 is %dn",diagonal_2);
if(diagonal_2==diagonal_1)
{
flag=1;
}
else
{
flag=0;
printf("Diagonals Sum are not Equal so Not A MagicSquaren");
exit(0);
}
//Finding Sum of Rows
for(i=0;i<rows;i++)
{
sum_rows=0;

for(j=0;j<col;j++)
{
sum_rows+=a[i][j];
}
printf("Sum of %d Row is %dn",k,sum_rows);
k++;
if(diagonal_1==sum_rows)
{
flag=1;
}
else
{
flag=0;
printf("Sum of Rows and Diagonals are not Equal,so Not A MagicSquaren");
exit(0);
}
}

//Finding sum of Columns
k=0;
for(i=0;i<col;i++)
{
sum_col=0;
for(j=0;j<rows;j++)
{
sum_col+=a[j][i];
}
printf("Sum of %d Column is %dn",k,sum_col);
k++;
if(diagonal_1==sum_col)
{
flag=1;
}
else
{
flag=0;
printf("Even Though Diagonals and Rows Sum are Equal but Sum of Columns are not Equal,so Not A MagicSquaren");
exit(0);
}
}
if(flag==1)
printf("Given Matrix is Magic Squaren");
}
else
{
printf("Not Possible as rows has to be Oddn");
}
return(0);
}
Enter number of rows
3
Enter Magic Square Numbers Horizontally
8
1
6
3
5
7
4
9
2
The given Matrix is
8 1 6
3 5 7
4 9 2
Sum of diagonal 1 is 15
Sum of diagonal 2 is 15
Sum of 0 Row is 15
Sum of 1 Row is 15
Sum of 2 Row is 15
Sum of 0 Column is 15
Sum of 1 Column is 15
Sum of 2 Column is 15
Given Matrix is Magic Square



//Coming Soon..
area. It's really easy to share with others. Click here ...
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.