Question

In: Computer Science

C PROGRAMMING LANGUAGE PROBLEM TITLE : ARRAY usually, if people want to input number into an...

C PROGRAMMING LANGUAGE

PROBLEM TITLE : ARRAY

usually, if people want to input number into an array, they will put it from index 0 until N - 1 using for. But, Bibi is bored to code like that. So, she didin't want to input the number that way.

So Bibi challenged you to make a program that will read a sequence (represent index) that she made, then input the number to an array but input it with the same sequence as sequence that Bibi gave.

Format Input

The first line represent integer N the size of Bibi's Array. The next line consist N integers Ai represent the sequence that Bibi want, it is guaranteed that the number is distinct. The next line consist N integers represent the value that she want to put inside array with index Ai.

Format Output

N integers represent the array that Bibi has starting from index 0.

Constraints

• 1 ≤ N ≤ 1, 000

• 0 ≤ Ai < N

Sample Input 1 (standard input)

5

0 1 2 3 4

1 2 3 4 5

Sample Output 1 (standard output)

1 2 3 4 5

Sample Input 2 (standard input)

5

4  3 2 1 0

1  2  3  4 5

Sample Output 2 (standard output)

5 4 3 2 1

sample Input 3 (standard input)

5

0 4 3 1 2

1 2 3 4 5

Sample Output 3 (standard output)

1 4 5 3 2

NOTES

• There isn’t any space after the last number.

• In the third sample Bibi want to input the number to array index 0 then 4 then 3 then 1 then 2

(MAKE THE COMPILER UNTIL SAMPLE 3)

Solutions

Expert Solution

C programming for above problem

#include <stdio.h>
int main()
{

int x;
int num[5];
int pos[5];
int n,number,i;
// loop runs upto 3 times
for (i=0; i<3;i++){
   
         
   // prompting and taking array
   printf("\nSample Input %d (standard input)",i+1);
   printf("\nEnter number of elements: ");
   scanf("%d", &n);
   // declaring array with all zeros
   int temp[5]={0,0,0,0,0};
  
   /* We are using a for loop to traverse through the array
   * while storing the entered values in the array
   */
   printf("\nEnter positions\n ");
   for (x=0; x<n;x++)
   {
       // taking inputs from the user
   scanf("%d", &pos[x]);
   }
   printf("\nEnter numbers\n");
   for (x=0; x<n;x++)
   {
   scanf("%d", &number);
   // condition check 1 <= N <= 1000
   if(number>=1 && number <=1000){
   temp[pos[x]]=number;  
           }
          
   }
  
   printf(" \nSample Output %d (standard output)\n",i+1);
   for (x=0; x<n;x++)
   {
       // printing the array
       printf("%d ", temp[x]);
   }
}
return 0;
}

OUTPUT SCREEN

#include <stdio.h>
int main()
{

    int x;
// declaring arrays
    int num[5];
    int pos[5];
    int n,number,i;
    // loop runs upto 3 times
     for (i=0; i<3;i++){
        
                 
            // prompting and taking array 
            printf("\nSample Input %d (standard input)",i+1);
            printf("\nEnter number of elements: ");
            scanf("%d", &n);
            // declaring array with all zeros
            int temp[5]={0,0,0,0,0}; 
        
            /* We are using a for loop to traverse through the array
             * while storing the entered values in the array
             */
             printf("\nEnter positions\n ");
             for (x=0; x<n;x++)
            {
                // taking inputs from the user
                scanf("%d", &pos[x]);
            }
            printf("\nEnter numbers\n");
            for (x=0; x<n;x++)
            {
                scanf("%d", &number);
                // condition check  1 <= N <= 1000
                if(number>=1 && number <=1000){
                temp[pos[x]]=number;    
                        }
                        
            }
            
            printf(" \nSample Output %d (standard output)\n",i+1);
            for (x=0; x<n;x++)
            {
                // printing the array
                printf("%d ", temp[x]);
            }
}
    return 0;
}


Related Solutions

C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements....
C PROGRAMMING LANGUAGE Problem title : Bibi's Array Bibi also has an array containing N elements. Like Lili, Bibi wants to know the highest frequency (most occurrences) and all elements which have that frequency. Format Input The first line contains an integer T stating the number of test cases. For each test case, the first line contains a single integer N which indicate the number of element in the array. The next line contains N integers Xi (1≤ i ≤...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade...
C Programming Language Problem Title : Take Three Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of the pandemic. So that the quality of learning remains good, Jojo's teacher gives a hard task for 4th grader. After the 4th graders finished their first task which is prime factorization. Jojo's teacher set up a game for the stundets. The game is very simple. Given N...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade...
C Programming Language Problem Title : 4th Grade Jojo just graduated and moved up to grade 4. Today is his first day in 4th grade. Unfortunately, the lessons are held online because of pandemic. So that the quality of learning remains good, Jojo’s teacher gives a hard task for 4th grader. The first task is to find the prime factorization of a number. Prime number is a natural number greater than 1 that is not a product of two smaller...
C Programming Language Problem Title : Museum Heist Jojo loves art. In his free time, he...
C Programming Language Problem Title : Museum Heist Jojo loves art. In his free time, he usually goes to the museum and admires the artwork there. since Jojo loves are so much, he is planning a heist at the museum. Jojo knows the price of every piece of art and doesn't want to raise suspicion, so he decided to steal the second most expensive art piece. It is guaranteed that there are at least two art pieces with different prices....
C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
C Programming Language Question The following program sums up a number from a user input argv[1]...
C Programming Language Question The following program sums up a number from a user input argv[1] by using a single thread. For example, argv[1] of 100 is going to give us a sum of 5050 using just a single thread. I need to modify it so that it takes 2 command lines args, argv[2] for number of threads. In other words, the program needs to use multi-threads to solve it. The number of threads is going to divide the work...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using malloc or calloc. Examples: Input: n = 5, A= {33,21,2,55,4} Output: {2,4,21,33,55} b) Write a function that declares an array of 256 doubles and initializes each element in the array to have a value equal to half of the index of that element. That is, the value at index 0 should be 0.0, the value at index 1 should be 0.5, the value at...
C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is...
C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields such that the field values oscillate repeatedly about a stable equilibrium value. Waves are usually represented using mathematical functions of the form F (x, t), where x = position and t = time. Your task is to write a program that will visualize a given wave for exactly N seconds. You do not need to worry about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT