Research Area

Ashutosh Dubey

Thursday, May 2, 2019

Array Programs

1.WAP to accept rollno of 5 students and display them.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
double a[5],i;
cout<<"\t\t\t\t\tLaxman"<<endl;
cout<<"Enter the Roll No4."<<endl;
for(i=0;i<=4;i++)
{
cin>>a[i];
}
for(i=0;i<=4;i++)
{
cout<<a[i]<<endl;
}
getch();}

2. WAP to accept 5 no and reverse them.







#include<iostream.h>


#include<conio.h>


void main()


{


clrscr();


int a[5],i;


cout<<"\t\t\t\tLaxman"<<endl;


cout<<"Enter the No."<<endl;


for(i=0;i<=4;i++)


{


cin>>a[i];


}


cout<<"Reverse of No."<<endl;


for(i=4;i>=0;i--)


{


cout<<a[i]<<endl;


}


getch();


}






3. WAP to accept 10 integer and find the sum of all even and odd numbers separately.






#include<iostream.h>


#include<conio.h>


void main()


{


clrscr();


cout<<" \t\t\t\tLaxman"<<endl;


int a[10],i,sume=0,sumo=0;


cout<<"Enter the no."<<endl;


for(i=0;i<=9;i++)


{


cin>>a[i];


}


for(i=0;i<=9;i++)


{


if(a[i]%2==0)


sume=sume+a[i];


else


sumo=sumo+a[i];


}


cout<<"Sum of Even No."<<sume<<endl;


cout<<"Sum of Odd No."<<sumo;


getch();


}






















4.WAP to accept 10 element and identify the max and min no in the array also identify the position as well.










#include<iostream.h>


#include<conio.h>


void main()


{


clrscr();


cout<<" \t\t\t\tLaxman"<<endl;


int a[10],i,max=0,min=0,m,n;


cout<<"Enter the no."<<endl;


for(i=0;i<=9;i++)


{


cin>>a[i];


}


for(i=0;i<=9;i++)


{


if(max<a[i])


{


max=a[i];


m=i;


}


else if(min>a[i])


{


min=a[i];


n=i;


}


}


cout<<"Maximum no.is"<<max;


cout<<"\t& Position of max.is"<<m+1<<endl;


cout<<"Minimum no.is"<<min;


cout<<"\t& Position of min.is"<<n+1;


getch();


}






5. WAP to accept the amount of sale made for each day in a week and calculate the average of these values.










#include<iostream.h>


#include<conio.h>


void main()


{


clrscr();


cout<<" \t\t\t\tLaxman"<<endl;


int a[7],i,j=0;


cout<<"Enter the sales"<<endl;


for(i=0;i<7;i++)


{


cout<<"Day "<<i+1<<"\t\t";


cin>>a[i];


j+=a[i];


}


cout<<"The sales for week"<<j/7;


getch();


}






6. WAP to implement BUBBLE SORT algorithm.






#include<iostream.h>


#include<conio.h>


void main()


{


clrscr();


cout<<" \t\t\t\tLaxman"<<endl;


int a[100],i,j,temp,n;


cout<<"Enter the no. of elements in the array"<<endl;


cin>>n;


cout<<"Enter the elements"<<endl;


for(i=0;i<n;i++)


{


cin>>a[i];


}


for(i=0;i<n;i++)


{


for(j=0;j<n-1;j++)


{


if(a[j]>a[j+1])


{


temp=a[j];


a[j]=a[j+1];


a[j+1]=temp;


}


}


}


cout<<"Sorted list is\n";


for(i=0;i<n;i++)


cout<<a[i]<<"\t";


getch();


}

No comments: