高级语言程序设计第六次作业

这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/2024C/

这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/2024C/homework/13303

学号:092300125

姓名:张天荣

#include<stdio.h>

int P(int num){
    int i;
    
    for(i=2;i<=num/2;i++){
        if(num%i==0)
            return 0;
    }
    return 1;
}

void fun(int m, int *k, int xx[]){
    int i;
    *k=0;
    for(i=0;i<m;i++){
        if(P(i))
            xx[(*k)++]=i;
    }

}

int main(void){

    int xx[20];
    int k=0;
    fun(10,&k,xx);
    
    return 0;

}
#include<stdio.h>
#include<string.h>

void C(int n,int m,char* ch1,char* ch2) {
	int i = 0,j=0;
	for (i = m - 1; i < n; i++)
		ch2[j++] = ch1[i];

	ch2[j] = '\0';

}

int main(void) {

	char ch1[20] = "ssvsb";
	char ch2[20];

	C(strlen(ch1),3,ch1,ch2);
	printf("%s",ch2);

	return 0;

}


3.

#include<stdio.h>

void C(int* arr,int n) {

	int i = 0, j = 0;
	int a;
	for (i = 0; i < n; i++) {
		for (j = 1; j < n - i; j++) {
			if (arr[j] < arr[j - 1]) {
				a = arr[j];
				arr[j] = arr[j - 1];
				arr[j - 1] = a;
			}
		}
	}
}

int main(void) {

	int arr[5] = {1,6,5,4,8};
	int n = sizeof(arr) / sizeof(arr[0]);

	C(arr, n);

	for (int i = 0; i < n; i++)
		printf("%d ",arr[i]);

	return 0;

}


4.

#include<stdio.h>
#include<stdlib.h>

void C(int** arr) {

	int n = 0,i=0;
	
	while ((scanf("%d", &n)) == 1) {
		*arr = (int*)realloc(*arr,sizeof(int)*(i+1));
		(*arr)[i++] = n;
	}
	
	for (i = i - 1; i >= 0; i--)
		printf("%d ", (*arr)[i]);
	
	
}

int main(void) {

	int* arr=NULL;
	
	C(&arr);
	
	return 0;

}


5.

#include<stdio.h>

void C(int* arr,int n) {

	int i=0;
	
	for (i = 0; i < n; i++)
		printf("%d ", arr[i]);
	
	
}

int main(void) {

	int arr[5] = {1,2,3,4,5};
	
	C(arr,5);
	
	return 0;

}

#include<stdio.h>

void C(int n, int m, int arr[n][m], int *max, int *maxrow, int *maxcol, int *min, int *minrow, int *mincol) {  
    *max = arr[0][0];  
    *min = arr[0][0];  
    *maxrow = 0;  
    *maxcol = 0;  
    *minrow = 0;  
    *mincol = 0;  

    for (int i = 0; i < n; i++) {  
        for (int j = 0; j < m; j++) {  
            if (arr[i][j] > *max) {  
                *max = arr[i][j];  
                *maxrow = i;  
                *maxcol = j;  
            }  
            if (arr[i][j] < *min) {  
                *min = arr[i][j];  
                *minrow = i;  
                *mincol = j;  
            }  
        }  
    }  
}  

int main(void) {

	int arr1[3][2]={1,2,3,4,5,6};
	int arr2[3][2]={7,8,9,10,11,12};
	
	int a,b,c,d,e,f;
	C(3,2,arr1,&a,&b,&c,&d,&e,&f);
	printf("%d %d %d %d %d %d\n",a,b,c,d,e,f);
	C(3,2,arr2,&a,&b,&c,&d,&e,&f);
	printf("%d %d %d %d %d %d\n",a,b,c,d,e,f);

	return 0;

}


7.

#include<stdio.h>

int C(int n,int arr[n][n]) {
	int i, j;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(arr[i][j]!=0)
                return 0;
        }
    }
    return 1;
}

int main(void) {

	int arr1[3][3] = { 1,6,0,4,8,0,3,0,6 };
	int arr2[3][3] = { 1,0,0,5,5,0,6,0,0 };
	if(C(3,arr1))
        printf("1\n");
    else
        printf("2\n");
	if(C(3,arr2))
        printf("3\n");
    else
        printf("4\n");

	return 0;

}
int C(int n,int m,int arr[n][m],int value) {
	int i, j;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(arr[i][j]==value)
                return 1;
        }
    }
    return 0;
}
#include<stdio.h>

int P(int value) {
	
	if (value <= 1)
		return 0;
	
	int i;
	for (i = 2; i * i <= value; i++) {
		if (value % i == 0)
			return 0;
	}
	return 1;
}

int C(int value,int* a,int* b) {
	
	if (value <= 3)
		return 0;
	int i = 2;
	
	for (i = 2; i  < value; i++) {

		if (P(i) && P(value - i)) {
			*a = i;
			*b = value - i;
			return 1;
		}
	}
	return 0;
}

int main(void) {

	int n,a=0,b=0;
	scanf("%d",&n);

	if (C(n, &a, &b)) 
		printf("%d=%d+%d\n", n, a, b);
	else
		printf("%d.\n",n);
	return 0;

}


10.

#include<stdio.h>
#include<string.h>

void shift(char* s, int n) {

	int l=strlen(s);
	char ch[l+1];
    int i=0;

    for(i=0;i<l;i++){
        if(i-n>=0)
            ch[i-n]=s[i];
        else
            ch[l+i-n]=s[i];
    }
    ch[l]='\0';
    strcpy(s,ch);

}

int main(void) {

	char ch[6]="hello";
	
    shift(ch,3);
	printf("%s",ch);
	return 0;

}
#include<stdio.h>
#include<string.h>

int C(int n,int arr[n][n]) {

    int sum1=0,sum2=0;
    int i,j;

    for(i=0;i<n;i++)
        sum1+=arr[0][n];

    for(i=1;i<n;i++){
        sum2=0;
        for(j=0;j<n;j++)
            sum2+=arr[i][j];
        if(sum1!=sum2)
            return 0;
    }
    for(i=0;i<n;i++){
        sum2=0;
        for(j=0;j<n;j++)
            sum2+=arr[j][i];
        if(sum1!=sum2)
            return 0;
    }
    sum2=0;
    for(i=0;i<n;i++){
        sum2+=arr[i][i];
    }
    if(sum1!=sum2)
        return 0;
    sum2=0;
    for(i=0;i<n;i++){
        sum2+=arr[i][n-1-i];
    }
    if(sum1!=sum2)
        return 0;
    
    return 1;

}

int main(void) {

    int n;
    scanf("%d",&n);
    int arr[n][n];
    int i,j;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++)
            scanf("%d",&arr[i][j]);
    }

    if(C(n,arr))
        printf("Yes\n");
	else
        printf("No\n");

	return 0;

}


12.

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int C(char* ch1,char* ch2) {
    int l1=strlen(ch1);
    int l2=strlen(ch2);
    
    if(l1!=l2)
        return 0;
    int i;
    for(i=0;i<l1;i++){
        if(tolower(ch1[i])==tolower(ch2[i]))
            ;
        else
            return 0;
    }
    return 1;
}

int main(void) {

    char ch1[6]="AasGR";
    char ch2[6]="aAsgr";

    if(C(ch1,ch2))
        printf("Yes");
    else
        printf("No");
  

}

posted @ 2024-11-07 23:31  hfdc  阅读(15)  评论(0编辑  收藏  举报