0% found this document useful (0 votes)
29 views3 pages

Exp 5

This document discusses two C programs. The first finds the smallest and largest numbers in an array along with their index values. It takes user input for the array size and values, sorts the array, and prints the smallest and largest values with their indexes. The second program reads user input to populate an array, prints the normal and reverse ordered arrays to display the values in reverse order. Both programs execute successfully and achieve their goals of processing array values as defined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Exp 5

This document discusses two C programs. The first finds the smallest and largest numbers in an array along with their index values. It takes user input for the array size and values, sorts the array, and prints the smallest and largest values with their indexes. The second program reads user input to populate an array, prints the normal and reverse ordered arrays to display the values in reverse order. Both programs execute successfully and achieve their goals of processing array values as defined.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Ex.No.

5
Usage of Arrays Reg.No: URK22CS5043
01.11.2022

a) Write a C program to find the smallest and largest number in an array with index value

Aim:
To find the smallest and largest number in an array with index value

Algorithm:
Step 1: Start the program.
Step 2: int n, k=0, l=0
Step 3: Read the Input values n
Step 4: int I =0, i<n, ++i
Step 5: Print smallest and largest number with index value
Step 6: Stop the Program.

Program:

#include <stdio.h>
int main() {
int n, k=0, l=0, i, j;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
for (i = 0; i < n - 1; ++i) {
for (j = 0; j < n - i - 1; ++j) {
if (arr[i] > arr[i + 1]) {
int temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
printf("smallest element = %.2lf and its position is %d ", arr[0],l);
for(i = 0; i < n; i++) {
if(arr[0] > arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf and its position is %d ", arr[n-1],n-1);
return 0;
}

Output:

Result:
This program is executed successfully and the reverse of an array is obtained

b) Write a C program to read a n number of values in a array and display it in reverse order

Aim:
To read a n number of values in a array and display it in reverse order

Algorithm:

Step 1: Start the program.


Step 2: int I, n, a[100]
Step 3: Read the Input values of n
Step 4: I = n-1; i>=0; i--
Step 5: Display reverse of a array
Step 6: Stop the Program.
Program:

include <stdio.h>
void main ()
{
int i, n, a[100];
printf ("Input the number of elements to store in the array :");
scanf ("%d", &n);
printf ("Input %d number of elements in the array :\n", n);
for (i = 0; i < n; i++)
{
printf ("element - %d : ", i);
scanf ("%d", &a[i]);
}
printf ("\nThe values store into the array are : \n");
for (i = 0; i < n; i++)
{
printf ("% 5d", a[i]);
}
printf ("\n\nThe values store into the array in reverse are :\n");
for (i = n - 1; i >= 0; i--)
{
printf ("% 5d", a[i]);
}
}

Output:

Result:
This program is executed successfully and the reverse of an array is obtained.

You might also like