0% found this document useful (0 votes)
7 views5 pages

61 Assignment4

The document outlines a menu-driven C program that performs various operations on an array, including reading and printing the array, calculating the sum of its elements, finding the minimum and maximum values, and searching for a specific element. It includes code snippets for each menu option, demonstrating how to implement these functionalities. The program is designed for a class assignment in Problem Solving and Programming.

Uploaded by

heramb.sharma24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

61 Assignment4

The document outlines a menu-driven C program that performs various operations on an array, including reading and printing the array, calculating the sum of its elements, finding the minimum and maximum values, and searching for a specific element. It includes code snippets for each menu option, demonstrating how to implement these functionalities. The program is designed for a class assignment in Problem Solving and Programming.

Uploaded by

heramb.sharma24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name-Heramb Sharma

Roll No-61
PRN-12414170
Class/div-EntcB
Batch-3
Subject-Problem Solving and Programming

4. Write a Menu Driven Program to perform the following operations on the array:
a. Read and print array
b. Print Addition of Array Elements
c. Find minimum and maximum number from array
d. Search an element from the array and print its location

Code-

#include <stdio.h>
int main()
{

int choice;
printf("menu:\n");
printf("1)Read and print array\n2)Print addition of array elements\n3)Find minimum and
maximum number from array\n4)Search an element from the array and print its location\
n5)Exit\n");
printf("Enter your choice\n");
scanf("%d", &choice);
switch (choice)
{
case 1:
int main();
{
int arr[10], i, size;
printf("Enter size: ");
scanf("%d", &size);
for (i = 0; i < size; i++)
{
printf("Enter the elements %d:", i);
scanf("%d", &arr[i]);
}
printf("Entered elements are:");
for (i = 0; i < size; i++)
{
printf("%d", arr[i]);
}
printf("\n");
return 0;
}

break;
case 2:

int main();
{
int arr[10], i, size, sum = 0;
printf("Enter size: ");
scanf("%d", &size);
for (i = 0; i < size; i++)
{
printf("Enter the elements %d:", i);
scanf("%d", &arr[i]);
}
printf("Sum of entered elements is:");
for (i = 0; i < size; i++)
{
sum = sum + arr[i];
}
printf("%d", sum);
printf("\n");
return 0;
}
break;
case 3:
int main();
{
int arr[10], i, size, min, max;
printf("Enter size: ");
scanf("%d", &size);

// Input validation (optional but good practice)


if (size < 1 || size > 10) {
printf("Invalid size. Enter a number between 1 and 10.\n");
return 1;
}

for (i = 0; i < size; i++) {


printf("Enter the element %d: ", i);
scanf("%d", &arr[i]);
}

min = arr[0];
max = arr[0]; // Fixed: initialize max

for (i = 1; i < size; i++) {


if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
}

printf("%d is minimum\n", min);


printf("%d is maximum\n", max);

return 0;
}

break;

case 4:
int main();
{
int rry[10], j, siz, tosearch, found;
printf("Enter size: ");
scanf("%d", &siz);
for (j = 0; j < siz; j++)
{
printf("Enter the elements %d:", j);
scanf("%d", &rry[j]);
}
printf("Entered elements are:");
for (j = 0; j < siz; j++)
{
printf("%d,", rry[j]);
}

printf("\n");
printf("Search the element\n");
scanf("%d", &tosearch);
found = 0;

for (j = 0; j < siz; j++)


{
if (rry[j] == tosearch)
{
found = 1;
break;
}
}
if (found == 1)
{
printf("Element %d found at %d position\n", tosearch, j + 1);
}
else
{
printf("Element %d not found in the array\n", tosearch);
}

return 0;
}
break;
case 5:
int main();
{
printf("Exiting");
}
break;
}
return 0;
}

Output-

You might also like