ubuntu@ubuntu:~/yuyu/yu$ gcc 15.c
ubuntu@ubuntu:~/yuyu/yu$ ./a.out
12
1 1 2 3 5 8 13 21 34 55 89 144 233
ubuntu@ubuntu:~/yuyu/yu$ cat 15.c
#include <stdio.h>
int main(int argc, const char *argv[])
{
int num;
scanf("%d",&num);
int fib(int num);
fib(num);
return 0;
}
int fib(int num) //1 1 2 3 5 7 12
{
int i;
int arr[num] ;
arr[0]=1;
arr[1]=1;
for(i=2;i<=num;i++)
{
arr[i]=arr[i-1]+arr[i-2];
}
for(i=0;i<=num;i++)
{
printf("%5d",arr[i]);
}
putchar(10);
return 0;
}
ubuntu@ubuntu:~/yuyu/yu$ gcc 16.c
ubuntu@ubuntu:~/yuyu/yu$ ./a.out
请输入矩阵行数:2
请输入矩阵列数:2
1 3 5 7 91 3
5 7
数组元素的平均值是:4.000000
数组中大于等于平均值的元素和是:12 符合条件的元素个数是:2
ubuntu@ubuntu:~/yuyu/yu$ ./a.out
请输入矩阵行数:3
请输入矩阵列数:4
1 3 5 7 9 1 21 2 3 5 6 8 9 0 8 6 1 2 3 5 6 71 3 5 7
9 1 21 2
3 5 6 8
数组元素的平均值是:5.000000
数组中大于等于平均值的元素和是:61 符合条件的元素个数是:7
ubuntu@ubuntu:~/yuyu/yu$ gcc 16.c
ubuntu@ubuntu:~/yuyu/yu$ cat 16.c
#include <stdio.h>
int main(int argc,const char *argv[])
{
int juzhen();
juzhen();
return 0;
}
int juzhen()
{
int h,l,i,j;
int sum;
float ave;
int add=0;
int count=0;
printf("请输入矩阵行数:");
scanf("%d",&h);
printf("请输入矩阵列数:");
scanf("%d",&l);
int arr[h][l];
for(i=0;i<h;i++)
{
for(j=0;j<l;j++)
{
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<h;i++)
{
putchar(10);
for(j=0;j<l;j++)
{
printf("%3d",arr[i][j]);
}
}
putchar(10);
for(i=0;i<h;i++)
{
for(j=0;j<l;j++)
{
sum = sum+arr[i][j];
}
}
ave=sum/(h*l);
printf("数组元素的平均值是:%f\n",ave);
for(i=0;i<h;i++)
{
for(j=0;j<l;j++)
{
if(arr[i][j]>=ave)
{
add=add+arr[i][j];
count++;
}
}
}
printf("数组中大于等于平均值的元素和是:%d ",add);
printf("符合条件的元素个数是:%d\n",count);
}
ubuntu@ubuntu:~/yuyu/yu$
ubuntu@ubuntu:~/yuyu/yu$ gcc 17.c
ubuntu@ubuntu:~/yuyu/yu$ ./a.out1 2 3
4 5 61 4
2 5
3 6
ubuntu@ubuntu:~/yuyu/yu$
ubuntu@ubuntu:~/yuyu/yu$ cat 17.c
#include <stdio.h>
int main(int argc,const char *argv[])
{
int fanzhuan();
fanzhuan();
return 0;
}
int fanzhuan()
{
int i,j;
int arr[2][3] = {{1,2,3},{4,5,6}};
int brr[3][2];
for(i=0;i<2;i++)
{
putchar(10);
for(j=0;j<3;j++)
{
printf("%3d",arr[i][j]);
}
}
putchar(10);
for(j=0;j<3;j++)
{
putchar(10);
for(i=0;i<2;i++)
{
brr[j][i]=arr[i][j];
printf("%3d",brr[j][i]);
}
}
putchar(10);
return 0;
}
ubuntu@ubuntu:~/yuyu/yu$