Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Use c language to define an integer array with up to N elements.
Use c language to define an integer array with up to N elements.

#include?

#include?

#include?

< p>#define?N?50

int?a[N];

int?count=0;

void?append()

{

printf("\n\nPlease enter the increased value:?");

int?n;

scanf(" %d",&n);

if(count+1

{

a[count++]=n;

printf("\nAdded successfully");

getch();

return;?

}

else

else

p>

{

printf("\nThe number of arrays has reached the maximum");

getch();

return;

}

}

void?del()

{

int?n;

printf("\n\nPlease enter the value to be deleted:?");

scanf("%d",&n);

int?i,j=0 ;

for(i=0;i

{

if(a[i]==n)

< p> {

for(j=i;j

{

a[j]=a[j+1] ;

}

count--;

printf("\nDelete successfully");

getch();

p>

return;

break;

}

}

printf("\nThe value to be deleted was not found ");

getch();

return;

}

void?sort()

{

int?i,j,n;

for(i=0;i

{

< p> for(j=0;j

{

if(a[j]>a[j+1])

{

n=a[j];

a[j]=a[j+1];

a[j+1 ]=n;

}

}

}

printf("\n\nSorting successful");

getch();

}

void?find()

{

int?i,n;< /p>

printf("\n\nPlease enter the value you are looking for:?");

scanf("%d",&n);

for( i=0;i

{

if(a[i]==n)

{

printf("\n\nFound,? The subscript is: %d",i);

getch();

return;

}< /p>

}

printf("\n\nNot found");

getch();

}

< p>void?display()

{

printf("\n\n");

int?i;

for(i=0;i

{

printf("%2d?",a[i]);

}< /p>

printf("\n\n***There are %d elements",count);

getch();

return;

}

void?menu()

{

int?sel;

while(1)

{

system("cls");

printf("1---------increase\n");?

< p> printf("2---------Delete\n");

printf("3---------Sort\n");

printf("4---------Search\n");

printf("5---------Display\n");< /p>

printf("6---------Exit\n");

printf("\n\nPlease select (1--6):?" );

scanf("%d",&sel);

if(sel<0?||?sel>6)

{

continue;

}

switch(sel)

{

case?1:

append();

break;

case?2:

del();

break;

< p> case?3:

sort();

break;

case?4:

find();

p>

break;

case?5:

display();

break;

case?6:< /p>

return;

}

}

}

int?main()

{

srand((unsigned)time(0));

int?i;

printf("Define how many elements the array has (not Greater than 50):?");

scanf("%d",&count);

for(i=0;i

{

a[i]=rand()%99+1;

}

menu();

return? 0;

}