Monday, December 1, 2014

C++ fuuction pro & swap Pro



++ program to swap two variables without using third variable or temporary variable

#include
#include
using namespace std;
int main()
{
int var1, var2;
 cout<<"Enter value for first integer:  ";
 cin>>var1;
 cout<<"Enter value for second integer:  ";
 cin>>var2;
 cout<<" Values before swapping:  "<  cout<<"First Integer ="<  cout<<"Second interger ="<               var1=var1+var2;
              var2=var1-var2;
              var1=var1-var2;
 cout<<" Values after swapping:  "<  cout<<"First integer ="<  cout<<"Second interger ="<     return 0;
}

C++ program to find the last prime number before number entered

#include

C++ program to find fibonacci series with simple logic

#include
#include
using namespace std;
int main()
{
int range, first = 0, second = 1, fibonicci=0;
cout << "Enter Range for Terms of Fibonacci Sequence: ";
cin >> range;
cout << "Fibonicci Series upto " << range << " Terms "<< endl;
for ( int c = 0 ; c < range ; c++ )
{
if ( c <= 1 )
fibonicci = c;
else
{
fibonicci = first + second;
first = second;
second = fibonicci;
}
cout << fibonicci <<" ";
}
return 0;
}

C++ program to swap two numbers using built in swap function in c++ standard library

#include
#include
using namespace std;
void swap()
{
    cout<<"this is my swap";
}
int main()
{
    int firstNum , secondNum;
    cout<<"Enter value for First Number:   ";
    cin>>firstNum;
    cout<<"Enter value for Second Number:  ";
    cin>>secondNum;
    cout<<"\n\n";
    cout<<"Values before calling built in swap function"<
    cout<<"\tFirst  Number = "<
    cout<<"\tSecond Number = "<
     cout<<"\n\n";
     std::swap( firstNum , secondNum );
    cout<<"Values After Calling Bulit in  Swap Function"<
    cout<<"\tFirst Number = "<
    cout<<"\tSecond Number = "<
    return 0;
}      

No comments:

Post a Comment