2.
#include<iostream.h>
int main ()
{
int a[50];
int i,j,temp,n;
cout<<" how many element you want to read n";
cout<<"(but keep in mind less than or equal to 50 )"<<endl;
cin>>n;
cout<<"enter elements one by one "<<endl;
for(i=0;i<=(n-1);i++)
cin>>a[i];
cout<<"the array in unsorted form:"<<endl;
for(i=0;i<=(n-1);i++)
{
cout<<a[i]<<endl;
}
for(i=0;i<=(n-2);i++)
for(j=i+1;j<=(n-1);j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
03.
#include<iostream.h>
#include<conio.h>
void main()
{
int m[3][2],i,j,x,y,s[3];
cout<<"enter the order of matrixn";
cin>>x>>y;
cout<<"enter the matrixn";
for(i=0;i<3;i++)
for(j=0;j<2;j++)
cin>>m[i][j];
for(i=0;i<3;i++)
s[i]=0;
for(i=0;i<3;i++)
for(j=0;j<2;j++)
s[i]=s[i]+m[i][j];
cout<<"the sum of each row isn";
for(i=0;i<3;i++)
cout<<s[i]<<endl;
getch();
}
4. #include <iostream.h>
void binary(int);
void main(void) {
int number;
cout << "Please enter a positive integer: "<<endl;
cin >> number;
if (number < 0)
cout << "That is not a positive integer.n";
else {
cout << number << " converted to binary is: ";
binary(number);
cout << endl;
}
}
void binary(int number) {
int remainder;
if(number <= 1) {
cout << number;
return;
}
7.
#include<iostream.h>
int main ()
{
int a[3][3]={{4,6,9},{6,1,0},{1,5,2}};
int i,j,trace;
trace=0;
for(i=0;i<=2;i++)
for(j=0;j<=2;j++)
{
if(i==j)
trace=trace+a[i][j];
}
cout<<"the trace is:"<<trace;
return 0;
}
8.
#include<iostream.h>
#include<conio.h>
#include<conio.h>
void main()
{
int o[2][2],p[2][2],i,j,a,b,l,m,x,y,s[2][2];
cout<<"enter the order of matrixn";
cin>>x>>y;
cout<<"enter the row of first matrixn";
cin>>a;
cout<<"enter the column of first matrixn";
cin>>b;
cout<<"enter the row of second matrixn";
cin>>l;
cout<<"enter the column of secod matrixn";
cin>>m;
cout<<"enter the first matrixn";
for(i=0;i<a;i++)
for(j=0;j<b;j++)
cin>>o[i][j];
cout<<"entr the second matrixn";
for(i=0;i<l;i++)
for(j=0;j<m;j++)
cin>>p[i][j];
10.
#include<iostream.h>
struct personal{
char name[20];
char dateofbirth[15];
char bloodgroup[10];
float height;
char contactadress[25];
char telephonenum[20];
char drivinglicensenum[18];
char qualification[30];
};
int main()
{
personal p1;
cout<<"enter person name:n";
cin>>p1.name;
cout<<"enter date of birth in ddd/mmm/yyy:n";
cin>>p1.dateofbirth;
cout<<"enter the blood group:n";
cin>>p1.bloodgroup;
cout<<"enter the height:n";
cin>>p1.height;
cout<<"enter contact address :n";
cin>>p1.contactadress;

Abebe1

  • 1.
    2. #include<iostream.h> int main () { inta[50]; int i,j,temp,n; cout<<" how many element you want to read n"; cout<<"(but keep in mind less than or equal to 50 )"<<endl; cin>>n; cout<<"enter elements one by one "<<endl; for(i=0;i<=(n-1);i++) cin>>a[i]; cout<<"the array in unsorted form:"<<endl; for(i=0;i<=(n-1);i++) { cout<<a[i]<<endl; } for(i=0;i<=(n-2);i++) for(j=i+1;j<=(n-1);j++) if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; }
  • 2.
    03. #include<iostream.h> #include<conio.h> void main() { int m[3][2],i,j,x,y,s[3]; cout<<"enterthe order of matrixn"; cin>>x>>y; cout<<"enter the matrixn"; for(i=0;i<3;i++) for(j=0;j<2;j++) cin>>m[i][j]; for(i=0;i<3;i++) s[i]=0; for(i=0;i<3;i++) for(j=0;j<2;j++) s[i]=s[i]+m[i][j]; cout<<"the sum of each row isn"; for(i=0;i<3;i++) cout<<s[i]<<endl; getch(); }
  • 3.
    4. #include <iostream.h> voidbinary(int); void main(void) { int number; cout << "Please enter a positive integer: "<<endl; cin >> number; if (number < 0) cout << "That is not a positive integer.n"; else { cout << number << " converted to binary is: "; binary(number); cout << endl; } } void binary(int number) { int remainder; if(number <= 1) { cout << number; return; }
  • 4.
    7. #include<iostream.h> int main () { inta[3][3]={{4,6,9},{6,1,0},{1,5,2}}; int i,j,trace; trace=0; for(i=0;i<=2;i++) for(j=0;j<=2;j++) { if(i==j) trace=trace+a[i][j]; } cout<<"the trace is:"<<trace; return 0; }
  • 5.
    8. #include<iostream.h> #include<conio.h> #include<conio.h> void main() { int o[2][2],p[2][2],i,j,a,b,l,m,x,y,s[2][2]; cout<<"enterthe order of matrixn"; cin>>x>>y; cout<<"enter the row of first matrixn"; cin>>a; cout<<"enter the column of first matrixn"; cin>>b; cout<<"enter the row of second matrixn"; cin>>l; cout<<"enter the column of secod matrixn"; cin>>m; cout<<"enter the first matrixn"; for(i=0;i<a;i++) for(j=0;j<b;j++) cin>>o[i][j]; cout<<"entr the second matrixn"; for(i=0;i<l;i++) for(j=0;j<m;j++) cin>>p[i][j];
  • 6.
    10. #include<iostream.h> struct personal{ char name[20]; chardateofbirth[15]; char bloodgroup[10]; float height; char contactadress[25]; char telephonenum[20]; char drivinglicensenum[18]; char qualification[30]; }; int main() { personal p1; cout<<"enter person name:n"; cin>>p1.name; cout<<"enter date of birth in ddd/mmm/yyy:n"; cin>>p1.dateofbirth; cout<<"enter the blood group:n"; cin>>p1.bloodgroup; cout<<"enter the height:n"; cin>>p1.height; cout<<"enter contact address :n"; cin>>p1.contactadress;