标签:print srand time printf std 联系 class ret ble
前三题:
#include<stdlib.h>
#include<time.h>
void bubble(int* px);
void chioce(int* q);
void del(int n, int len, int* py);
int main()
{
int a[10], * p, b[10], * q, * r;
p = a;
q = b;
srand(time);
for (int i = 0; i < 10; i++) {
b[i] = rand() % 100;
a[i] = rand() % 100;
}
for (int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
bubble(p);
for (int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
for (int i = 0; i < 10; i++)
printf("%d ", b[i]);
printf("\n");
chioce(q);
for (int i = 0; i < 10; i++)
printf("%d ", b[i]);
printf("\n");
int n, len;
scanf_s("%d %d", &n, &len);
del(n, len, p);
for (int i = 0; i < 9 - n; i++)
{
printf("%d ", a[i]);
}
printf("\n");
r = delt(q);
for (int i = 0; i < 10; i++)
printf("%d", r[10]);
printf("\n");
return 0;
}
void bubble(int* p)
{
int i, j, k;
for (i = 0; i < 9; i++)
{
for (j = 0; j < 9 - i; j++)
{
if (*(p + j) > * (p + j + 1))
{
k = *(p + j);
*(p + j) = *(p + j + 1);
*(p + j + 1) = k;
}
}
}
}
void chioce(int* q)
{
int i, j, k, t;
for (int i = 0; i < 9; i++)
{
k = i;
for (int j = i + 1; j < 10; j++)
{
if (*(q + k) > * (q + j))
{
t = *(q + k);
*(q + k) = *(q + j);
*(q + j) = t;
}
}
}
}
void del(int n, int len, int* py)
{
int i;
for (i = 0; i < 10 - len; i++)
{
*(py + i + n) = *(py + len + n + i);
}
}
第四题:`#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int *delt(int* pz);
int main()
{
int a[10],*p,b[10],*q,*r;
p = a;
q = b;
srand(time);
for (int i = 0; i < 10; i++) {
b[i] = rand() % 100;
a[i] = rand() % 100;
}
for (int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
for (int i = 0; i < 10; i++)
printf("%d ", b[i]);
printf("\n");
r = delt(p);
printf("\n");
return 0;
}
int* delt(int* pz)
{
int i, j, k,b[10],m,n=0;
int* p1;
p1 = b;
for (i = 0; i < 9; i++)
{
if (pz[i] < pz[i + 1])
j = i + 1;
}
m = *(pz + j);
for (int k = 0; k < 10; k++)
{
if (pz[k] != m)
{
b[n] = *(pz+k);
n += 1;
}
}
for (int i = 0; i < n; i++)
{
printf("%d ", b[i]);
}
return p1;
}
`
第五题:从大到小
`#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void list(int* px, int* py);
int main()
{
int * p,* q;
int a[10] = { 1,15,25,34,44,56,68,71,82,99 };
int b[20] = { 5,22,36,39,45,48,55,59,62,83 };
p = a;
q = b;
for (int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
for (int i = 0; i < 10; i++)
printf("%d ", b[i]);
printf("\n");
list(p, q);
for (int i = 0; i < 20; i++)
{
printf("%d ", b[i]);
}
return 0;
}
void list(int* px, int* py)
{
int i, j, k;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10+i; j++)
{
if (*(px + i) > * (py + j))
{
k = *(px + i);
*(px + i) = *(py + j);
*(py + j) = k;
}
}
}
}
`
标签:print srand time printf std 联系 class ret ble
原文地址:https://www.cnblogs.com/fcz1221/p/14147171.html