forked from Abhijeet5665/c-programs-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting2.c
More file actions
60 lines (45 loc) · 619 Bytes
/
testing2.c
File metadata and controls
60 lines (45 loc) · 619 Bytes
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
47
48
49
50
51
52
53
#include<string.h>
#include<stdio.h>
#include<math.h>
int max=-999;
void swap(char *x,char *y){
char temp;
temp=*x;
*x=*y;
*y=temp;
}
void permute(char a[],int l,int r){
if(l==r){
//printf("%s\n",a);
int i=0,x;
int n=strlen(a);
int r=pow(10,n);
n--;
int sum=0;
while(i!=strlen(a)){
x=(int)a[i]-'0';
sum=sum+x*r;
r=pow(10,n);
n--;
i++;
}
if(max<sum/10)
max=sum/10;
printf("%d\n max=%d\n",sum/10,max);
}
else{
int i;
for(i=l;i<=r;i++){
swap(a+l,a+i);
permute(a,l+1,r);
swap(a+l,a+i);
}
}
}
void main(){
char str[20];
printf("eneter the string\n");
scanf("%s",str);
int n=strlen(str);
permute(str,0,n-1);
}