In the todays article we are going to talk about how can we find the smallest element in an array and how many ways we can solve this program so lets go.
So here are some points mentions below that we discussed in this
- Question
- sample input
- Logic
- solution with loop
- solution using function
- Feedback
Question-
Write a C Program to find the biggest element in the array
sample input
enter the range - 4
2 4 6 3
The biggest element is
6
C Program to find largest element in array |
Logic to solve the problem
- Take an array of some integers then take a variable ( n ) for taking the input how many data the user want to enter then run a for loop to taking the inputs .
- Again run another for loop and inside the loop use if condition for checking the large element in the array , Take a variable and initialize it from =0,.
- Then check inside the if the condition that the value that is greater than large assign it to large and print the large value
- Then again run a for loop to displaying the array after reversing
Source Code
#include<stdio.h>
int main()
{
int n,large=0;
printf("Enter the size :\n");
scanf("%d",&n);
int arr[100];
for(int i=0;i<n;i++)
{
printf("Enter the element no.\n");
scanf("%d",&arr[i]);
}
for(int i=0;i<n;i++)
{
if(large<arr[i])
large=arr[i];
//here we define from first that any element greater than zero in the array will become the greater array
//then we declare as it is greater
//in the next step if any value found in the array that is greater than the value store in array then it will assign to
//large and declare as bigger value and the process continue till the end
}
printf("The biggest element in the array is : %d",large);
return 0;
}
Solve by using the function
Source Code
// Write a C program to find the biggest element of a given array of integers
#include <stdio.h>
void large(int arr[], int n)
{
int lrg=0;
for (int i = 0; i < n; i++)
{
if (lrg < arr[i])
lrg = arr[i];
}
printf("The biggest element in the array is : %d",large);
}
int main()
{
int n,large=0;
printf("Enter the size :\n");
scanf("%d",&n);
int arr[100];
for(int i=0;i<n;i++)
{
printf("Enter the element no.\n");
scanf("%d",&arr[i]);
}
large(arr, n);
return 0;
}
Check Out OUR Home page for more information about practice problem
Also check Out
Also check Out Projects for Resume
Problems On C++
Q-2) Vectors In c++
Problems on TCS paper
1 , 1 , 2 , 3 , 4 , 9 , 8 , 27 , 16 , 81 , 32 , 243 , 64 , 729 , 128 , 2187
0 , 0 , 2 , 1 , 4 , 2 , 6 , 3 , 8 , 4 , 10 , 5 , 12 , 6 , 14 , 7 , 16 , 8
1 , 1 , 2 , 3 , 4 , 9 , 8 , 27 , 16 , 81 , 32 , 243 , 64 , 729 , 128 , 2187
0 , 0 , 2 , 1 , 4 , 2 , 6 , 3 , 8 , 4 , 10 , 5 , 12 , 6 , 14 , 7 , 16 , 8
FEEDBACK
If still you have any doubts please comment below and please share your approaches in the comment to know others and help others.
If still you have any doubts please comment below and please share your approaches in the comment to know others and help others.
Post a Comment
Post a Comment
Please do not spam in comment