Question

Write a code fragment that reverses the order of the values in a one-dimensional string array....

Write a code fragment that reverses the order of the values in a one-dimensional string array. Do not create another array to hold the result. Hint: Use the code in the text for exchanging the values of two elements.. Implement using a while loop

Homework Answers

Answer #1

#include <stdio.h>

int main()

{

int arr[] = {1, 2, 3, 4, 5, 6};

int n = 6,start=0;

int end=n-1;

printf("Before Reverse: \n");

for (int i = 0; i < n; i++)

printf("%d ",arr[i]);

printf("\n");

while (start < end)

{

// swapping the fist and last elements

int temp = arr[start];

arr[start] = arr[end];

arr[end] = temp;

start++;

end--;

}

printf("Before Reverse: \n");

for (int i = 0; i < n; i++)

printf("%d ",arr[i]);

return 0;

}

Note : If you like my answer please rate and help me it is very Imp for me

Know the answer?
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
Similar Questions
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop...
C++ Code! Represent the following matrix using a two-dimensional array and write a nested for loop to initialize the elements (do not initialize the array in the declaration): 10  9   8 7   6   5 4 3   2
Write a code snippet to accept integer values coming from a user into an array named...
Write a code snippet to accept integer values coming from a user into an array named snippet and takes in 25 items using a do while loop
Write a swift code segment that reverses each word in a String (DO NOT use the...
Write a swift code segment that reverses each word in a String (DO NOT use the reverse method) I've been at this for awhile now. Language is Swift; must be beginner level. I know how to reverse all the letters in a string, but I can't figure out how to reverse just the letters in the words of a string ex. String = "the cat drank the milk" change to print "eht tac knard eht klim" How would you write...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++...
CAN YOU PLEASE WRITE THIS CODE IN A DIFFERENT WAY 'EASIER AND BETTER' QUESTION Using C++ 11. Write a function that will merge the contents of two sorted (ascending order) arrays of type double values, storing the result in an array out- put parameter (still in ascending order). The function shouldn’t assume that both its input parameter arrays are the same length but can assume First array 04 Second array Result array that one array doesn’t contain two copies of...
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
Perl Programming Language 1) Write a Perl script to concatenate "This is String One" and "This...
Perl Programming Language 1) Write a Perl script to concatenate "This is String One" and "This is String Two". Print all three strings, one per line with its length. Output: This is String One (print length here) This is String Two (print length here) This is String One This is String Two (print length here) 2) Write a Perl function that creates an array using qw function with the month names. It then prints the elements 4 and 7 (May...
Write a method that takes an integer array and returns a copy of this array, without...
Write a method that takes an integer array and returns a copy of this array, without the middle (two) elements. result of removing two values from the array { 2, 6, 2, 4 } [ 2 4 ] The result of removing one value from the array { 4, 6, 2, 3, 4, 5, 6 } [ 4 6 2 4 5 6 ] Using Java.
Write Java code to create a 2D array that mimics the one below. Do not use...
Write Java code to create a 2D array that mimics the one below. Do not use curly brackets to assign values. Instead, use nested loops and if-else or switch. x o o o x o x o x o o o z o o o x o x o x o o o x
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT