Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <stdio.

h>
#define size 7
int main(void)
{
int list[size] = { 0 }, i, sum = 0, max, min, search_key, found = 0, j, temp;

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


{

printf("%d.Enter a postive number:", i + 1);


scanf("%d", &list[i]);
sum += list[i];

}
printf("The sum of all the values are %d\n", sum);

max = list[0];
for (i = 1; i < size; i++)
{
if (list[i] > max)
max = list[i];
}
min = list[0];
for (i = 1; i < size; i++)
{
if (list[i] < min)
min = list[i];
}
printf("The highest value in the list is %d\n", max);
printf("The lowest value in the list is %d\n", min);

printf("Enter the number that you want to find : ");


scanf("%d", &search_key);

for (i = 0; i < 5; i++)


{
if (list[i] == search_key)
{
found = 1;
printf("%d is found at index %d\n", search_key, i);
}
}

if (found == 0)
printf(" Sorry %d is not in the list\n", search_key);

for (i = 0; i < size - 1; i++)

{
for (j = i + 1; j < size; j++)
{
if (list[i] > list[j])
{
temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}
printf("\nElements of array in sorted ascending order: \n");
for (int i = 0; i < 5; i++)
printf("%d ", list[i]);
printf("\n");

return(0);
}

You might also like