C language-create a dynamic array, enter the five student scores, use the function to check the failure, and output

Code area

#include<stdio.h>
#include<stdlib.h>   //因为用到了malloc
void check(int *p)
{
 int i;
 printf("they are fails\n");
 for(i=0;i<5;i++)
 {
  if(p[i]<60)
  printf("%dth :%d  \n",i+1,p[i]);
 }
}
main()
{
  int *p1,i;  //p1是int型指针
  p1=(int *)malloc(5*sizeof(int)); //开辟动态区域,将地址转化为int *,然后放在p1中
  printf("input the scores in order\n");
  for(i=0;i<5;i++)
  {
   scanf("%d",p1+i);
  
  }
  check(p1);
}
Published 57 original articles · Liked 54 · Visits 2363

Guess you like

Origin blog.csdn.net/September_C/article/details/104930602