Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help for perform some operation parallely Pin
superselector20-Jan-14 20:39
superselector20-Jan-14 20:39 
GeneralRe: Need help for perform some operation parallely Pin
OriginalGriff20-Jan-14 22:52
mveOriginalGriff20-Jan-14 22:52 
AnswerRe: Need help for perform some operation parallely Pin
GuyThiebaut20-Jan-14 21:55
professionalGuyThiebaut20-Jan-14 21:55 
GeneralRe: Need help for perform some operation parallely Pin
Ron Beyer21-Jan-14 2:26
professionalRon Beyer21-Jan-14 2:26 
GeneralRe: Need help for perform some operation parallely Pin
GuyThiebaut21-Jan-14 5:41
professionalGuyThiebaut21-Jan-14 5:41 
GeneralRe: Need help for perform some operation parallely Pin
GuyThiebaut21-Jan-14 6:27
professionalGuyThiebaut21-Jan-14 6:27 
GeneralRe: Need help for perform some operation parallely Pin
Ron Beyer21-Jan-14 7:01
professionalRon Beyer21-Jan-14 7:01 
QuestionHelp writing a program which adds up values in a 2D array to determine if it is a magic square Pin
Member 1052812320-Jan-14 3:43
Member 1052812320-Jan-14 3:43 
<pre lang="text">
Hi there,
I am attempting to write a program which adds up the values in a 2D array to determine if the array is a magic square(that is, that all rows, all columns, and all diagonals add up to the same amount). As you can see I have not gotten very far, and am having trouble working out how to add up each separate row and store the values as separate variables , so I can compare them.

I would appretiate some help on this if possible.







private void RunQuestionFour()
        {
            //for array
            int[,] anArray;
            int columns;
            int rows;

            //for checking
            int tempTotalvalue = 0;
            

            Random rndNumber1 = new Random();
           

            //create array and assign values to it

            Console.WriteLine("Please enter an integer to determine the size of the array e.g 5 = 5x5");
            columns = Convert.ToInt16(Console.ReadLine());
            rows = columns;

            Console.WriteLine("\n");

            anArray = new int[rows,columns];
            
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    int random1 = rndNumber1.Next(1, columns + 1);                   
                    anArray[i, j] = random1;            
                    Console.Write("{0} ", anArray[i, j]);
                    
                }
                Console.WriteLine();
            }

            //my attempt at adding up the values in each row

            for (int y = 0; y < rows; y++)
            {

                
                tempTotalvalue = 0; 
                

                for (int x = 0; x < columns; x++)
                {
                    tempTotalvalue = tempTotalvalue + anArray[y, x];

                   
                }

                Console.WriteLine(tempTotalvalue); //program so far writes out values of each row, but I need to store each row's value in different variables to compare them right?
                
            }
            
            Console.ReadLine();

           

        }


        static void Main(string[] args)
        {
            Soft140 mySoft140 = new Soft140();

            mySoft140.RunProgram();


            Console.ReadKey();
        }
    }
}

AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
Peter Leow20-Jan-14 4:20
professionalPeter Leow20-Jan-14 4:20 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
OriginalGriff20-Jan-14 5:50
mveOriginalGriff20-Jan-14 5:50 
AnswerRe: Help writing a program which adds up values in a 2D array to determine if it is a magic square Pin
BillWoodruff20-Jan-14 9:08
professionalBillWoodruff20-Jan-14 9:08 
QuestionCustom Data Types Pin
sunsilk1020-Jan-14 3:04
sunsilk1020-Jan-14 3:04 
AnswerRe: Custom Data Types Pin
Manfred Rudolf Bihy20-Jan-14 3:25
professionalManfred Rudolf Bihy20-Jan-14 3:25 
AnswerRe: Custom Data Types Pin
BillWoodruff20-Jan-14 5:13
professionalBillWoodruff20-Jan-14 5:13 
AnswerRe: Custom Data Types Pin
Freak3020-Jan-14 23:30
Freak3020-Jan-14 23:30 
QuestionC# with Oraclei Pin
Nightbird.14319-Jan-14 21:00
Nightbird.14319-Jan-14 21:00 
AnswerRe: C# with Oraclei Pin
V.19-Jan-14 21:49
professionalV.19-Jan-14 21:49 
QuestionMulti Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron19-Jan-14 19:23
ptr_Electron19-Jan-14 19:23 
AnswerRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
Mycroft Holmes19-Jan-14 21:02
professionalMycroft Holmes19-Jan-14 21:02 
GeneralRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron20-Jan-14 0:40
ptr_Electron20-Jan-14 0:40 
AnswerRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
Bernhard Hiller20-Jan-14 3:47
Bernhard Hiller20-Jan-14 3:47 
GeneralRe: Multi Desktop app, Need to take Screen short of a given desktop using handle. Pin
ptr_Electron20-Jan-14 7:11
ptr_Electron20-Jan-14 7:11 
QuestionSuggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
ahmed_one19-Jan-14 18:48
ahmed_one19-Jan-14 18:48 
AnswerRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
Mycroft Holmes19-Jan-14 20:57
professionalMycroft Holmes19-Jan-14 20:57 
GeneralRe: Suggestion required for Accounting Software core infrastructure VS2010 C# MySql Pin
ahmed_one19-Jan-14 21:11
ahmed_one19-Jan-14 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.