寻找最大值//数据不重复
方法1
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int code[10]={1,2,3,4,5,60,7,8,9,6};
int i;
int box,box_1;
box=code[0];
for(i=1;i<10;i++)
{
if(box<code[i])
box=code[i];
}
printf("max=%d",box);
return 0;
}
寻找最大值是数组code[i]几//数据不重复
方法1
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int code[10]={1,2,3,4,5,60,7,8,9,6};
int i;
int box,box_1;
box=code[0];
for(i=1;i<10;i++)
{
if(box<code[i])
box=code[i];
}
for(i=1;i<10;i++)
{
if(box==code[i])
{
box_1=i;
break;
}
}
printf("i=%d",box_1);
return 0;
}
输出最小的那9个。//数据不重复
方法1
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int code[10]={1,2,3,4,5,60,7,8,9,6};
int i;
int box,box_1;
box=code[0];
for(i=1;i<10;i++)
{
if(box<code[i])
box=code[i];
}
for(i=1;i<10;i++)
{
if(box==code[i])
{
box_1=i;
break;
}
}
for(i=1;i<10;i++)
{
if(code[i]==box)
continue;//continue的用法。
printf("%d ",code[i]);
}
// printf("i=%d",box_1);
return 0;
}
从大到小,输出最大的那9个。//数据不重复
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int code[10]={20,3,4,5,60,7,8,9,6,1};
int i;
int box,box_1;
int max,j=0;
box=code[0];
for(j=0;j<9;j++)
{
for(i=0;i<(9-j);i++)
{
if(code[i]<code[i+1])
{
box=code[i+1];
code[i+1]=code[i];
code[i]=box;
}
}
}
for(i=0;i<=9;i++)
{
printf("index%d=%d\n",i,code[i]);
}
return 0;
}