Question

Create a C# program using WINDOWS FORM App in Visual Studio. THE ANSWER MUST BE IN...

Create a C# program using WINDOWS FORM App in Visual Studio. THE ANSWER MUST BE IN C#, IN WINDOW FORM APP, IN VISUAL STUDIOS. Write the code to:

Write a method called MaximumDiffrence that accepts an integer array as a parameter and return the maximum difference between adjacent values in the array, where the gap is defined as the absolute value of the difference between the 2 adjacent values.

Example: if the array contains {5, 7, 4, 9, 6, 12, 8} so

The first gap is (5,7)=-2 and the absolute value is 2

The second gap is (7,4)=3

Third gap is (4,9) = -5 its absolute value is 5

Fourth gap is (9,6) = 3

Fifth gap is (6,12) = 6

Sixth gap is (12, 8) = 4

The method should return 6, the max absolute difference

If the array has just 2 or less elements, then it should return 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

On form button click event you can write the below code , assuming that the input is from a text box of integers separated with semi column (ex : 1;2;3;4)

private void btnSubmit_Click(object sender, Eventargs e)

{

string a = txtArray.Text;
       int result = 0;
       char[] delimiter1 = new char[] {';'};
       string[] array1 = a.Split(delimiter1, StringSplitOptions.None);
       int[] b = new int[array1.Length];
       for(int i = 0 ; i < array1.Length ; i++)
       {
           b[i] = Convert.ToInt32(array1[i]);
       }
       if(b.Length > 2)
       {
           for(int i = 0 ; i < b.Length-1 ; i++)
           {
               int result1 = Math.Abs(b[i]-b[i+1]);
               result = (result > result1 ? result : result1);
           }
           MessageBox.Show(result);
       }
       else
       {
           MessageBox.Show("0");
       }

}

Add a comment
Know the answer?
Add Answer to:
Create a C# program using WINDOWS FORM App in Visual Studio. THE ANSWER MUST BE IN...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create in C# Write a method called MaximumDiffrence that accepts an integer array as a parameter...

    Create in C# Write a method called MaximumDiffrence that accepts an integer array as a parameter and return the maximum difference between adjacent values in the array, where the gap is defined as the absolute value of the difference between the 2 adjacent values. Example: if the array contains {5, 7, 4, 9, 6, 12, 8} so The first gap is (5,7)=-2 and the absolute value is 2 The second gap is (7,4)=3 Third gap is (4,9) = -5 its...

  • **This program is to be created using Visual Studio C#**Create as a Windows Form application** 1....

    **This program is to be created using Visual Studio C#**Create as a Windows Form application** 1. Output a header in the console: “This is a replacement program” 1. Output a header that states: “This is Program 5” 2. Output a thank you message: “Thank you for running the program.”

  • **This program is to be created using Visual Studio C#**Create as a Windows Form application** 1....

    **This program is to be created using Visual Studio C#**Create as a Windows Form application** 1. Output a header in the console: "Program 1" 2. Next you will ask the user to enter three floats and read the values into variables. 3. Perform addition, multiplication, and division examples with the numbers entered. 4. Implicitly cast the floats into doubles. 5. Explicitly cast the floats into ints. 6. Use conversion methods to convert the floats into strings. 7. Ask the user...

  • In Visual Basic Windows Form App, how would you create an object with 5 fields that...

    In Visual Basic Windows Form App, how would you create an object with 5 fields that pulled from text boxes and adds the object to an array of objects at the push of a button. For example an object Item has the fields strManufacturer, strProcessor, strForm, strVideo, and strRAM. How do I send the text someone enters in to those variables and make an object that is in an array of objects with a button called save?

  • Please note: This is in Visual Basic. Create an application (windows forms app). Add a label...

    Please note: This is in Visual Basic. Create an application (windows forms app). Add a label and a button to the form. The button’s Click event procedure should declare and initialize a one-dimensional Double array. Use any six numbers to initialize the array. The procedure should display (in the label) the lowest value stored in the array. Code the procedure using the For...Next statement.

  • Write a C# Windows Forms App code in Visual studio with a "start", "stop", "up", "down",...

    Write a C# Windows Forms App code in Visual studio with a "start", "stop", "up", "down", "left" and "right" buttons and a textbox. The textbox should start printing numbers from 1 to 100 on the press of the "start" button and stop printing process immediately on the press of "stop" button. Also create a thread after stop button is pressed to allow manual input from  "up", "down", "left" and "right" buttons and print up, down, left or right in the same...

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • Program must be in C language and MUST be able to run on visual studio 2....

    Program must be in C language and MUST be able to run on visual studio 2. Using Pointers and Arrays 2.1 Write a function bubblesort which will accept an array of double precision floating point numbers of length N and sort the array. Ref: https://en.wikipedia.org/wiki/Bubble_sort (I can verify this is accurate) 2.2 Write a program which exercises the bubblesort. For a good test, the program should have more than 20 values.

  • VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE &...

    VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE & ANSWER/FOLLOW ALL THE QUESTIONS IN THE ASSIGNMENT! . . Your program assignment Write a program name DeskGUI that computes the price of a desk and whose button Click Event calls the following methods: • A method to accept the number of drawers in the desk as input from the key board. This method returns the number of drawers to the SelectDesk_Click event. A method...

  • VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE &...

    VISUAL STUDIO - WINDOWS FORM APP (C#) - PLEASE MAKE SURE TO SHOW ALL CODE & ANSWER/FOLLOW ALL THE QUESTIONS IN THE ASSIGNMENT! . . Your program assignment Write a program name DeskGUI that computes the price of a desk and whose button Click Event calls the following methods: • A method to accept the number of drawers in the desk as input from the key board. This method returns the number of drawers to the SelectDesk_Click event. A method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT