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
klio [65]
3 years ago
15

Write a method swaparrayends() that swaps the first and last elements of its array parameter. ex: sortarray = {10, 20, 30, 40} b

ecomes {40, 20, 30, 10}. the array's size may differ from 4.
Computers and Technology
1 answer:
Alexus [3.1K]3 years ago
3 0
In the C programming language, you can't determine the array size from the parameter, so you have to pass it in as an extra parameter. The solution could be:

#include <stdio.h>

void swaparrayends(int arr[], int nrElements)
{
int temp = arr[0];
arr[0] = arr[nrElements - 1];
arr[nrElements - 1] = temp;
}


void main()
{
int i;
int myArray[] = { 1,2,3,4,5 };
int nrElements = sizeof(myArray) / sizeof(myArray[0]);
swaparrayends(myArray, nrElements);

for (i = 0; i < nrElements; i++)
{
printf("%d ", myArray[i]);
}

getchar();
}

In higher languages like C# it becomes much simpler:

        static void Main(string[] args)
        {
            int[] myArray = {1, 2, 3, 4, 5};
            swaparrayends(myArray);
            foreach (var el in myArray)
            {
                Console.Write(el + " ");
            }

            Console.ReadLine();
        }

        static void swaparrayends(int[] arr)
        {
            int temp = arr[0];
            arr[0] = arr.Last();
            arr[arr.Length - 1] = temp;
        }

You might be interested in
Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and ca
REY [17]

Answer:

The code for this class is shown in the explanation section

Explanation:

public class Circle {

   private double radius;

   private double diameter;

   private double area;

   public Circle(double radius, double diameter, double area) {

       this.radius = 1;

       this.diameter = diameter;

       this.area = area;

   }

   public void setRadius(double radius) {

       this.radius = radius;

       diameter = radius*2;

       area= Math.PI*(radius*radius);

   }

   public double getRadius() {

       return radius;

   }

}

6 0
3 years ago
The following is the pseudocode for which type of algorithm? For start = each array subscript, from the first to the next-to-las
Snezhnost [94]

Answer:

Sorting Algorithm

Explanation:

Here we are arraigning the elements in ascending order. Using for loop we are iterating through all the elements. in one iteration the first minimum element in the list is at 1st place and in the second iteration the second minimum element is in 2nd position and so on

8 0
3 years ago
If you’re paid hourly and work 40 hours in one week how much overtime have you worked? 8 hours none $48 or $80
Serggg [28]

Answer: You said 40 Hours. So $40

So, Isn't it $48, Because How Do You Get 80?

5 0
4 years ago
Read 2 more answers
When should students practice netiquette in an online course? Check all that apply.
ser-zykov [4K]

Answer:

The answer to this question is given below in the explanation section. However, the correct answer is: student should practice netiquette in an online course when they are participating in online discussion board.

Explanation:

It is important for you as a student to recognize that the online classroom is in fact a classroom, and certain behaviors are expected when you communicate with both your peers and your instructors. These guidelines for online behavior and interaction are known as “netiquette”.

So, the correct option of this question is: students should practice netiquette in an online course when they are participating in an online discussion board. Because the discussion board is opened by the instructor/tutor, he constantly looking for student behavior throughout the discussion. so, students should use netiquette practice during the discussion in the online class.

However, other options are not correct because, in these options, there is not the presence of teacher/instructor. And, also noted that netiquette is practiced in online class by the student.  

8 0
3 years ago
Read 2 more answers
Using the college registration example from section 6.7.3 as a starting point, do the following:
Arada [10]

Answer:

Explanation:

NCLUDE Irvine32.inc

TRUE = 1

FALSE = 0

.data

gradeAverage WORD ?

credits WORD ?

oKToRegister BYTE ?

str1 BYTE "Error: Credits must be between 1 and 30" , 0dh,0ah,0

main PROC

call CheckRegs

exit

main ENDP

CheckRegs PROC

push edx

mov OkToRegister,FALSE

; Check credits for valid range 1-30

cmp credits,1 ; credits < 1?

jb E1

cmp credits,30 ; credits > 30?

ja E1

jmp L1 ; credits are ok

; Display error message: credits out of range

E1:

mov edx,OFFSET str1

call WriteString

jmp L4

L1:

cmp gradeAverage,350 ; if gradeAverage > 350

jna L2

mov OkToRegister,TRUE ; OkToRegister = TRUE

jmp L4

L2:

cmp gradeAverage,250 ; elseif gradeAverage > 250

jna L3

cmp credits,16 ; && credits <= 16

jnbe L3

mov OkToRegister,TRUE ; OKToRegister = TRUE

jmp L4

L3:

cmp credits,12 ; elseif credits <= 12

ja L4

mov OkToRegister,TRUE ; OKToRegister = TRUE

L4:

pop edx ; endif

ret

CheckRegs ENDP

END main

8 0
4 years ago
Other questions:
  • Marie can now edit her photos, send them in emails, print them on a printer, and use them as wallpaper on her computer. This is
    9·2 answers
  • Nonverbal communication relies on _________________. a. multiple channels b. continuous feedback c. ambiguous interpretation d.
    9·1 answer
  • The next page and previous page buttons allow you to navigate through a worksheet while in print preview mode.
    6·1 answer
  • Computer input is the process of translating physical signals (light, sound, movement) into which of the following?
    8·2 answers
  • An investment website can tell what devices are used to access the site. The site managers wonder whether they should enhance th
    10·1 answer
  • Int [] val = { 3, 10, 44 };
    13·1 answer
  • In the Microsoft Office Suite, what tells a database what to insert information in the document? 
    8·1 answer
  • The most effective technique of malware propagation among the following list
    7·1 answer
  • Any movie/show suggestions??
    7·2 answers
  • Database policies should be created and implemented by all organizations, regardless of the ________ of the organization.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!