samedi 30 juin 2018

Why my c++ array element changed into a large number?

#include<iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{

 long long  n,i;
 cin>>n;

 long long arr[n];**strong text**
 for(i=0;i<n;i++){
  cin>>arr[n];
 }
 long long index=0;
 for(i=1;i<n;i++)
 {
   if(arr[i]>arr[index])
   {
     index=i;
   }
   else
   continue;
 }

 for(i=0;i<n;i++){
  cout<<arr[i]<<endl;    
 }
}

Eg:- Input:- 5

12 33 22 11 5

Output:-

84785773116751

8476457385632857804

8065190381340

208132006536

18037221972114776

Can Anyone explain me why I am getting such weird output when all I did just print my array without changing it's value?

Aucun commentaire:

Enregistrer un commentaire