-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from ankurgupta255/master
Move Zeroes of Array
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n; | ||
int a[100]; | ||
int i=0; | ||
int j=n-1; | ||
int cnt=0; | ||
cout<<"Enter the size of the array: "; | ||
cin>>n; | ||
cout<<"Enter the array Elements: "; | ||
for(int i=0;i<n;i++){ | ||
cin>>a[i]; | ||
} | ||
for(i=0;i<n;i++){ | ||
if(a[i]==0){ | ||
cnt++; | ||
} | ||
} | ||
for(i=0;i<n-cnt;i++){ | ||
if(a[i]==0){ | ||
for(j=n-1;j>=0;j--){ | ||
if(a[j]!=0){ | ||
int temp=a[i]; | ||
a[i]=a[j]; | ||
a[j]=temp; | ||
break; | ||
} | ||
else{ | ||
cout<<"All Elements are 0s."; | ||
}}}} | ||
for(i=0;i<n;i++){ | ||
cout<<a[i]<<"\t"; | ||
} | ||
return 0; | ||
system("PAUSE"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n; | ||
int a[100]; | ||
int i=0; | ||
int j=0; | ||
int cnt=0; | ||
int n1=0; | ||
int n2=0; | ||
cout<<"Enter the size of the array: "; | ||
cin>>n; | ||
cout<<"Enter the array Elements: "; | ||
for(i=0;i<n;i++){ | ||
cin>>a[i]; | ||
} | ||
int pro=a[0]*a[1]; | ||
for(i=0;i<n-1;i++){ | ||
for(j=i+1;j<n;j++){ | ||
if((a[i]*a[j])>pro){ | ||
n1=a[i]; | ||
n2=a[j]; | ||
pro=a[i]*a[j]; | ||
} | ||
} | ||
} | ||
cout<<"The 1st number is "<<n1<<endl; | ||
cout<<"The 2nd number is "<<n2<<endl; | ||
cout<<"The maximum product is "<<pro; | ||
return 0; | ||
system("PAUSE"); | ||
} |