没有考虑输入不是数字的情况下写的代码,可能执行效率没各位的高。但是也是一种方法。直接取出最大的数然后删除就可以了。
程序代码:
[ 本帖最后由 soler 于 2009-8-8 23:17 编辑 ]
程序代码:#include "stdio.h"
#include <string.h>
main()
{
char ch[100];
int n;
printf("pls enter the number:\n");
gets(ch);
printf("pls enter the digit number you wanted to delete:\n");
scanf("%d",&n);
int i,j;
int max,counter;
for(i=0;i<n;i++)
{
max=i;
for(j=0;ch[j]!='\0';j++)
if(ch[max]<ch[j])
max=j;
ch[max]=' ';
}
i=0;
while(1)
{
if(ch[i]>'0'&&ch[i]<='9')
{
counter=i;
break;
}
i++;
}
for(i=counter;ch[i]!='\0';i++)
{
if(ch[i]!=' ')
printf("%c",ch[i]);
}
return 0;
}
[ 本帖最后由 soler 于 2009-8-8 23:17 编辑 ]







