This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

SEARCH THE BLOG

Showing posts with label programs. Show all posts
Showing posts with label programs. Show all posts

Friday, February 1, 2013

FORLOOP

           Example of countdown using a forloop.


// countdown using a for loop

INPUT-

#include <iostream.h>
int main ()
{
for (int n=10; n>0; n--) 
{
cout << n << ", ";
}
cout << "FIRE!";
return 0;
}

OUTPUT-

10, 9, 8, 7, 6, 5, 4, 3, 2, 1, FIRE!

WHILE LOOP

For example, we are going to make a program to count down      using a while loop:

// custom countdown using while

INPUT-

#include <iostream.h>
int main ()
{
int n;
cout << "Enter the starting number > ";
cin >> n;
while (n>0) {
cout << n << ", ";
 --n;
}
cout << "FIRE!";
return 0;
}

OUTPUT-

Enter the starting number
8
8, 7, 6, 5, 4,
3, 2, 1, FIRE!



C++ PROGRAMS


// operating with variables

INPUT-           


#include <iostream.h>


int main ()
{
// declaring variables:
int a, b;
int result;


// process:
a = 5;
b = 2;
a = a + 1;
result = a - b;


// print out the result:
cout << result;


// terminate the program:
return 0;
}

OUTPUT-  
           4




C++ PROGRAM



             // my second program IN C++

    
    

    INPUT-


#include <iostream.h>


int main ()
{
cout << "Hello World! ";
cout << "I'm a C++ program";
return 0;
}

OUTPUT-

      Hello World! I'm a C++ program

C++ program



Probably the best way to start learning a programming language is with a program. So here is our first program:


// my first program in C++

INPUT-

#include <iostream.h>


int main ()
{
                cout << "Hello World!";
     retern 0;
    }
    
     OUTPUT-
        
            HELLO WORLD!