57 (Use the structure pointer to find out the information of the student with the highest score in the structure)

57 date: 2021.3.14
Insert picture description here
Key points:
IsPrime () Judgment prime number

The detailed code is as follows:

#include  <conio.h>
#include  <stdio.h>
/*************found**************/
int IsPrime(int n)
{
    
     
  int i,m;
  m=1;
  for(i=2;i<n;i++)
 /*************found**************/
     	if(!(n%i))
	{
    
    
		m=0;
		break;
	}

  return(m);
}
void main()
{
    
     
  int j,k;
  printf("\nPlease enter an interger number between 2 and 10000: ");
  scanf("%d",&k);
  printf("\nThe prime factor(s) of %d is(are): ",k);
  for(j=2;j<k;j++)
 	if((!(k%j)) && (IsPrime(j)))
		printf("%4d,",j);
  printf("\n");
}

Insert picture description hereKey point:
the usage scenarios of the pointing operator member operator are different

The detailed code is as follows:

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define N 10
typedef struct ss    /*定义结构体*/
{
    
     char num[10]; 
  int s;
} STU;
void fun(STU a[], STU *s)
{
    
    
  /*
	analyse:

	找出成绩最高的学生记录->通过形参返回主函数(只有一个最高分)

  */


	//指向运算符  成员运算符  题中"s -> s"等价于 (*s).s

	int i;

	*s = a[0];

	for(i = 0; i<N; i++)
	{
    
    
		if(s->s < a[i].s)
			*s =a[i];
	}

	/* ERROR:
	int i,j = 0,max = a[0].s;

	for(i = 0; i< N; i++)
	{
		if(a[i].s >= max)
			max = a[i].s;
	}
	*s = a[i];
	*/

}
void main()
{
    
     
  FILE *wf;
  STU a[N]={
    
    {
    
     "A01",81},{
    
     "A02",89},{
    
     "A03",66},{
    
     "A04",87},{
    
     "A05",77},
  {
    
     "A06",90},{
    
     "A07",79},{
    
     "A08",61},{
    
     "A09",80},{
    
     "A10",71}},m;
  int i;
  system("CLS");
  printf("*****The original data*****");
  for(i=0;i<N;i++) 
     printf("No=%s Mark=%d\n", a[i].num,a[i].s);
  fun(a,&m);
  printf("*****THE RESULT*****\n");
  printf("The top :%s, %d\n",m.num,m.s);
/******************************/
  wf=fopen("out.dat","w");
  fprintf(wf,"%s,%d",m.num,m.s);
  fclose(wf);
/*****************************/
}

Guess you like

Origin blog.csdn.net/weixin_44856544/article/details/114778943