-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquestion_4.cpp
More file actions
45 lines (44 loc) · 1.01 KB
/
question_4.cpp
File metadata and controls
45 lines (44 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
A nonnegative integer n is given. Design an algorithm to count all the solutions of the inequalityx2+y2< n,
where x and y are non-negative integers. The pseudocode should not use any operations with real numbers (square roots, etc.).
Analyse the pseudocodedesigned by you.
*/
#include <iostream>
using namespace std;
int comp(int a){
return(a%10);
}
void selectionSort(int arr[], int n){
int i, j, min_idx;
for (i = 0; i < n - 1; i++) {
min_idx = i;
for (j = i + 1; j < n; j++) {
if (comp(arr[j]) > comp(arr[min_idx]))
min_idx = j;
}
if (min_idx != i)
swap(arr[min_idx], arr[i]);
}
}
void print(int arr[], int size){
int i;
for (i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
int main() {
cout<<"S.Navaneetha Krishnan 21BCE1351\n";
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
printf("Original Array:");
print(arr,n);
selectionSort(arr,n);
printf("Sorted Array: ");
print(arr,n);
return 0;
}