Saturday 20 December 2014

Find Armstrong number in C++

#include<iostream>
  using namespace std;
  int main()
  {
  int armstrong=0,num=0,result=0,check;
  cout<<"Enter Number to find it is an Armstrong number?";
       cin>>num;
       check=num;
       for(int i=1;num!=0;i++){
           armstrong=num%10;
           num=num/10;
           armstrong=armstrong*armstrong*armstrong;
           result=result+armstrong;
       }
       if(result==check){
       cout<<check<<"  is an Armstrong Number";
       }
       else{
       cout<<check<<"  is NOT an Armstrong Number";
       }
       return 0;
    }

Find Palindrome number in c++

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int palindrome, reverse=0;
  6.     cout<<"Enter number:  ";
  7.     cin>>palindrome;
  8.     int num=0,key=palindrome;
  9. for(int i=1;palindrome!=0;i++){

  10.     num=palindrome%10;
  11.     palindrome=palindrome/10;
  12.     reverse=num+(reverse*10);
  13.               }

  14.    if(reverse==key){
  15.    cout<<key<<" is a Palindrome Number";
  16.             }
  17.             else{
  18.    cout<<key<<"is NOT a Palindrome Number";
  19.             }
  20. return 0;
}

C++ program to find Fibonacci Series

  • #include<iostream>
  •     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;

  •     }
  • Find last prime number occur before enter number


    #include<iostream>
    using namespace std;
    int main()
    {
     int num,count=0;
     cout<<"Enter number to find last prime number occurs before it: ";
     cin>>num;
      for( int a=num-1;a>=1;a--)
      {
       for(int b=2;b<a;b++)
          {
           if(a%b==0)
           count++;
           }
           if(count==0)
           {
          if(a==1)
           {
           cout<<"no prime number less than 2";
           break;
         }
          cout<<a<<" is the last prime number before entered number";
           break;
           }
           count=0;
    }
    return 0;
    }

    Friday 19 December 2014

    C++ program to swap the values of two integers

    #include<iostream>

    using namespace std;

    int main()

    {

    int var1, var2, swap;

     cout<<"Enter value for first integer:  ";

     cin>>var1;

     cout<<"Enter value for second integer:  ";

     cin>>var2;

     cout<<" Values Before swapping:  "<<endl;

     cout<<"First Integer ="<<var1<<endl;

     cout<<"Second Interger ="<<var2<<endl;

                  swap=var1;

                  var1=var2;

                  var2=swap;

     cout<<" Values After swapping:  "<<endl;

     cout<<"First Integer ="<<var1<<endl;

     cout<<"Second Interger ="<<var2<<endl;

     return 0;

    }

    Thursday 18 December 2014

    C++ program to find greatest number between three numbers

    1. #include<iostream>
    2. using namespace std;
    3. int main()
    4. {
    5. int num1,num2,num3;
    6. cout<<" Enter value for first number";
    7. cin>>num1;

    8. cout<<" Enter value for second number";
    9. cin>>num2;

    10. cout<<" Enter value for third number";
    11. cin>>num3;
    12. if(num1>num2&&num1>num3)
    13. {
    14. cout<<" First number is greatest:"<<endl<<"whick is= "<<num1;
    15. }
    16. else if(num2>num1&&num2>num3)
    17. {
    18. cout<<" Second number is greatest"<<endl<<"whick is= "<<num2;
    19. }
    20. else
    21. {
    22. cout<<" Third number is greatest"<<endl<<"whick is= "<<num3;
    23. }
    24. return 0;
    25. }

    Program to find factorial of Number in C++

     The factorial of a number 'n' is the product of all number from 1 upto the number 'n'
    it is denoted by n!.  For example n=5 then factorial of 5 will be 1*2*3*4*5= 120. 5!= 120
    Factorial program C++ Logic:
    • First think what is the factorial of a number? How mathematically it can be calculated.
    •  If you got this info then it will be very easier to make a C++ Program logic to find the factorial.
    •  User enters a number and we have to multiply all numbers upto entered number.
    • Like if user enters 6  then Factorial should be equal to factorial= 1*2*3*4*5*6.
    • In this case a for Loop will be very helpful. It will start from one and multiply all numbers upto entered number after it loop will be terminated.
    • Take a variable and initialized it to 1 and in loop store multiplication result into it like in below program a variable 
    • Factorial is used for this purpose.what is we does not initialized it to 1 and initialized it to zero or remain it uninitialized. In case of 0 our result will be zero in case of any number entered
    • In case of not initializing it our answer will correct mostly but if variable contains garbage value then we will not be able to get correct result. 
    • It is recommended that to initialize it to one.
    #include<iostream>

    using namespace std;

    int main()

    {

        int num,factorial=1;

        cout<<" Enter Number To Find Its Factorial:  ";

        cin>>num;

        for(int a=1;a<=num;a++)

        {

            factorial=factorial*a;

        }

    cout<<"Factorial of Given Number is ="<<factorial<<endl;

        return 0;

    }

    FIND PRIME NUMBER IN C++

    What is a PRIME NUMBER?

    " A Natural number greater than 1 which has only two divisor 1 and itself is called prime number ".
    For Example:  

    5 is prime, because it has only two divisors 1 and itself.

    1. #include<iostream.h>
    2. #include<conio.h>
    3.         void main()
    4.         {
    5.          //clrscr();
    6.          int number,count=0;
    7. cout<<"ENTER NUMBER TO CHECK IT IS PRIME OR NOT ";
    8.           cin>>number;
    9.            for(int a=1;a<=number;a++)
    10.                {
    11.                 if(number%a==0)
    12.                    {
    13.                   count++;
    14.                    }
    15.                }
    16.        if(count==2)
    17.          {
    18.           cout<<" PRIME NUMBER \n";
    19.          }
    20.        else
    21.          {
    22.           cout<<" NOT A PRIME NUMBER \n";
    23.          }
    24.        //getch();
    25.        }

    FIND THE PERFECT NUMBER IN C++

    What is a perfect number?
    "Perfect number is a positive number which sum of all positive divisors excluding that number.
    For example 6 is Perfect Number since divisor of 6 are 1, 2 and 3. Sum of its divisor is
    1 + 2+ 3 =6
    and  28 is also a Perfect Number
     since 1+ 2 + 4 + 7 + 14= 28

    Other perfect numbers: 496, 8128

    1. #include<iostream.h>
    2. #include<conio.h>
    3. void main()                 //Start of main
    4. {
    5.   clrscr();
    6.    int i=1, u=1, sum=0;
    7.    while(i<=500)
    8.  {                                  // start of first loop.

    9.    while(u<=500)
    10.    {                               //start of second loop.
    11.      if(u<i)
    12.      {
    13.       if(i%u==0 )
    14.       sum=sum+u;
    15.      }                          //End of if statement
    16.     
    17.      u++;
    18.    }                           //End of second loop

    19.    if(sum==i)
    20.    {
    21.     cout<<i<<" is a perfect number."<<"\n";
    22.    }

    23.    i++;
    24.    u=1;  sum=0;
    25.  }                             //End of First loop
    26.    getch();
    27.  }                            //End of main

    Wednesday 16 July 2014

    Intro to C

    Every full C program begins inside a function called "main". A function is simply a collection of commands that do "something". The main function is always called when the program first executes. From main, we can call other functions, whether they be written by us or by others or use built-in language features. To access the standard functions that comes with your compiler, you need to include a header with the #include directive. What this does is effectively take everything in the header and paste it into your program. Let's look at a working program:
    #include <stdio.h>
    int main()
    {
        printf( "I am alive!  Beware.\n" );
        getchar();
        return 0;
    }
    
    Let's look at the elements of the program. The #include is a "preprocessor" directive that tells the compiler to put code from the header called stdio.h into our program before actually creating the executable. By including header files, you can gain access to many different functions--both the printf and getchar functions are included in stdio.h. 

    The next important line is int main(). This line tells the compiler that there is a function named main, and that the function returns an integer, hence int. The "curly braces" ({ and }) signal the beginning and end of functions and other code blocks. If you have programmed in Pascal, you will know them as BEGIN and END. Even if you haven't programmed in Pascal, this is a good way to think about their meaning. 

    The printf function is the standard C way of displaying output on the screen. The quotes tell the compiler that you want to output the literal string as-is (almost). The '\n' sequence is actually treated as a single character that stands for a newline (we'll talk about this later in more detail); for the time being, just remember that there are a few sequences that, when they appear in a string literal, are actually not displayed literally by printf and that '\n' is one of them. The actual effect of '\n' is to move the cursor on your screen to the next line. Notice the semicolon: it tells the compiler that you're at the end of a command, such as a function call. You will see that the semicolon is used to end many lines in C. 

    The next command is getchar(). This is another function call: it reads in a single character and waits for the user to hit enter before reading the character. This line is included because many compiler environments will open a new console window, run the program, and then close the window before you can see the output. This command keeps that window from closing because the program is not done yet because it waits for you to hit enter. Including that line gives you time to see the program run. 

    Finally, at the end of the program, we return a value from main to the operating system by using the return statement. This return value is important as it can be used to tell the operating system whether our program succeeded or not. A return value of 0 means success. 

    The final brace closes off the function. You should try compiling this program and running it. You can cut and paste the code into a file, save it as a .c file, and then compile it. If you are using a command-line compiler, such as Borland C++ 5.5, you should read the compiler instructions for information on how to compile. Otherwise compiling and running should be as simple as clicking a button with your mouse (perhaps the "build" or "run" button). 

    You might start playing around with the printf function and get used to writing simple C programs.

    Wednesday 4 June 2014

    How Can I Optimize My META Description - WordPress

     I’m glad you asked! Finally, we’ll get to those Conditional WordPress Tags I talked about earlier. Here is the code below:

    <meta name=”description” content=”<?php if (have_posts() && is_single() OR is_page()):while(have_posts()):the_post();
    $out_excerpt = str_replace(array(“\r\n”, “\r”, “\n”), “”, get_the_excerpt());
    echo apply_filters(‘the_excerpt_rss’, $out_excerpt);
    endwhile;
    elseif(is_category() OR is_tag()):
    if(is_category()):
    echo “Posts related to Category:
    “.ucfirst(single_cat_title(“”, FALSE));
    elseif(is_tag()):
    echo “Posts related to Tag:
    “.ucfirst(single_tag_title(“”, FALSE));
    endif;
    else: ?><?php bloginfo(‘description’) ?>
    <?php endif; ?>” />

    Install this code in between your WordPress site’s <head></head> section in the ‘header.php’ file. Basically, this code will do a couple things.

    If the search engine/user views your site’s individual pages or categories, the conditional WordPress tags kick in and tell the browser/webcrawler to grab the opening excerpt of your post/page and use that as the META Description tag.
    If the search engine/user lands on the homepage, it will tell the browser/webcrawler to display the default Blog Description (which you specify on the ‘Settings’ page) as your META Description.

    Tuesday 3 June 2014

    Claim Google Authorship for Your WordPress Website

    Hopefully you’ve already caught the importance of Google Authorship, the mechanism by which Google’s search engine rankings can be influenced byAuthor Rank.

    If you haven’t, Google Authorship basically amounts to the biggest shakeup in search since the link. It’s Google’s way of identifying the author of a piece of content to factor it as a signal of content quality.
    We realize that most writers and online publishers don’t have tons of time to sift through excessively geeky posts involving underlying website code (rel= “author” or rel=”me” anyone?).
    Also, the process up until this point has been confusing, to say the least. Now, that tedious code and confusion is not necessary.

    Easily Claim Google Authorship with the Genesis Framework for WordPress

    It’s a truly exciting time for online writers because high-value content that attracts, entertains, informs, and engages enhances the author’s authority, instead of only page or site authority. This in turn will kick in the Author Rank effect, which are search signals that are directly associated with you.
    If you’re using WordPress, you’re hopefully already running the newest version (3.5) on your site. Our StudioPress division just released a new version of the Genesis Framework for WordPress with a similarly streamlined feel.
    Now, with the beautiful designs, SEO benefits, and added security of Genesis also comes an effortless connection to Google Authorship.
    We’ve made it very easy to get Google to associate your content with your Google+ profile. Here’s how.

    How to Setup Google Authorship in 3 Easy Steps 

    1. Add Your Google+ Profile Link
    Go to the edit user screen (and to your profile, if you have multiple authors) in your WordPress dashboard and scroll down until you see the option box for your Google+ profile link. Copy your Google+ profile link and paste it into the Google+ option box. Here’s my Google+ profile link, to give you the right idea:

    2. Add a Google+ Contributor Link
    Now you’ll need to add a reciprocal link back from your Google+ profile to the site(s) you just updated. You can do this by going to your Google+ profile page, and editing the “Contributor To” section.
    In the dialog that appears, click “Add custom link”, and then enter your website URL. 
    3. Test Your Google Authorship Connection
    Finally, you’ll want to test that you accomplished the first two steps properly.
    Thankfully, Google has provided a Structured Data Testing Tool to do the checking for you.


    Thursday 29 May 2014

    CSS3: Viewport Units

    Developing web designs that adjust to the width or – if needed – the height of a browser window is easy with percentage-based values. You will probably be doing this on a daily basis, optimizing your website for tablets and smartphones. No matter the element, text blocks, images, everything adjusts to the size given.

    But using percentage-based values is not always the best way to define sizes in relation to the browser window. Think of font sizes. A font size cannot be defined to react to a changing width of the browser window, at least not percentage-based. CSS3 introduces new units that explicitly address this problem.

    Viewport Units for More Flexible Size Definitions

    The units „vw“ and „vh“ define a width/height relative to the window size. We use „vw“ for „view width“ and „vh“ for „view height“. These so-called viewport units allow us to define sizes in relation to the recent size of the browser window.

    div {
      width: 50vw;
      height: 100vh;
    }

    Our example element will take up 50% of the window width and 100% of the window height. While percentage-based values always relate to their parent element, viewport units always relate to the window size. It is even possible to define heights in relation to width and vice versa.


    div {
      height: 50vw;
    }

    Our example defines the height of the element to be 50% of the window width. Scaling down the window width alters the element’s height.

    Universal Font Size Fits Due to Viewport Units

    If you want to secure a decent typography, you will want to make sure, that fonts are displayed in acceptable sizes, no matter the device it’s being displayed on. Especially large headlines need to be taken care of, to avoid having them look horrible. Use viewport units to define your font in relation to the width of the browser window.


    h1 {
      font-size: 10vw;
    }

    Our example defines the font size to be 10% of the window width. Thanks to „vw“, the font size, defines for „h1“ will now always adjust to the browser window.

    Define Sizes Depending on The Aspect Ratio

    To add to the units „vw“ and „vh“, we got the units „vmin“ and „vmax“.With „vmin“ we define a size either in relation to the window height or in relation to the window width, depending on which value is smaller. I s the width smaller than the height, „vmin“ will relate to the width. You can imagine what „vmax“ does. Yup, the same, only in relation to the higher value.

    div {
      width: 2vmin;
    }

    In this example our element will receive a width of 20% of the window width while the window width is smaller than the height. Is the height smaller than the width, the element will be defined as being 20% of the window height. It’s easy, once you played around with it a bit.

    Browser Support

    You won’t believe it, but viewport units are supported by all major browsers. Even the Internet Explorer is able to properly work with them, from version 10 onwards, at least. Firefox added support from version 19, Chrome from version 20.

    Thursday 15 May 2014

    How to Disable Right Click and Protect Your Blog Content from Copy Cats

    Blogpost content copied/stolen by other blogger is one thing that must be faced by every blogger. This often makes us angry because our works is stolen without permission, however, we can still be able to minimize it. Here, I want to give you tips how to disable right click andprotect your blog content, so, your contents will be more difficult to be copied. Indeed, there will be always a way to outsmart these tricks.
    protect your blog content

    This is how to protect your blog content from copy cats: (I will give you 2 ways)

    First:

    1. Login to your blog, we will edit our blog template, go to layout -> edit HTML.
    2. Find <body> and replace with this script: <body oncontextmenu=’return false;’ onkeydown=’return false;’ onmousedown=’return false;’>
    3. Finish.
    It’s easy right? Here is the explanation for the HTML functions.
    oncontextmenu=’return false;’  –> it is to disable right click.
    onkeydown=’return false;’  –> it is to disable keyboard keys (CTRL+A, CTRL+U, etc…)
    onmousedown=’return false;’   –> it is to disable mouse selection.
    ‘return false’   –> It is to disable function you want.
    From three functions above, you can use 1, 2 or all. And this first method is great but it can be outsmarted by disabling javascript in browser. So, you need to add the second method to your blog.

    Second

    1.  Go to layout -> edit HTML and find </head>.
    2. Then add this script above </head>
    1
    2
    3
    4
    5
    6
    
    <script type='text/javascript'>
    if (top.location != self.location) top.location.replace(self.location);
    </script>
    <script type='text/javascript'>
    document.ondragstart = function(){return false;};
    </script>
    3. After that, add this script below <body>  (if you have used the first way, then just add below/after <body oncontextmenu=’return false;’ onkeydown=’return false;’ onmousedown=’return false;’>)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    
    <div align='center'><noscript>
       <div style='position:fixed; top:0px; left:0px; z-index:3000; height:100%; width:100%; background-color:#FFFFFF'>
       <div style='font-family: Tahoma; font-size: 14px; background-color:#FFF000; padding: 10pt;'>To see this page as it is meant to appear, we ask that you please enable your Javascript!</div></div>
    </noscript></div>
    <script type='text/javascript'>
    function mousedwn(e) {
    try { if (event.button == 2||event.button == 3) return false; }
    catch (e) { if (e.which == 3) return false; }
    }
        document.oncontextmenu = function() { return false; }
        document.ondragstart   = function() { return false; }
        document.onmousedown   = mousedwn;
    </script>
    <style type='text/css'>
    * : (input, textarea) {
     
     
        -webkit-touch-callout: none;
        -webkit-user-select: none;
    }
     
     
    img {
            -webkit-touch-callout: none;
            -webkit-user-select: none;        
        }
    </style>
     
     
    &lt;script type='text/javascript'&gt;
    window.addEventListener(&quot;keydown&quot;,function (e) {
        if (e.ctrlKey &amp;&amp; (e.which == 65 || e.which == 67 || e.which == 85 || e.which == 80)) {
            e.preventDefault();
        }
    })
            document.keypress = function(e) {
            if (e.ctrlKey &amp;&amp; (e.which == 65 || e.which == 67 || e.which == 85 || e.which == 80)) {
        }
            return false;
                    };
    &lt;/script&gt;
    If you only use this second method, your visitors still can be able to do right click, CTRL+A and click copy, however, it can’t be pasted. And that script also has ability to protect your blog from copypaste although the javascript is disabled. Because your visitor will be forced to enable their browser javascript. But, for me, I recommend you to use both of these methods.
    protect blog from copy paste
    Well, above are two easy methods you can use and try for your blog. I have tested and used above methods in this testing blog: http://valentinesdaygiftsz.blogspot.com/. It’s so easy. Hopefully now you can protect your blog from copy cats. Happy blogging!