Saturday, June 13, 2015




Q 1:- a) Write a function in C++ which take an array, its size and number to be searched with in array, the function should determine how many time the number is repeated in array.
For example let an array A as follows
10
2
8
2
11
29
21
2
11
Find_times (A, 9, 2); should return 3,
Find_times (A, 9, 8); should return 1;
b) The intersection of two sets is the common elements presented in those sets for example
let A={1,9,5,4,8} and B={8,10,6,14} are two sets ,their intersection will be {1,4,8}
Write a program in c++ having two array A and B, both arrays represent sets;
Find and print the intersection of these arrays.
Q:-2 a) write a piece of code to find the two maximum values with in two dimensional array of integers.
b) A palindrome is an array which is read as same from front and back like 12321 ,tibit etc.
Write a program in C++ to find whether a given array is palindrome or not .
Q 3:- a) Write a code in c++ which to print following sequence N=7;
         
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
                            

b)   Write a function in c++ to find a digit sum of an integer (e.g let N=21934 digit sum of N=2+1+9+3+4=19.)

Tuesday, May 5, 2015

Programe for reversing integer in c++

 #include<iostream>
using namespace std;

int main() {
int number, reverse = 0;
cout<<"Input a Number to Reverse and press Enter: ";
 cin>> number;     // Taking Input Number in variable number

   while(number!= 0)
   {
      reverse = reverse * 10;
      reverse = reverse + number%10;
      number = number/10;
   }
   cout<<"New Reversed Number is:  "<<reverse;
   return 0;

}

Sunday, April 19, 2015

C++ Programming

Use of sizeof()

This function is used for finding the size of any variable include array ,structure and class .

Syntax:

if we want to find the size of integer variable :

int a,b;
b=10;
a=sizeof(b);
cout<< b <<endl ;

or
cout <<sizeof(b)<<endl;

if we want to find the size of general data type :

cout<<sizeof(int)<<endl;
cout<<sizeof(float)<<endl;
cout<<sizeof(bool)<<endl;

OOP using c++

Pass by Reference Function Example

#include<iostream>//for cin and cout objects
using namespace std;//definition of cin and cout object lies in std namespace
void swap(int &a,int&b)//function prototype

//use address operator (this operator return the memory address of variable)
{
int temp;
temp=a;
a=b;
b=temp;
}
void main()
{
int x=2;
int y=4;
swap(x,y);
cout << x << endl ;
cout << y << endl ;
        system("pause");
}