#include <stdio.h>
int main()
{
int m,n,i,j,k,temp;
scanf("%d %d",&m,&n);
int ara1[m+n],ara2[n]; //m+n because i'll copy 2nd array to 1st array
for(i=0;i<m;i++){
scanf("%d",&ara1[i]);
}
for(j=0;j<n;j++){
scanf("%d",&ara2[j]);
}
j=0;
//copying elements of 2nd array to 1st array
for(i=m;i<(m+n);i++){
ara1[i]=ara2[j];
j++;
}
//sorting array in increasing order
for(i=0;i<(m+n);i++){
for(j=i+1;j<(m+n);j++){
if(ara1[i]>ara1[j]){
temp = ara1[i];
ara1[i]=ara1[j];
ara1[j] = temp;
}
//removing 2nd element if there are two same elements
if(ara1[i]==ara1[j]){
for(k=j;k<(m+n-1);k++){
ara1[k]=ara1[k+1];
}
n--;
}
}
}
for(i=0;i<(m+n-1);i++){
printf("%d ",ara1[i]);
}
printf("%d",ara1[i]); //printing the last element without space ahead of it
return 0;
}
I’m getting RUNTIME ERROR in 3rd case. Please help me find where’s the problem.
Oh! Sorry! @Abdullah_1234 I didn’t specifically meant the last loop.
I wanted to mean drop the if statement in the last loop.
And also sort the list y before that.
Miscalculations from both side I think.
y is guaranteed to be sorted already but what @Abdullah_1234 is doing is appending new elements of x in its end.
So, he requires to sort it again.
I tested it before commenting.
Are you sure, bhaia? Because, these tree lines of code:
for i in x:
if i not in y:
y.append(i)
Is doing the following:
Take each element from X
If it satisfies a condition, append it to the back of Y:
Now, if X is originally sorted, then Y will be sorted at the end for sure.
Let’s take this list for example:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
If you take each element from here from left to right, and push the odd ones to a new list, the new list will have the odd numbers in sorted order. Shouldn’t it?
Oh! Sorry, my bad. submission
I didn’t notice that he took an empty list for calculations.
Hmm, It will work even without sorting.
Btw, @hjr265 bro, It is a long time since I have argued over codes.
Hope to argue with you again.
Can you help me with a problem of mine after the end of the mock contest?
Thanks bro.
I was absent for quite a few days because I had to study to complete my syllabus for the upcoming exam.
Hope you will also help in the future