Tuesday, 6 June 2017

pass by value ,,array

#include <iostream>
using namespace std;

float average(int arr[], int size);

int main() {

int balance[5] = { 50,50,50,50,50 };
float avg;
avg = average(balance, 5);
cout << "Average value is: " << avg << endl;

return 0;
}
float average(int arr[], int size)
{
double xavg;
xavg = (arr[0] + arr[1] + arr[2] + arr[3] + arr[4]) / 5;
return xavg;
}

Wednesday, 24 May 2017

multuplication of 2*2 matrix

#include<iostream>
using namespace std;
int main()
{
                int twoDarray[2][2],twoDarray1[2][2],twoDarray2[2][2];
                cout<<"enter the values in first matrix \n";
                for(int rsize=0;rsize<2;rsize++)
                               
                {
                                for(int csize=0;csize<2;csize++)
                                {
                                       
                                      
                                                cin>>twoDarray[rsize][csize];
                                cin>>twoDarray1[rsize][csize];

                               

                            
                            
                              
                             
                                }
                                cout<<"\n";
               

                }
                for(int rsize=0;rsize<2;rsize++)
                               
                {
                                for(int csize=0;csize<2;csize++)
                                {
                                                int sum=0;
                                                for(int x=0;x<2;x++)
                                                {
                                                                sum=sum+twoDarray[rsize][x]*twoDarray1[x][rsize];
                                                }
                                twoDarray2[rsize][csize]=sum;
                               
                                }
                }
                                for(int rsize=0;rsize<2;rsize++) 
                {
                                for(int csize=0;csize<2;csize++)
                                {
                                                cout<<twoDarray2[rsize][csize]<<"\t";
                               
                                                 
                                }
                                cout<<"\n";
                               
                                }


                return 0;

}

Wednesday, 3 May 2017

factorial c++ programming

#include <iostream>
using namespace std;
int main()
{
int fact=1, i;
cout << "emter the number";
cin >> i;
for (int count = 1; count <=i; count++)
{
fact = fact*count;

}
cout << fact;
return 0;
}

Wednesday, 26 April 2017

home work display straick

#include <iostream>
using namespace std;
int main()
{
int space = 0, star = 5;
for (int i = 1; i <=5; i++)
{
for ( int j = 0; j <space; j++)
{
cout << " ";
}
for (int j = 0; j < star; j++)
{
cout << "*";
}
cout << endl;
space++;
star--;
}

return 0;
}
.........................................................................
#include <iostream>
using namespace std;
int main()
{
int space = 5, star = 1;
for (int i = 1; i <=5; i++)
{
for ( int j = 1; j <space; j++)
{
cout << " ";
}
for (int j = 0; j < star; j++)
{
cout << "*";
}
cout << endl;
space--;
star++;
}

return 0;
}
.............................................................
#include <iostream>
using namespace std;
int main()
{
int space = 5, star = 1;
for (int i = 1; i <=5; i++)
{
for ( int j = 1; j <space; j++)
{
cout << " ";
}
for (int j = 0; j < star; j++)
{
cout << "*";
}
for (int j = 1; j < star; j++)
{
cout << "*";
}
cout << endl;
space--;
star++;
}

return 0;
.............................................................................
#include <iostream>
using namespace std;
int main()
{

int space1 = 1, star1 =5 ;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <space1; j++)
{
cout << " ";
}
for (int j = 0; j < star1; j++)
{
cout << "*";
}
for (int j = 1; j < star1; j++)
{
cout << "*";
}
cout << endl;
space1++;
star1--;
}
return 0;
}
}
.............................................................................
#include <iostream>
using namespace std;
int main()
{
int space = 5, star = 1;
for (int i = 1; i <=5; i++)
{
for ( int j = 1; j <space; j++)
{
cout << " ";
}
for (int j = 0; j < star; j++)
{
cout << "*";
}
for (int j = 1; j < star; j++)
{
cout << "*";
}
cout << endl;
space--;
star++;
}
int space1 = 1, star1 =5 ;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <space1; j++)
{
cout << " ";
}
for (int j = 0; j < star1; j++)
{
cout << "*";
}
for (int j = 1; j < star1; j++)
{
cout << "*";
}
cout << endl;
space1++;
star1--;
}
return 0;
}
............................................................

Tuesday, 25 April 2017

c++ prog..
..................................................................
#include <iostream>
using namespace std;
int main()
{
int n,m,l;
cout << " enter the first number ";
cout<< endl;
cin >> n;
if (n > 0)
{
cout << "enter  the second number ";
cout << endl;
cin >> m;

if (m > 0)
{

l = m + n;
cout << "the sum is =" << l;
}
else
{
cout << "you have entered the negative number";
}
}

else
{
cout << "you have entered the negative number";
}

return 0;
}
........................................................................
#include <iostream>
using namespace std;
int main()
{
int a, b, result, i,count;
cout << "enter the number whose table you want to display";
cout << endl;
cin >> a;
cout << "enter the size of table";
cout << endl;
cin >> i;
for (count = 1; count <= i; count++)
{
result = a*count;

cout << a << "*" << count << "="<<result;
cout << endl;
}
return 0;
}
..........................................................................
#include <iostream>
using namespace std;
int main()
{
cout << "    * \n   ***\n  *****\n   ***\n    *";
return 0;
}

...................................................................
#include <iostream>
using namespace std;
int main()
{
int n, m;
cout << "enter first number";
cin >> n;
    cout<<"enter the second number";
cin >> m;
if (n == m)
{
cout << "n is equal to m";

}
else if (n > m)
{
cout << "n is greater than m";
}
else
{
cout << "n is less than m";
}
return 0;
}
..........................................................................
#include <iostream>
using namespace std;
int main()
{
int a, b=10;
for (a =0;a=b;a++)
{
if (a = b)
{
cout << "a=b";
break;
}
else
{

}
}
return 0;
}
.............................................................................................................
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout << "enter the two numbers" << endl;
cin >> a;
cout << endl;
cin >> b;
while (a >0)
{
if (a ==b)
{
cout << "a is equal to b";
break;
}
else if (a > b)
{
cout << "a is greater than b";
break;
}
else
{
cout << "a is less than b";
break;
}

}
return 0;
}
.......................................................................................................................
#include<iostream>
using namespace std;
int main()
{
int a;
cout << "ENter the number";
cin>> a;
int n = 10;
while (a != n)
{
if (a > n)
{
cout << "Guess a smaller number";
cout << "ENter the number";
cin >> a;

}

else if (a < n)
{
cout << "Guess a larger number";
cout << "ENter the number";
cin >> a;
}
else {
cout << "You have got the number";
break;
}
}
return 0;

}
............................................................................
#include <iostream>
using namespace std;
int main()
{
int array[2];
int size=0;
cin >> size;
array[size];
int sum = 0;
for (int i = 0; i < size; i++)
{
cin >> array[i];
}
for (int i = 0; i < size; i++)
{
sum = sum + array[i];
}
cout << sum;
return 0;
}
...................................................................
#include <iostream>
using namespace std;
int main()
{
int base, exponent,result=1;
cout << "enter the base" << endl;
cin >> base;
cout << "enter expenent" << endl;
cin >> exponent;
for (int i = 1; i <= exponent; i++)
{
result=result*base;
}
cout << result;

return 0;
}
..................................................................................
#include <iostream>
using namespace std;
int main()
{
int A[4] = { 80,15,29,99};
int found = 0;
int b;
cout << "enter the number we want to find";
cin>> b;
for (int i=0;i<4;i++)

if (b == A[i])
{
cout << "number found at" << i;
found = 1;

}

else if(found==0)
{
cout << "number not found";
break;

}
return 0;
}
...........................................................................