87.2k views
0 votes
Write a program in C language using pointers to access and manipulate indirectly an array. The elements of this array must be integer values given by user while execution time and the array must store 200 elements. After all elements stored, calculate and tell:

A) How many values are bigger than the smallest value in the whole array.

User Fdan
by
7.2k points

1 Answer

5 votes

Final answer:

In this C program, pointers are used to access and manipulate an array to count the number of values greater than the smallest value in an array of 200 integers provided by the user.

Step-by-step explanation:

The question asks for a C program that uses pointers to manipulate an array that stores 200 integers provided by the user during execution. After storing all the elements, the program should count how many values in the array are larger than the smallest value.

The following is an example program demonstrating how you can achieve this:

#include

int main() {
int array[200], *ptr, smallest, count = 0;
ptr = array; // Pointer assignment

// Input integers from user
printf("Enter 200 integers:\\");
for(int i = 0; i < 200; i++) {
scanf("%d", ptr + i);
}

// Finding the smallest value
smallest = *ptr;
for(int i = 1; i < 200; i++) {
if(*(ptr + i) < smallest) {
smallest = *(ptr + i);
}
}

// Count values greater than smallest
for(int i = 0; i < 200; i++) {
if(*(ptr + i) > smallest) {
count++;
}
}

printf("There are %d values in the array that are greater than the smallest value %d.\\", count, smallest);

return 0;
}

This program declares an array of 200 integers and a pointer to integers. It then uses the pointer to store user input in the array, find the smallest value in the array, and count how many array elements are greater than that smallest value.

User Alexandre Victoor
by
7.0k points