URI ONLINE JUDGE SOLUTION 1042 - Simple Sort
Problem
Solution
C programming source code for uri online judge beginner problem 1042 - Simple Sort
Read three integers and sort them in ascending
order. After, print these values in ascending order, a blank line and
then the values in the sequence as they were readed.
Input
The input contains three integer numbers.
Output
Solution
C programming source code for uri online judge beginner problem 1042 - Simple Sort
#include<stdio.h>
int main()
{
int val[3],sort[3],i,j,temp;
for(i=0;i<3;i++){
scanf("%d",&val[i]);
sort[i]=val[i];}
for(i=0;i<2;i++){
for(j=0;j<2;j++){
if(sort[j]>sort[j+1]){
temp=sort[j+1];
sort[j+1]=sort[j];
sort[j]=temp;}
}
}
for(i=0;i<3;i++)
printf("%d\n",sort[i]);
printf("\n");
for(i=0;i<3;i++)
printf("%d\n",val[i]);
return 0;
}
How it works? This is the beginner level problem of uri online judge.Here you would have to sort three integer value.At first you would have to take three integer value as user input.Then you can apply any sorting algorithm.You can also solve this without using any sorting algorithm as there are only three integers value.After sorting you should print them in ascending order,and a blank line and the way data is inputed. Hopefully you would understand the problem.Don't copy paste the code as same.Just try to understand it and then try yourself. It would be better for you.
int main()
{
int val[3],sort[3],i,j,temp;
for(i=0;i<3;i++){
scanf("%d",&val[i]);
sort[i]=val[i];}
for(i=0;i<2;i++){
for(j=0;j<2;j++){
if(sort[j]>sort[j+1]){
temp=sort[j+1];
sort[j+1]=sort[j];
sort[j]=temp;}
}
}
for(i=0;i<3;i++)
printf("%d\n",sort[i]);
printf("\n");
for(i=0;i<3;i++)
printf("%d\n",val[i]);
return 0;
}
Comments
Post a Comment