C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

C++

How do we write a program to calculate the largest element in an array of 10 cells

28th Feb 2019, 6:37 AM
Shubhra Jyotsna
Shubhra Jyotsna - avatar
7 Answers
+ 5
logic part: max=array[0]; for(i=0;i<10;i++) { if(max<array[i]) max=array[i]; }
28th Feb 2019, 8:15 AM
[ ]
[     ] - avatar
+ 4
[ ] oops my bad ๐Ÿ˜ฅ. You were right all along. How do you pronounce your name, brackets?
28th Feb 2019, 1:21 PM
Sonic
Sonic - avatar
+ 1
Sonic Sonic when max is less than the array element then it implies that there is some other element present in array larger than max so the required element is that.....therefore max<array[i]
28th Feb 2019, 1:15 PM
[ ]
[     ] - avatar
+ 1
i hope i am clear ๐Ÿ˜…!!
28th Feb 2019, 1:17 PM
[ ]
[     ] - avatar
+ 1
Sonic lol actually its just blank ....its from a character of a show(anime pls dont judge me now) like yours ...but brackets is fine๐Ÿ˜
28th Feb 2019, 1:25 PM
[ ]
[     ] - avatar
+ 1
~ swim ~ As u wish sir.....but i guess there is not much harm in i=0
28th Feb 2019, 1:45 PM
[ ]
[     ] - avatar
+ 1
#include<iostream> using namespace std; Int main() { int I,max,n,a[]; cout<<"\n enter limit"; cin>>n; cout<<"\n enter array : "; for(i=0;i<n;i++) cin>>a[i]; max=a[0]; for( I=0;i<n;i++) { if(a[I]>max) max=a[i];} cout<<"\n maximum number is="; cout<<max; return 0; }
25th Sep 2019, 1:18 PM
Narendra Pratap Singh