Thursday, 26 November 2015

Fizz Buzz Program

Write a program that will print all the numbers from 1 to 100 that will print "FizzBuzz", for numbers that are divisible by both 3 and 5 and print "Fizz" for numbers divisible by 3 and "Buzz" for numbers divisible by 5:



for(var i=1; i<=100; i++) {
    if((i % 3 == 0) && (i % 5 == 0)) {
        document.write("FizzBuzz");
        document.write("
");
    }
    else if(i % 3 == 0) {
         document.write("Fizz");
         document.write("
");
     }
    else if(i % 5 == 0) {
        document.write("Buzz");
     document.write("
");
    }
    
    else {
        document.write(i);
        document.write("
");
    }
}

Sunday, 24 May 2015

How To Create a Layout In HTML5

HTML5 layout
Here is a very simple way you can create a new HTML5 layout. This is a responsive layout that means this will fit to any screen. you can check this by decreasing the width of your browser,  this will adjust with the screen. Here we use width as percentage(%), this will adjust the site with your screen.











<!DOCTYPE html>
<html>
<head>
 <style>
            /* Here is the CSS code */
 *
 {
  margin: auto;
 }
 h2
 {
  text-align: center;
  color: #fff;
 }
 header
 {
  width: 100%;
  height: 100px;
  background-color: #400000;
 }
 aside
 {
  width: 30%;
  height: 600px;
  float: left;
  background-color: #660066;
 }
 section
 {
  width: 100%;
  height: 600px;
  background-color: #663399;
 }
 footer
 {
  width: 100%;
  height: 50px;
  background-color: #400000;
  clear: both;
 }
 </style>
</head>
<body>
<!-- This is html code-->
<header>
 <h2>I am Header</h2>
</header>
<aside>
 <h2>Side Bar</h2>
</aside>
<section>
 <h2>Section</h2>
</section>
<footer>
 <h2>Footer</h2>
</footer>
</body>
</html>

Friday, 22 May 2015

Program In C++ to Print Fibonacci Numbers

print Fibonacci numbers in c++
Problem: Write a program in c++ that will print the fibonacci numbers to a limit.

Description: This is another best program in c++ which prints the fibonacci numbers. You have to enter the number till where you want to print the series.



#include<iostream>
#include<cmath>

using namespace std;

int main()
{
   unsigned long a=0,b=1,num;
   unsigned long c=0;
   cout << "Enter the number till where you want fibonacci series...... : ";
   cin >> num;
   cout << endl;
   cout << a << ", ";
   while (c<=num)
   {
      cout << b << ", ";
      c=a+b;
      a=b;  
      b=c;  
   }
   cout << endl << endl;
   system("pause");
   return 0;
}

Write a Program In C++ That Will Convert Roman Number Into Decimal Number

convert roman numbers into decimal numbers
Problem: Write a c++ program that will convert roman numbers into its equivalent decimal numbers.

This program takes a roman number as input and converts into decimal number. please make sure to keep the caps lock on. Run this program in devc++


#include <iostream>
#include <string>

using namespace std;
class RomanNumber
{
private:
        string romanNumber;
        int sum; 

public:

  RomanNumber( string input)
                {
                      romanNumber = input;
                }
  int convert()
                {
                      int length = romanNumber.length();

                      int previous = 0;
                      bool error = false;
                      int nIndex = 0;
                      sum = 0;
                      while( (error == false) && (nIndex < length) )
               {
              switch(romanNumber[nIndex])
              {
                    case 'M':
                             sum += 1000;
                   if(previous < 1000)
                   {
                sum -= 2 * previous;
                   }
                   previous = 1000;
                   break;
                  case 'D':
                   sum += 500;
                   if(previous < 500)
                   {
                 sum -= 2 * previous;
                   }
                   previous = 500;
                   break;
                  case 'C':
                   sum += 100;
                   if(previous < 100)
                   {
                  sum -= 2 * previous;
                   }
                   previous = 100;
                   break;
                 case 'L':
                   sum += 50;
                   if(previous < 50)
                   {
                 sum -= 2 * previous;
                   }
                   previous = 50;
                   break;
                 case 'X':
                   sum += 10;
                   if(previous < 10)
                   {
                   sum -= 2 * previous;
                   }
                   previous = 10;
                   break;
                 case 'V':
                   sum += 5;
                   if(previous < 5)
                   {
                 sum -= 2 * previous;
                   }
                          previous = 5;
                   break;
                 case 'I':
                   sum += 1;
                   if(previous < 1)
                   {
                  sum -= 2 * previous;
                   }
                   previous = 1;
                   break;
                       default:
                            cout << romanNumber[nIndex] << " is not a Roman Numeral!" << endl;
                            error = true;
                            sum = 0;
                 } // switch
                               nIndex++;
                      } // while
                      return sum;
         } 
};

int main()
{
       system("color 1F");
       string myInput;
       cout<<"\n\n\t\t....ROMAN NUMBER TO DECIMAL CONVERTER....\n\n";
       cout<<"\n\n\tEnter your input in Roman Number(Plz Keep Caps Lock On): ";
       cin>>myInput;

       RomanNumber myRomanNumber(myInput);

       int value=myRomanNumber.convert();

       cout << "\n\n\t\tRoman Number " << myInput << " is equals to Decimal " << value <<endl<<endl;

       system("pause");
       return 0; 
}