程序设计题
【题一】
#include<stdio.h>
#define N 80
void fun(int *w,int p,int n)
{
int x, j, ch;
for (x = 0; x <= p; x++)
{
ch = w[0];
for (j = 1; j < n; j++)
{
w[j - 1] = w[j];
}
w[n - 1] = ch;
}
}
int main()
{
int a[N] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
int i, p, n = 15;
printf("The oriqinal data:\n");
for (i = 0; i < n; i++)
{
printf("%3d", a[i]);
}
printf("\n\nEnter p:");
scanf("%d", &p);
fun(a, p, n);
printf("\nThe data after moving:\n");
for (i = 0; i < n; i++)
{
printf("%3d", a[i]);
}
printf("\n\n");
}
【题二】
void fun(char* a)
{
while (*a != '\0')
{
a++;
}
a--;
while (*a == '*')
{
a--;
}
*(a + 1) = '\0';
}
【题三】
void fun(int m,int k,int xx[])
{
int i, j, n;
for (i = m + 1, n = 0; n < k; i++)
{
for (j = 2; j < i; j++)//判断i是否是素数
{
if (i%j == 0)break;//不是跳出判断,判断下一个数
}
if (j >= i)//若是素数,存入xx[]数组中
{
xx[n++] = i;
}
}
}