This is the best program in C++ for logic building and understanding the arrays. The program will find out the second greatest number in a given array.
Source Code
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#define MIN -1
int main()
{
cout<<"\a\n\n\n"
<<"\t******************************************************"<<endl
<<"\t** **"<<endl
<<"\t** Welcome To **"<<endl
<<"\t** **"<<endl
<<"\t** Second Largest **"<<endl
<<"\t** **"<<endl
<<"\t** Demo **"<<endl
<<"\t** **"<<endl
<<"\t******************************************************"<<endl<<endl<<endl;cout<<"";
int largest=MIN,secondLargest=MIN;
int array[6]={3,1,7,3,9,5};
for(int i=0;i<5;i++){
cout<<array[i]<<",";
}
for(int i=0;i<5;i++){
if(array[i]>largest){
secondLargest=largest;
largest=array[i];
}
}
cout<<endl<<"Second Largest:"<<secondLargest;
int i;
cin>>i;
return 0;
}
0 comments:
Post a Comment