Dowemo
0 0 0 0

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//数组作为函数的参数,传递的是地址(指针),占4个字节
//函数的参数对于数组没有副本机制,数组的拷贝非常浪费内存空间以及CPU
void show(int num[10])
{
 for (int i = 0; i <10; i++)
 {
 printf("%dn", num[i]);
 }
}
void show1(int *p)
{
 for (int i = 0; i <10; i++)
 printf("%dn", p[i]);
}
void show2(int num[3][4])
{
 for (int i = 0; i <12; i++)
 {
 printf("%dn", num[i/4][i % 4]);
 }
}
void show3(int(*p)[4])
{
 for (int i = 0; i <12; i++)
 {
 printf("%dn", p[i/4][i % 4]);
 }
}
void main1()
{
 int num[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 int number[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
//show1(num);
//show2(number);
 show3(number);
 system("pause");
}
//数组的值逆序排列
void change(int number[], int n)
{
 int turn;
 for (int i = 0; i <n/2; i++)
 {
 turn = number[i];
 number[i] = number[n - 1 - i];
 number[n - 1 - i] = turn;
 }
 for (int i = 0; i <n; i++)
 printf("%dn", number[i]);
}
void main2()
{
 int num[11] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
 change(num, 11);
 change(num, 11);
 system("pause");
}
//用指针的方法将数组的值从大到小输出
//冒泡排序
void order(int *p, int n)
{
 int max, turn;
 for (int i = 0; i <n - 1; i++)
 {
 max = i;
 for (int j = i + 1; j <n; j++)
 {
 if (p[j]>p[max])
 {
 max = j;
 }
 }
 if (max!= i)
 {
 turn = p[i];
 p[i] = p[max];
 p[max] = turn;
 }
 printf("%dn", p[i]);
 }
 printf("%dn", p[n - 1]);
}
void order1(int *p, int n)
{
 int turn;
 for (int i = 0; i <n - 1; i++)
 {
 for (int j = i + 1; j <n; j++)
 {
 if (*(p + j)>*(p + i))
 {
 turn = *(p + i);
 *(p + i) = *(p + j);
 *(p + j) = turn;
 }
 }
 printf("%dn", *(p + i));
 }
 printf("%dn", *(p + n - 1));
}
void main3()
{
 time_t ts;
 srand((unsigned int)time(&ts));
 int num[10];
 for (int i = 0; i <10; i++)
 {
 num[i] = rand() % 100;
 printf("%dn", num[i]);
 }
 printf("------------------------------n");
 order1(num, 10);
 system("pause");
}
//有一个班,3个学生,各学4门课,计算总平均成绩以及第n个学生的成绩
void avr(int(*p)[4], int n)//指向一维数组的指针
{
 int res = 0;
 for (int i = 0; i <n; i++)
 {
 for (int j = 0; j <4; j++)
 {
 res += p[i][j];
 }
 }
 printf("average score is %dn", res/= 12);
}
void showstuscore(int num, int(*p)[4])
{
 for (int i = 0; i <4; i++)
 {
 printf("%dn", *(*(p + num - 1) + i));
 }
}
//只要有一门成绩不及格,则输出其所有科目的成绩
void 抓不及格(int num, int(*p)[4])
{
 for (int i = 0; i <num; i++)
 {
 for (int j = 0; j <4; j++)
 {
 if (*(*(p + i) + j) <60)
 {
 printf("第%d位同学的所有成绩n", i + 1);
 showstuscore(i + 1, p);
 break;
 }
 }
 }
}
void main()
{
 int score[3][4] = { { 45, 68, 97, 68 }, { 49, 67, 65, 99 }, { 100, 59, 98, 86 } };
//avr(score, 3);
//int num;
//puts("查看第几位学生的所有成绩?n");
//scanf_s("%d", &num);
//showstuscore(num, score);
 抓不及格(3, score);
 system("pause");
}




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs