Find Biggest In An Array, Without Sorting It: C

First we have to assume that a[0] is biggest. Now store the value of a[0] inside a variable called big. Now compare value of big with other values in the array. If big is less than any other value, then store the bigger value inside variable big.

Video Tutorial: Biggest In An Array, Without Sorting It: C


[youtube https://www.youtube.com/watch?v=tKaImGrxgKo]

YouTube Link: https://www.youtube.com/watch?v=tKaImGrxgKo [Watch the Video In Full Screen.]



Note that, the previous value inside the variable big is discarded.

Full source code

#include < stdio.h >
#include < conio.h >

void main()
{
int big, a[20], N, pos, i;
clrscr();

printf("Enter the array size\n");
scanf("%d", &N);

printf("Enter %d elements\n", N);
for(i = 0; i < N; i++) 
           scanf("%d", &a[i]);

         big = a[0];
         pos = 0;

         for(i = 1;  i < N; i++)
          if(a[i] > big)
  {
    big = a[i];
    pos = i+1;
    }

 printf("Big is %d and its position is %d", big, pos);

 getch();
}

Output
Enter the array size
5
Enter 5 elements
2
0
100
108
55
Big is 108 and its position is 4

Array Basics in C++ : Find Sum

Video tutorial to show the basic use of arrays: Initialization, Declaration, Getting values from the users, finding sum of all the array elements etc.

Array is a collection of homogeneous data items.

Full Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream .h>
#include<conio .h>
 
void main()
{
  //  int a[5] = { 1, 3, 2, 4, 5 }; declaration with initialization
 
  int a[5], sum = 0;
  clrscr();
 
  cout< <"Enter 5 numbers\n";
  for(int i=0; i&lt;5; i++)
   cin>>a[i];
 
  cout< <"Input array is..\n";
  for(i=0; i&lt;5; i++)
  {
   cout<<a[i]<<endl;
   sum = sum + a[i];  // sum += a[i];
  }
  cout<<"Sum of array elements: "<<sum;
 
  getch();
 
}

In this program we take input from the user and display the user entered numbers and find the sum of all the array elements and display it as well.

Elements are stored from the index number 0. i.e., if the array size is 5, the values will be stored in a[0], a[1], a[2], a[3], a[4];

Ex:
int a[5] = { 1, 3, 2, 4, 5 }; declaration with initialization
float a[5] = { 1.1, 2.0, 3.3, 1.3, 5.6 };

Video Tutorial: Array Basics in C++ : Find Sum


[youtube https://www.youtube.com/watch?v=BfAa2koJv64]

YouTube Link: https://www.youtube.com/watch?v=BfAa2koJv64 [Watch the Video In Full Screen.]



Output:
Enter 5 numbers
1
2
3
4
5
Input array is..
1
2
3
4
5
Sum of array elements: 15