0

how to make ascending operator

i want to sort some operator for example: input=& ^ ! (each input with space) output=! & ^ the order is the same as in ASCII and each input and output operator have one space before the other operator

13th Oct 2018, 3:02 AM
Yoaraci
Yoaraci - avatar
3 ответов
+ 8
#include <stdio.h> #include <string.h> int main() { char sym[5]; fgets(sym, 5, stdin); printf("You entered: %s\n\n", sym); for(int i = 0; i < (strlen(sym) - 1); i++) { for(int j = 0; j < (strlen(sym) - 1) - 1; j++) { if(sym[j] > sym[j+1]) { char temp = sym[j]; sym[j] = sym[j+1]; sym[j+1] = temp; } } } printf("After sorting: %s\n", sym); return 0; }
13th Oct 2018, 9:18 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Where is the code you have tried
13th Oct 2018, 3:40 AM
Rishabh
Rishabh - avatar
- 1
#include<stdio.h> int main () { char ope [7]; int i, j, t, z; scanf ("%d",&t); for (i=0; i<=t; i++) { scanf ("%c %c %c",&ope[i],&ope[i],&ope[i]); } for (i=0; i<=t-1; i++) { for (j=i+1; j<=t; j++) { int temp; if (ope[i] > ope[j]) { temp=ope[i]; ope[i]=ope[j]; ope[j]=temp; } } } for (i=1; i<=t; i++) { printf ("Case #%d: %c %c %c\n", i, ope[i], ope[i], ope[i]); } return 0; } this is my code
13th Oct 2018, 4:21 AM
Yoaraci
Yoaraci - avatar