Move Hundreds to End

 Coding Problem Keys 

 Move Hundreds to End 

 Problem Statement 

Fill in the missing lines of code to implement the method  (function) moveHundreds (int array[], int size) so that the method moves all the integer values with 100 to the end of the array. The order of the remaining integers must be maintained.

 Boundary Condition(s) 

1 <= N <= 1000

 Example Input/Output 1 

 Input 

6
12 100 45 8 100 25

 Output 

12 45 8 25 100 100

 Explanation 

There are two integer values as 100 which are moved to the end.
The remaining integers 12 45 8 25 are printed in the same order as given in the input.

 Example Input/Output 2 

 Input 

8
100 100 65 100 14 100 100 56

 Output 

65 14 56 100 100 100 100 100

 Max Execution Time Limit: 4000 millisecs 

 Solution 

 Programming Language: C Language 

void moveHundreds(int array[],int size){
    int arr[size],c=0;
    for(int i=0;i<size;i++){
        if(array[i]!=100){
            arr[c]=array[i];
            c++;
        }
    }
    for(int i=0;i<c;i++){
        array[i]=arr[i];
    }
    while(c<size){
        array[c]=100;
        c++;
    }
}

// Published By PKJCODERS

 Alter 

// Note: This code is not for SkillRack Users

#include <stdio.h>
void moveHundreds(int arr[],int size){
    int c=0;
    for(int i=0;i<size;i++){
        if(arr[i]==100){
            c++;
            continue;
        }else{
            printf("%d ",arr[i]);
        }
    }
    while(c>0){
        printf("100 ");
        c--;
    }

}
int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    for(int i=0;i<n;i++)
        scanf("%d",&arr[i]);
    moveHundreds(arr,n);
}

// Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Print Alphabets

Sort Number By Unit and Tenth Digits

Matrix Unit Digit Swap

Array Elements - Divisible by D

Unique Characters

Next Multiple of X after N