第八次作业
1、输入正整数n,在输入n个整数,冲大到小输出
#include"stdio.h"![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609155808386-696213338.jpg)
int main(void)
{
int i,j,t,x;
int n,a[10];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
x=i;
for(j=x+1;j<n;j++)
if(a[x]<a[j])
x=j;
t=a[i];
a[i]=a[x];
a[x]=t;
printf("%d\t",a[i]);}
return 0;
![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609155808386-696213338.jpg)
int main(void)
{
int i,j,t,x;
int n,a[10];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++){
x=i;
for(j=x+1;j<n;j++)
if(a[x]<a[j])
x=j;
t=a[i];
a[i]=a[x];
a[x]=t;
printf("%d\t",a[i]);}
return 0;
2、输入正整数n,在输入n个数字,分析,输出出现次数最多的数
#include"stdio.h"![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160236990-1636954322.png)
int main(void)
{
int i,x,t,z;
int n,a[10];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<=9;i++)
a[i]=0;
for(i=1;i<n;i++)
scanf("%d",&x);
while(x!=0){
i=x%10;
x=x/10;
if(i>=0&&i<=9)
a[i]++;
else
printf("no");}
printf("\n");
printf("%d\n",a[i]);
return 0;
}
![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160236990-1636954322.png)
int main(void)
{
int i,x,t,z;
int n,a[10];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<=9;i++)
a[i]=0;
for(i=1;i<n;i++)
scanf("%d",&x);
while(x!=0){
i=x%10;
x=x/10;
if(i>=0&&i<=9)
a[i]++;
else
printf("no");}
printf("\n");
printf("%d\n",a[i]);
return 0;
}
3、判断是否是三角矩阵
#include"stdio.h"
int main(void)
{
int i,j,sign=0;
int n,a[6][6];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i>j&&a[i][j]==0)
sign=1;}
}
if(sign==1)
printf("Yes");
else
printf("NO");
return 0;
}![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160603171-383326518.png)
![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160608700-2006844775.jpg)
int main(void)
{
int i,j,sign=0;
int n,a[6][6];
printf("Enter n:");
scanf("%d",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&a[i][j]);}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i>j&&a[i][j]==0)
sign=1;}
}
if(sign==1)
printf("Yes");
else
printf("NO");
return 0;
}
![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160603171-383326518.png)
![](https://img2018.cnblogs.com/blog/1619595/201906/1619595-20190609160608700-2006844775.jpg)