C program that finds the largest element in an array :

  1. #include <stdio.h>
  2. int main() {
  3.   int n, i;
  4.   long long int t1 = 0, t2 = 1, nextTerm;

  5.   printf("Enter the number of terms: ");
  6.   scanf("%d", &n);

  7.   printf("Fibonacci Series: ");

  8.   for (i = 1; i <= n; ++i) {
  9.     printf("%lld, ", t1);
  10.     nextTerm = t1 + t2;
  11.     t1 = t2;
  12.     t2 = nextTerm;
  13.   }

  14.   return 0;
  15. }

  • This program first reads in n, the number of elements in the array. It then reads in n elements from the user and stores them in the array. 
  • Finally, it iterates through the array and compares each element to the first element (which is initially set to the largest). 
  • If it finds a larger element, it updates the value of the first element to be the larger value. At the end, the program prints out the largest element in the array.


  • This program first initializes an array a with 10 elements and assigns the value of the first element to the variable max.
  • It then loops through the array and compares each element with max. 
  • If an element is larger than max, max is updated with the new value. After the loop finishes, max will contain the largest element in the array.

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu