Find Smallest Element in Array : C Program

Computer Science » C Program » Find Smallest Element in Array 

Program :

#include<stdio.h>
 
int main() 
{
   int a[30], i, num, smallest;
 
   printf("nEnter no of elements : ");
   scanf("%d", &num);
 
   //Read n elements in an array
   for (i = 0; i < num; i++)
      scanf("%d", &a[i]);
 
   //Consider first element as smallest
   smallest = a[0];
 
   for (i = 0; i < num; i++) {
      if (a[i] < smallest) {
         smallest = a[i];
      }
   }
 
   // Print out the Result
   printf("nSmallest element is : %d", smallest);
 
   return (0);
}

Output :

Enter no of elements : 5
10 20 30 40 50
Smallest element is : 10
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Find Largest Element in Array : C ProgramComputer Science » C Program » Find Largest Element in Array Program : [php]#include<stdio.h> int main() { int a[30], i, num, largest; printf("nEnter no of elements : "); scanf("%d", &num); //Read n elements in an array for (i = 0; i < num; i++) scanf("%d", &a[i]); //Consider first element as largest largest = a[0]; for (i = 0; i < num; i++) { if (a[i] > largest) { largest = a[i]; } } // Print out the Result printf("nLargest element is : %d", largest); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Largest element is : 50[/php]
    Tags: program, find, element, array, computer, science, output, programs
  • C Program ExamplesComputer Science » C Program » C Program Examples "How to print hello, world! using c program ? How to find area of a circle using c program ? How to find smallest element in an array using c program ? You all must have this kind of questions in your mind. Below article will solve this puzzle of yours. Just take a look.”  - Here we have listed all the programs in C programming language, categorised under different progamming concepts like Basic, Area, Mathematical, Number, Array etc. Check the respective category to view all the programs under that category. C Programs - Basic C Programs C Programs - Number Programs C Programs - Area Programs C Programs - Mathematical Programs C Programs - Array Programs C Programs - Electrical Programs C Programs - Pyramid Programs
    Tags: programs, program, computer, science
  • Find Sum of Digits of a Number : C ProgramComputer Science » C Program » Find Sum of Digits of a Number Program : [php]#include <stdio.h> int main() { long number, digit, sum = 0; printf("Enter the number :"); scanf("%ld", &number); while (number > 0) { digit = number % 10; sum = sum + digit; number = number / 10; } printf("nSum of the digits of given number is : %ld", sum); }[/php] Output : [php]Enter the number : 2882 Sum of the digits of given number is : 20[/php]
    Tags: program, find, computer, science, output, programs
  • Delete an Element from Specified Location from Array : C ProgramComputer Science » C Program » Delete an Element from Specified Location from Array Program : [php]#include&lt;stdio.h&gt; int main() { int arr[30], num, i, loc; printf("nEnter no of elements : "); scanf("%d", &amp;num); //Read elements in an array printf("nEnter %d elements : ", num); for (i = 0; i &lt; num; i++) { scanf("%d", &amp;arr[i]); } //Read the location printf("nLocation of the element to be deleted : "); scanf("%d", &amp;loc); /* loop for the deletion */ while (loc &lt; num) { arr[loc - 1] = arr[loc]; loc++; } num--; // No of elements reduced by 1 //Print Array for (i = 0; i &lt; num; i++) printf("n %d", arr[i]); return (0); }[/php] Output : [php]Enter no of elements : 5 Enter 5 elements : 10 20 30 40 50 Location of the element to be deleted : 3 10 20 40 50[/php]
    Tags: program, element, array, computer, science, output, programs
  • Calculate Addition of All Elements in Array : C ProgramComputer Science » C Program » Calculate Addition of All Elements in Array Program : [php]#include&lt;stdio.h&gt; int main() { int i, arr[50], sum, num; printf("nEnter number of elements :"); scanf("%d", &amp;num); //Reading values into Array printf("nEnter the values :"); for (i = 0; i &lt; num; i++) scanf("%d", &amp;arr[i]); //Computation of total sum = 0; for (i = 0; i &lt; num; i++) sum = sum + arr[i]; //Printing of all elements of array for (i = 0; i &lt; num; i++) printf("na[%d]=%d", i, arr[i]); //Printing of total printf("nSum of all elements : %d", sum); return (0); }[/php] Output : [php]Enter number of elements : 4 Enter the values : 10 20 30 40 a[0]=10 a[1]=20 a[2]=30 a[3]=40 Sum of all elements : 100[/php]
    Tags: program, array, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here