img
Question:
Published on: 3 December, 2024

Write a C program to manage array operation using switch case.

Answer:
#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
	int a[100]={12,45,41,96,32},i,j,m,n,p;
	clrscr();

	printf("\n\n\t***  Proceed according to the instruction  ***");
	printf("\n\n\t\n\tFor Doing----\n\t\t\tINSERTION  press-->> 1\n\t\t\tDELITION  press-->> 2\n\t\t\tMODIFICATION  press-->> 3\n\t\t\tEXIT  press-->> 4\n");
	printf("\n\n\tEnter Ur choice :  ");
	scanf("%d",&i);
	switch(i)

	{

		case 1:
		{
			clrscr();
			printf("\n\n\t\t\t\t***INSARTING***\n\n");
			printf("\tThe present data in array.....");
			for(j=0;j<m;j++)
			{
				if(a[j]==NULL)
					break;
				printf("%d  ",a[j]);
			}
			printf("\n\tenter the number which you want to insert---->> ");
			scanf("%d",&n);
			printf("\n\t\tEnter the position ");
			scanf("%d",&p);
			for(j=m;j>=p;j--)
			{
				a[j]=a[j-1];
			}
			a[p]=n;
			printf("\n\n\n\t\tThe present data in array......\n\n\t\t\t ");
			for(j=0;j<=m;j++)
			{
				if(a[j]==NULL)
					break;
				else
					printf("%d ",a[j]);
			 }

			getch();
			break;
		}
		case 2:
		{
			clrscr();
			printf("\n\n\t\t\t\t***DELETING***\n\n");
			printf("\tThe present data in array.....");
			for(j=0;j<m;j++)
			{
				if(a[j]==NULL)
					break;
				printf("%d ",a[j]);
			}
			printf("\n\tenter the number which you want to delete---->>");
			scanf("%d",&n);
			for(j=0;j<m;j++)
			{
				if(a[j]==n)
				{
					for(j=j;j<m;j++)
					{
						a[j]=a[j+1];
					}
				}

			}
			printf("\n\n\n\t\tThe present data in array......\n\n\t\t\t ");
			for(j=0;j<m;j++)
			{
				if(a[j]==NULL)
					break;
				else
					printf("%d ",a[j]);
			 }
			 getch();
			 break;
		}
		case 3:
		{
			clrscr();
			printf("\n\n\t\t\t\t***MODIFYING***\n\n");
			printf("\tThe present data in array.....");
			for(j=0;j<m;j++)
			{
				if(a[j]==NULL)
					break;
				printf("%d ",a[j]);
			}
			printf("\n\tenter the number which you want to modify---->>");
			scanf("%d",&n);
			for(j=0;j<m;j++)
			{
				if(a[j]==n)
				{
					printf("\n\tenter your currect number.....");
					scanf("%d",&a[j]);
					break;
				}
			}
			printf("\n\n\n\t\tThe present data in array......\n\n\t\t\t ");
			for(j=0;j<m;j++)
			{
				if(a[j]==NULL)
					break;
				else
					printf("%d ",a[j]);
			 }


			getch();
			break;
		}
		case 4:
		{
			exit();
			break;
		}
	}
	main();
}
Random questions