bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / internal-practice / IP-18.c

IP-18.c (940B)


      1 /* Write a C program that includes a user-defined function named findLargest with the
      2 signature int findLargest(int arr[], int size);. The function should take an array of integers
      3 and its size, and return the largest element in the array. */
      4 
      5 #include <stdio.h>
      6 
      7 void inputArray(int[], int);
      8 int findLargest(int[], int);
      9 
     10 int main()
     11 {
     12     int size;
     13     printf("How many element do you want to enter: ");
     14     scanf("%d", &size);
     15     int arr[size];
     16     inputArray(arr, size);
     17     printf("\nLargest Element is: %d", findLargest(arr, size));
     18     return 0;
     19 }
     20 
     21 void inputArray(int arr[], int size)
     22 {
     23     int i;
     24     for (i = 0; i < size; i++)
     25     {
     26         printf("Enter element %d: ", i + 1);
     27         scanf("%d", &arr[i]);
     28     }
     29 }
     30 
     31 int findLargest(int arr[], int size)
     32 {
     33     int largest = arr[0], i;
     34     for (i = 1; i < size; i++)
     35     {
     36         if (largest < arr[i])
     37         {
     38             largest = arr[i];
     39         }
     40     }
     41     return largest;
     42 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror