Lab Programs

Creating a array

1. Design, Develop and Implement a menu driven Program in C for the following Array Operations a. Creating an Array of N Integer Elements b. Display of Array Elements with Suitable Headings c. Exit. Support the program with functions for each of the above operations.

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

int array[10], n;

void create()
{
	int i;
	printf("Enter the size of array: ");
	scanf("%d", &n);
	printf("\n\nEnter the elements of array: ");
	for(i=0; i<n; i++)
		scanf("%d", &array[i]);
}


void display()
{
	int i;
	printf("\n\nThe array elements are: ");
	for(i=0; i<n; i++)
	printf("%d\t", array[i]);
}

int main()
{
	int ch;
	while(1)
	{
		printf("\n\n______MENU_____\n");
		printf("1.Create\n");
		printf("2.Display\n");
		printf("3.Exit\n");
		printf("Enter Your Choice:");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
				create();
				break;
			case 2:
				display();
				break;
			case 3:
				exit(0);
			default:
				printf("INVALID CHOICE\n");
		}
	}
	return 0;

}
______MENU_____
1.Create
2.Display
3.Exit
Enter Your Choice:1
Enter the size of array: 5

Enter the elements of array: 1 2 3 4 5

______MENU_____
1.Create
2.Display
3.Exit
Enter Your Choice:2

The array elements are: 1 2 3 4 5
______MENU_____
1.Create
2.Display
3.Exit
Enter Your Choice:3

--------------------------------
Process exited after 18.12 seconds with return value 0
Press any key to continue . . .