Skip to content

Commit

Permalink
Array and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed Apr 24, 2018
1 parent cb59491 commit aaf8a8b
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
32 changes: 32 additions & 0 deletions array/bubble_sort.cpp
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;
}
38 changes: 38 additions & 0 deletions array/fun_array-4.cpp
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;
}
45 changes: 45 additions & 0 deletions array/fun_array-5.cpp
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;
}
24 changes: 24 additions & 0 deletions array/fun_from_other_file.cpp
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;
}
23 changes: 23 additions & 0 deletions array/io.cpp
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];
}
}


0 comments on commit aaf8a8b

Please sign in to comment.