Wednesday 5 June 2013


//function to construct exponential series of user defined "n". if user enter n=10 then it construct series upto 10...
// exponential series

#include <iostream.h>
#include <math.h>

void main()
{
int terms;
float f = 1, x, v = 0;

cout<<"enter value of variable x: ";
cin>>x;
cout<<"enter number of terms of series: ";
cin>>terms;

for(int n = 1; n<=terms ; n++)
{
v = v + pow(x, n-1)/f;
f = f*n;
}
cout<<"e^"<<x<<" upto "<<terms<<" terms is = "<<v<<endl;
cout<<endl;
}

Monday 3 June 2013

To find maximum deviation
// maximum deviation

#include<iostream.h>
#include <math.h>
void main()
{
int a[3][3], i, j, k, max, min;
float mean, md, sum = 0;

// initializing 2 D array a with user defined values

cout<<"Enter values for array A"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for a["<<i<<"]["<<j<<"]:";
    cin>>a[i][j];
  }
}

cout<<endl<<endl;

// origional array A

cout<<"displaying origional array A:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<a[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl<<endl;

// maximum, minimum, mean and md

max = a[0][0];
min = a[0][0];

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(a[i][j] > max)
{
max = a[i][j];
}
if(a[i][j] < min)
{
min = a[i][j];
}

sum = sum + a[i][j];
}
}

cout<<"maximum value in array A is = "<<max<<endl;
cout<<"minimum value in array A is = "<<min<<endl;

mean = sum / 9;

cout<<"mean value of the array is = "<<mean<<endl;

if(abs(max - mean) > abs(min - mean))
{
md = abs(max - mean);
cout<<"maximum deviation from mean "<<mean<<" is "<<md<<endl;
}
else
{
md = abs(min - mean);
cout<<"maximum deviation from mean "<<mean<<" is "<<md<<endl;
}

cout<<endl<<endl;
}
To check matrix is identity or not?
// addition of arrays

#include<iostream.h>
void main()
{
int a[3][3], b[3][3], c[3][3],  i, j;

// initializing 2 D array a with user defined values

cout<<"Enter values for array A"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for a["<<i<<"]["<<j<<"]:";
    cin>>a[i][j];
  }
}

cout<<endl<<endl;

// initializing 2 D array b with user defined values

cout<<"Enter values for array B"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for b["<<i<<"]["<<j<<"]:";
    cin>>b[i][j];
  }
}

cout<<endl<<endl;

// addition and displaying the sum

cout<<"A + B =:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
  c[i][j] = a[i][j] + b[i][j];
    cout<<c[i][j]<<" ";
  }
cout<<endl;
}


}

// addition of arrays

#include<iostream.h>
void main()
{
int a[3][3], b[3][3], c[3][3],  i, j;

// initializing 2 D array a with user defined values

cout<<"Enter values for array A"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for a["<<i<<"]["<<j<<"]:";
    cin>>a[i][j];
  }
}

cout<<endl<<endl;

// initializing 2 D array b with user defined values

cout<<"Enter values for array B"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for b["<<i<<"]["<<j<<"]:";
    cin>>b[i][j];
  }
}

cout<<endl<<endl;

// addition and displaying the sum

cout<<"A + B =:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
  c[i][j] = a[i][j] + b[i][j];
    cout<<c[i][j]<<" ";
  }
cout<<endl;
}


}

Sunday 2 June 2013

// Create TWO 2-D arrays of size 3 by 3 with user defined values.
// Swap the contents of the two arrays. Display both arrays.


#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j, temp;

// initializing 2 D array a with user defined values

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for a["<<i<<"]["<<j<<"]:";
    cin>>a[i][j];
  }
}

cout<<endl;

// initializing 2 D array b with user defined values

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for b["<<i<<"]["<<j<<"]:";
    cin>>b[i][j];
  }
}

cout<<endl;

//displaying array a

cout<<"displaying array a:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<a[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

//displaying array b

cout<<"displaying array b:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<b[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

// swapping 2 D array a and b

cout<<"copying array:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
temp = a[i][j];
a[i][j] = b[i][j];
b[i][j] = temp;
  }
}

//displaying array a

cout<<"displaying array a after swapping:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<a[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

//displaying array b

cout<<"displaying array b after swapping:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<b[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

}

// Create a 2-D array of size 3 by 3 with user defined values.
// Copy this array in another array of the same size.
// Display both arrays.

#include<iostream.h>
void main()
{
int a[3][3], b[3][3], i, j, zero = 0;

// initializing 2 D array a with user defined values

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"enter value for a["<<i<<"]["<<j<<"]:";
    cin>>a[i][j];
  }
}

cout<<endl;

//displaying array a

cout<<"displaying array a:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<a[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

// copyinh 2 D array a to b

cout<<"copying array:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
b[i][j] = a[i][j];
  }
}

//displaying array b

cout<<"displaying array b:"<<endl<<endl;

for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
cout<<b[i][j]<<" ";
  }
  cout<<endl;
}

cout<<endl;

}

# include <iostream.h>

// Construct a user defined array of 10 integers.
// Count the even and odd integers in the array and display the counts.

void main()
{
    int a[10], i;
int even = 0;
int odd = 0;

for(i = 0; i<10 ;i++)
{
cout<<"enter an integer for location a["<<i<<"]: ";
cin>>a[i];

if(a[i]%2 == 0)
{
even++;
}
else
{
odd++;
}
}

cout<<"the array has "<<even<<" even numbers"<<endl;
cout<<"the array has "<<odd<<" odd numbers"<<endl;
}

Subscribe to RSS Feed Follow me on Twitter!