----------------解决方案--------------------------------------------------------
//任意输入数,将其中最大的数打出来 #include <stdlib.h> #include <conio.h>
void main() { int numsize; int *ip;
int counter; int tempcounter; int temp; cprintf("please enter the numsize:\t"); cscanf("%d",&numsize); ip = (int *)malloc(numsize*sizeof(int)); if(!ip) exit(1); for(counter=0;counter<numsize;counter++,ip++) { cprintf("\nplease enter the %dth number:\t",counter+1); cscanf("%d",ip); } ip-=numsize; //冒泡排序 for(counter=0;counter<numsize;counter++) { for(tempcounter=0;tempcounter<numsize-counter-1;tempcounter++) { if(*(ip+tempcounter)>*(ip+tempcounter+1)) { temp=*(ip+tempcounter); *(ip+tempcounter)=*(ip+tempcounter+1); *(ip+tempcounter+1)=temp; } } } cprintf("the maxnum is:\t"); cprintf("%5d",*(ip+numsize-1)); free(ip); cprintf("\n"); cprintf("END\n"); }
----------------解决方案--------------------------------------------------------
#include<stdio.h>
main()
{ long int a[100],i=0,max;
printf("请输入整数(9999为结束标记):\n");
do{
scanf("%d",&a[i]);
i++;
}while(a[i-1]!=9999);
i=1;
max=a[0];
while(a[i]!=9999)
{
if(a[i]>max)
max=a[i];
i++;
}
printf("max=%d\n",max);
}
坚强依然!永不言苦!永不言败!睇透数据结构!编程编程再编程!-----激情依旧
----------------解决方案--------------------------------------------------------
2楼用的是“动态数组”
----------------解决方案--------------------------------------------------------
那么还有一题,任意输入数,将它们从大到小输出
----------------解决方案--------------------------------------------------------
1楼都排序了
想从小到大就从小到大输出
想从大到小就从大到小输出
----------------解决方案--------------------------------------------------------