當前位置:首頁 » 編程語言 » c語言上三角矩陣

c語言上三角矩陣

發布時間: 2025-01-31 05:02:30

『壹』 c語言編程 上三角矩陣

#include "stdio.h"
#include "math.h"
int main( )
{
int a[6][6],flag,i,j,n;
scanf("%d",&n);
for (i=0;i<n;i++)
for (j=0;j<n;j++)
scanf("%d",&a[i][j]);
flag=0;
for(i=1;i<n;i++)
for(j=0;j<i;j++)
if(a[i][j]==0) flag++;
if(flag==n*(n-1)/2) printf("YES\n");
else printf("NO\n");
}
}

『貳』 c語言 任意輸入一個3×3的矩陣,用函數實現求上三角矩陣並輸出。

第一題#include <stdio.h>
void shangsan(int (*p)[3])
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==1&&j==0)
printf("%c",32);
else if(i==2&&(j==0||j==1))
printf("%c",32);
else
printf("%d",(*(p+i))[j]); }
printf("\n");
} }
void main()
{ int s[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
scanf("%d",&s[i][j]);
shangsan(s);}第二題#include <stdio.h>
int mystrcmp(char *p1,char *p2)
{ for(int i=0;i<15;i++,p1++,p2++)
{ if(*p1!=*p2)
return *p1-*p2;
}
return 0;
}
void main()
{
int M;
char s1[15],s2[15];
gets(s1);
gets(s2);
M=mystrcmp(s1,s2);
if(M==0)
printf("字元串相等!");
else
printf("字元串不相等!差值是:%d",M); }第三題#include <stdio.h>
float HH(float score[])
{ float Max=0,Min=32767,sum=0;
for(int i=0;i<10;i++)
{
sum+=score[i];
if(score[i]>Max)
Max=score[i];
else if(Min>score[i])
Min=score[i];
}
score[0]=Max;
score[1]=Min;
return sum/10;}
void main()
{ float shuzu[10];
for(int i=0;i<10;i++)
scanf("%f",&shuzu[i]);
printf("平均分是:%f\n最高分數是:%f\n最低分數是:%f\n",HH(shuzu),shuzu[0],shuzu[1]);
}

熱點內容
app什麼情況下找不到伺服器 發布:2025-05-12 15:46:25 瀏覽:714
php跳過if 發布:2025-05-12 15:34:29 瀏覽:467
不定時演算法 發布:2025-05-12 15:30:16 瀏覽:131
c語言延時1ms程序 發布:2025-05-12 15:01:30 瀏覽:166
動物園靈長類動物配置什麼植物 發布:2025-05-12 14:49:59 瀏覽:736
wifi密碼設置什麼好 發布:2025-05-12 14:49:17 瀏覽:148
三位數乘兩位數速演算法 發布:2025-05-12 13:05:48 瀏覽:397
暴風影音緩存在哪裡 發布:2025-05-12 12:42:03 瀏覽:542
access資料庫exe 發布:2025-05-12 12:39:04 瀏覽:630
五開的配置是什麼 發布:2025-05-12 12:36:37 瀏覽:365