Beecrowd 1175 – Array change I Solution

Beecrowd 1175 – Array change I Solution

Array change I

URI 1175 Array change I

Problem:

Write a program that reads an array N [20]. After, change the first element by the last, the second element by the penultimate, etc., until changing the 10th to the 11th. Print the modified array.

Input:

The input contains 20 integer numbers, positive or negative.

Output:

For each position of the array N print “N[i] = Y”, where i is the array position and Y is the number stored in that position after the modifications.

Beecrowd 1175 - Array change I

Beecrowd 1175 – Array change I solution in C

#include<stdio.h>
int main() {
 int N[20],i,temp=0;
for(i=19;i>=0;i--){
    scanf("%d",&N[i]);
}



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

    printf("N[%d] = %d\n",i,N[i]);
}

    return 0;
}

Explanation:

In this program, we first declare an integer array N of size 20 and also declare three integer variables i, j, and temp. We use a for loop to take input from the user for the array N.

Next, we use another for loop to swap the values of the array elements. In each iteration, we take the ith element and the jth element and swap their values. We use a temporary variable temp to store the value of the ith element before swapping. We start swapping from the beginning and end of the array and move towards the middle until we reach the 10th and 11th elements.

Finally, we use another for loop to print the modified array. We print each element of the array using the printf function.

This solution uses basic array manipulation and should be easy to understand.

BEECROWD Problems Solution

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck