1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KIM [24]
2 years ago
6

c Write a program that simulates a magic square using 3 one dimensional parallel arrays of integer type. Each one the arrays cor

responds to a row of the magic square. The program asks the user to enter the values of the magic square row by row and informs the user if the grid is a magic square or not. flowchart
Computers and Technology
1 answer:
Komok [63]2 years ago
7 0

Answer:

hope this helps and do consider giving a brainliest to the ans if it helped.

Explanation:

//program to check if the entered grid is magic square or not

/**c++ standard libraries

*/

#include<bits/stdc++.h>

using namespace std;

/**function to check whether the entered grid is magic square or not

*/

int isMagicSquare(int arr[3][3]){

  int i,j,sum=0,sum1=0,rsum,csum;

  for(i=0;i<3;i++){

      sum+=arr[i][i];

      sum1+=arr[i][2-i];

  }

  if(sum!=sum1){

      return 0;

  }

 

  for(i=0;i<3;i++){

      rsum=0;

      csum=0;

      for(j=0;j<3;j++){

          rsum+=arr[i][j];

          csum+=arr[j][i];

      }

      if(sum!=rsum){

          return 0;

      }

      if(sum!=csum){

          return 0;

      }

  }

  return 1;

}

/** main function to get user entries and

* call function

* and print output

*/

int main(){

  int i,j,arr[3][3]={0};

  for(i=0;i<3;i++){

      for(j=0;j<3;j++){

          cout<<"Enter the number for row "<<i<<" and column "<<j<<" : ";

          cin>>arr[i][j];

      }

  }

  int ret = isMagicSquare(arr);

  if(ret==1){

      cout<<"This is a Lo Shu magic square"<<endl;

  }

  else{

      cout<<"This is not a Lo Shu magic square"<<endl;

  }

  return 0;

}

You might be interested in
The first character of the VIN designates which of the following? 
Dennis_Churaev [7]

country or origin is usually the first character of a vin #

7 0
3 years ago
Read 2 more answers
Write a program num2rome.cpp that converts a positive integer into the Roman number system. The Roman number system has digits I
Tom [10]

Answer:

Explanation:

#include <stdio.h>  

int main(void)  

{    

   int num, rem;

   printf("Enter a number: ");

   scanf("%d", &num);

   printf("Roman numerals: ");        

   while(num != 0)

   {

       if (num >= 1000)       // 1000 - m

       {

          printf("m");

          num -= 1000;

       }

       else if (num >= 900)   // 900 -  cm

       {

          printf("cm");

          num -= 900;

       }        

       else if (num >= 500)   // 500 - d

       {            

          printf("d");

          num -= 500;

       }

       else if (num >= 400)   // 400 -  cd

       {

          printf("cd");

          num -= 400;

       }

       else if (num >= 100)   // 100 - c

       {

          printf("c");

          num -= 100;                        

       }

       else if (num >= 90)    // 90 - xc

       {

          printf("xc");

          num -= 90;                                              

       }

       else if (num >= 50)    // 50 - l

       {

          printf("l");

          num -= 50;                                                                      

       }

       else if (num >= 40)    // 40 - xl

       {

          printf("xl");            

          num -= 40;

       }

       else if (num >= 10)    // 10 - x

       {

          printf("x");

          num -= 10;            

       }

       else if (num >= 9)     // 9 - ix

       {

          printf("ix");

          num -= 9;                          

       }

       else if (num >= 5)     // 5 - v

       {

          printf("v");

          num -= 5;                                      

       }

       else if (num >= 4)     // 4 - iv

       {

          printf("iv");

          num -= 4;                                                            

       }

       else if (num >= 1)     // 1 - i

       {

          printf("i");

          num -= 1;                                                                                    

       }

   }

   return 0;

}

8 0
2 years ago
HELPPP
Westkost [7]

Answer:

D. 30 or more

Explanation:

All other ones are canceled out ad the score adds 10.

7 0
3 years ago
Example of Bandwidth Analogies: using Pipe
skelet666 [1.2K]

Answer:

Bandwidth describes the maximum data transfer rate of a network or Internet connection. ... For example, a gigabit Ethernet connection has a bandwidth of 1,000 Mbps (125 megabytes per second). An Internet connection via cable modem may provide 25 Mbps of bandwidth.

7 0
2 years ago
Read 2 more answers
What adaptation Judy and her parents have that help them run from predators coming?​
Elza [17]

Answer:

.57

Explanation:

3 0
2 years ago
Other questions:
  • You would like to set up an online meeting to communicate with colleagues on a group project. Which of these tools should you su
    9·1 answer
  • Behaving in an acceptable manner within a workplace environment is referred to as having
    9·1 answer
  • Compare and contrast the following network types: Personal Area Network (PAN) Local Area Network (LAN) Metropolitan Area Network
    14·1 answer
  • Assume you are a network consultant for a company that is designing a private WAN to communicate between five locations spread t
    10·1 answer
  • Write a program "addnumbers.c" where it takes as many arguments as the user includes as command line arguments and calculates th
    11·1 answer
  • A type of graph that uses horizontal bars to compare data is called a
    15·2 answers
  • I need le help, darn ijourneys
    10·2 answers
  • Define the terms of data and information .​
    6·1 answer
  • Do you think it’s better for a young designer to use free, open-source art programs or to pay for commercial programs? Explain y
    14·1 answer
  • Describe the method used by operating systems to differentiate between TCP connections.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!