- 从0到1,回归基础,夯实基础 ,点滴积累,成就未来
#include <stdio.h>
#include <stdlib.h>
int main1()
{
void fun(int x, int y, int(*p)(int, int));
int max2(int , int );
int min2(int , int );
int add2(int, int);
int a = 21, b = -9, n;
printf("choose 1,2 or 3:\n");
scanf_s("%d", &n);
if (n == 1)
fun(a, b, max2);
else if (n == 2)
fun(a, b, min2);
else if (n == 3)
fun(a, b, add2);
}
void fun(int x, int y, int(*p)(int, int))
{
int result;
result = (*p)(x, y);
printf("%d\n", result);
}
int max2(int x, int y)
{
return x > y ? x : y;
}
int min2(int x, int y)
{
return x < y ? x : y;
}
int add2(int x, int y)
{
return (x + y);
}
int main2()
{
float score[][4] = { { 60, 70, 80, 90 }, { 56, 89, 67, 88 }, { 34, 78, 90, 66 } };
float *search(float(* pointer)[4], int n);
float *p;
int i, k;
printf("enter the number of stdudent:\n");
scanf_s("%d", &k);
p = search(score, k);
for (i = 0; i < 4; i++)
printf("%5.2f\t", *(p + i));
printf("\n");
}
float *search(float(*pointer)[4], int n)
{
float *pt;
pt = *(pointer + n);
return pt;
}
int main3()
{
float score[][4] = { { 60, 70, 80, 90 }, { 56, 89, 67, 88 }, { 34, 78, 90, 66 } };
float *search_score(float(*pointer)[4]);
float *p;
int i, j;
for (int i = 0; i < 3; i++)
{
p = search_score(score + i);
if (p == *(score+i))
{
printf("No.%d socre;", i);
for (int j = 0; j < 4; j++)
{
printf("%5.2f ", *(p + j));
}
printf("\n");
}
}
}
float *search_score(float(*pointer)[4])
{
int i = 0;
float *pt;
pt = NULL;
for (; i < 4; i++)
if (*(*pointer + i) < 60)
pt = *pointer;
return pt;
}
int main4()
{
void sort(char *name[], int n);
void print(char *name[], int n);
char *name[] = { "Follow me", "BASIC", "Great Wall", "FORTRAN", "Computer design" };
int n = 5;
sort(name, n);
print(name, n);
system("pause");
return 0;
}
void sort(char *name[], int n)
{
char *temp ;
temp = name[0];
int i, j, k;
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i+1; j < n; j++)
if (strcmp(name[k], name[j])>0)
k = j;
if (k != i)
{
temp = name[i];
name[i] = name[k];
name[k] = temp;
}
}
}
void print(char *name[], int n)
{
int i=0;
char *p = name[0];
while (i<n)
{
p = *(name + i++);
printf("%s\n", p);
}
}
int main5()
{
char *name[] = { "Follow me", "BASIC", "Great Wall", "FORTRAN", "Computer design" };
char **p;
int i;
for (int i = 0; i < 5; i++)
{
p = name + i;
printf("%s\n", *p);
}
}
int main()
{
void checkp(int *p);
int *p1, i;
p1 = (int *)malloc(5 * sizeof(int));
for (i = 0; i < 5; i++)
scanf_s("%d", p1 + i);
checkp(p1);
free(p1);
system("pause");
return 0;
}
void checkp(int *p)
{
int i;
for (i = 0; i < 5; i++)
if (*(p+i) < 60)
printf("%d ", *(p+i));
printf("\n");
}