Last active
August 29, 2015 14:09
-
-
Save aa-ahmed-aa/6e674ca8407b9dcfa867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int arr[5]; | |
int store; | |
for (int i = 0; i < 5; i++) | |
{ | |
cout << "please enter the value of index :" << endl; | |
cin >> arr[i]; | |
} | |
for (int i = 0; i < 4; i++) | |
{ | |
for (int j = i+1; j < 5; j++) | |
{ | |
if (arr[i]>arr[j]) | |
{ | |
store = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = store; | |
} | |
} | |
} | |
for (int f = 0; f < 5; f++) | |
{ | |
cout << arr[f]; | |
} | |
cout<<endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <stdio.h> | |
# include <cs50.h> | |
# include <string.h> | |
# define n 5 | |
int main () | |
{ | |
int a[n]; | |
printf("Please enter 5 numbers: \n"); | |
for(int i=0;i<n;i++) | |
{ | |
a[i]=GetInt(); | |
} | |
for(int i=0;i<n;i++) | |
{ | |
int smallest=a[i]; | |
int smallest_location=i; | |
for(int j=i+1;j<n;j++) | |
{ | |
if(a[j]<smallest) | |
{ | |
smallest=a[j]; | |
smallest_location=j; | |
} | |
} | |
a[smallest_location]=a[i]; | |
a[i]=smallest; | |
} | |
printf("Please wait..........\n"); | |
for(int i=0;i<n;i++) | |
{ | |
printf("%i\n",a[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment