C CODE:
#include <stdio.h>
#include <stdlib.h> //for exit
int main() {
int n,i; //declaring size variable of array as n and iterator as i
printf("Enter size of array: ");
scanf("%d",&n);//input size of array
int arr[n];//making array
while(1){ //for infinite loop till exit
printf("*Press 1 to Enter Data in array \n");
printf("*Press 2 to Print Data of array \n");
printf("*Press 3 to Clear Data of array \n");//for clearing data make all 0
printf("*Press 0 to EXIT \n");
int choice;
scanf("%d",&choice);//inputting choice
switch(choice)
{
case 1:
printf("\nEnter %d values to insert into array:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]); //inputting values in array
}
printf("\n");
break;
case 2:
printf("\nHere are your %d elements of array:\n",n);
for(i=0;i<n;i++)
{
printf("%d ",arr[i]); // outputting array values
}
printf("\n\n");
break;
case 3:
for(i=0;i<n;i++)
{
arr[i]=0; //clearing values of array by putting 0 at every place
}
printf("\nSucessfully cleared data in array:\n\n",n);
break;
case 0:
exit(0); //to exit the program
default:
printf("Invalid Input");}} // to handle case other than 0 1 2
return 0;}
SCREENSHOT OF C CODE:
SCREENSHOT OF RUNNING PROGRAM:
I hope I solved your query in case of doubt feel free to ask in comment section.
Get Answers For Free
Most questions answered within 1 hours.