-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpfulMaths.cpp
46 lines (39 loc) · 1.03 KB
/
helpfulMaths.cpp
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
46
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[101];
cin>>str;
int count = strlen(str);
int x= count/2 +1;
// intermediate array formation with only numbers
int intermediatearray[101];
char* ptr = str;
while(*ptr != '\0'){
static int i=0;
intermediatearray[i]=*ptr-48;
ptr=ptr+2;
i++;
}
// for(int i=0;i<elementsIA;i++){
// cout<<intermediatearray[i]<<" ";
// }
// intermediate array sort using bubble sort algorithm
for(int i=0;i<x-1;i++){
for(int j=0;j<x-1;j++){
if(intermediatearray[j]>intermediatearray[j+1]){
int temp;
temp = intermediatearray[j];
intermediatearray[j]= intermediatearray[j+1];
intermediatearray[j+1]=temp;
}
}
}
// intermediate array display with required outlook
for(int i=0;i<x-1;i++){
cout<<intermediatearray[i]<<"+";
}
cout<<intermediatearray[x-1];
return 0 ;
}