-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb59491
commit aaf8a8b
Showing
5 changed files
with
162 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,32 @@ | ||
/* Bubble sort program using function and array | ||
*/ | ||
#include<iostream> | ||
#include<stdlib.h> | ||
#include<iomanip> | ||
#include "io.cpp" | ||
using namespace std; | ||
void bubble(int a[],int n){ | ||
int i,j,temp; | ||
for(i=0;i<n-1;i++) // steps | ||
{ | ||
for(j=0;j<n-1-i;j++) | ||
if(a[j]>a[j+1]) | ||
{ | ||
temp = a[j]; | ||
a[j]= a[j+1]; | ||
a[j+1]=temp; | ||
} | ||
} | ||
} | ||
|
||
int main(){ | ||
int a[10]; | ||
//input phase | ||
input(a,10); | ||
//processing phase | ||
bubble(a,10); | ||
// output phase | ||
cout<<"\n Sorted array :"; | ||
output(a,10); | ||
return 0; | ||
} |
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 @@ | ||
/* array declaration + initialization from keyboard | ||
*/ | ||
|
||
#include<iostream> | ||
#include<stdlib.h> | ||
#include<iomanip> | ||
|
||
using namespace std; | ||
|
||
void fun_add(int a[],int n){ | ||
int i; | ||
for(i=0;i<n;i++) | ||
a[i] = a[i]+10; | ||
} | ||
|
||
int main(){ | ||
int a[10]; | ||
int i; | ||
|
||
//input phase | ||
for(i=0;i<10;i++) | ||
{ | ||
cout<<"\n Enter a["<<i+1<<"] number "; | ||
cin>>a[i]; | ||
} | ||
|
||
//processing phase | ||
|
||
fun_add(a,5); | ||
|
||
// output phase | ||
|
||
cout<<"\n Modified array :"; | ||
for(i=0;i<10;i++) | ||
cout<<setw(10)<<a[i]; | ||
|
||
return 0; | ||
} |
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,45 @@ | ||
/* array declaration + initialization from keyboard | ||
*/ | ||
|
||
#include<iostream> | ||
#include<stdlib.h> | ||
#include<iomanip> | ||
|
||
using namespace std; | ||
|
||
void output(int a[],int n){ | ||
for(int i=0;i<n;i++) | ||
cout<<setw(10)<<a[i]; | ||
} | ||
|
||
void input(int x[],int n){ | ||
for(int i=0;i<n;i++) | ||
{ | ||
cout<<"Enter x["<<i+1<<"] number : "; | ||
cin>>x[i]; | ||
} | ||
} | ||
|
||
void fun_add(int a[],int n){ | ||
int i; | ||
for(i=0;i<n;i++) | ||
a[i] = a[i]+10; | ||
} | ||
|
||
int main(){ | ||
int a[10]; | ||
|
||
|
||
//input phase | ||
input(a,10); | ||
|
||
//processing phase | ||
|
||
fun_add(a,10); | ||
|
||
// output phase | ||
|
||
cout<<"\n Modified array :"; | ||
output(a,10); | ||
return 0; | ||
} |
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,24 @@ | ||
/* array declaration + initialization from keyboard | ||
*/ | ||
#include<iostream> | ||
#include<stdlib.h> | ||
#include<iomanip> | ||
#include "io.cpp" | ||
using namespace std; | ||
void fun_add(int a[],int n){ | ||
int i; | ||
for(i=0;i<n;i++) | ||
a[i] = a[i]+10; | ||
} | ||
|
||
int main(){ | ||
int a[10]; | ||
//input phase | ||
input(a,10); | ||
//processing phase | ||
fun_add(a,10); | ||
// output phase | ||
cout<<"\n Modified array :"; | ||
output(a,10); | ||
return 0; | ||
} |
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,23 @@ | ||
/* array declaration + initialization from keyboard | ||
*/ | ||
|
||
#include<iostream> | ||
#include<stdlib.h> | ||
#include<iomanip> | ||
|
||
using namespace std; | ||
|
||
void output(int a[],int n){ | ||
for(int i=0;i<n;i++) | ||
cout<<setw(10)<<a[i]; | ||
} | ||
|
||
void input(int x[],int n){ | ||
for(int i=0;i<n;i++) | ||
{ | ||
cout<<"Enter x["<<i+1<<"] number : "; | ||
cin>>x[i]; | ||
} | ||
} | ||
|
||
|