求解几道问题
1.编写自定义函数,实现n阶矩阵的转置。2.某数理化三项竞赛训练组有3个人,找出其中至少有一项成绩不合格者。要求使用指针函数实现。
3.编写自定义函数判定,从键盘输入的某一年份是否为闰年,并将1000~2000之间的所有闰年输出。
程序代码:
#include <stdio.h>
int main (void) {
int i,j,x,y;
void rotate (int x,int y,int a[x][y]);
//Input numbers of array
scanf("%i%i",&x,&y);
//declare array
int a[x][y];
//input element
for(i=0;i<x;i++) {
for(j=0;j<y;j++) {
scanf("%i",&a[i][j]);
}
}
//display
printf("Before:\n");
for(i=0;i<x;i++) {
for(j=0;j<y;j++) {
printf("%i ",a[i][j]);
}
printf("\n");
}
//rotate
rotate(x,y,a);
//display
printf("After:\n");
for(i=0;i<y;i++) {
for(j=0;j<x;j++) {
printf("%i ",a[i][j]);
}
printf("\n");
}
return 0;
}
//function
void rotate (int x,int y,int a[x][y]) {
int i,j,temp;
for(i=0;i<x;i++) {
for(j=i+1;j<y;j++) {
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
}
程序代码:
#include <stdio.h>
int main (void) {
int year,i,j;
int leapyear(int n);
printf("Enter year:");
scanf("%i",&year);
if(leapyear(year)==1)
printf("yes\n");
else
printf("no\n");
//
for(i=1000;i<2001;i++) {
if(leapyear(i)==1)
printf("%i\n",i);
}
return 0;
}
int leapyear(int n) {
if(n%4==0&&n%100!=0||n%400==0)
return 1;
}

程序代码:#include <stdio.h>
struct Node
{
float math;
float phy;
float che;
};
bool fun(Node *p)
{
int i = 0;
if(p->che <= 60 || p->math <= 60 || p->phy <= 60)
return false;
return true;
}
int main()
{
Node a[3] = {0};
int i,j,k;
for(i = 0;i<3;i++)
{
scanf("%f %f %f",&a[i].math,&a[i].phy,&a[i].che);
if(!fun(&a[i]))
printf("%0.1f %0.1f %0.1f\n",a[i].math,a[i].phy,a[i].che);
}
return 0;
}
