输入10个字符,按照ascii码表排序并输出:
时间: 2023-05-12 20:05:56 浏览: 175
C# 字符串按 ASCII码 排序的方法
Sure, here's the code to sort 10 characters in ascending order based on their ASCII values:
```
#include <stdio.h>
#include <string.h>
int main() {
char str[11];
int i, j, n;
printf("Enter 10 characters: ");
scanf("%s", str);
n = strlen(str);
for (i = 0; i < n-1; i++) {
for (j = i+1; j < n; j++) {
if (str[i] > str[j]) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
printf("Sorted characters: %s\n", str);
return 0;
}
```
This program takes in 10 characters from the user, sorts them in ascending order based on their ASCII values, and then outputs the sorted characters.
阅读全文