Vous êtes sur la page 1sur 5

/*This is a simple C++ Program

I call this file as sample.cpp


*/

#include <iostream>---------- header file
#include "conio.h"---------- old c header

using namespace std; -------
(
int main () --- function
{ (START OF FUNCTION)
cout<< "C++ is a powerful programming.";


getch();
return 0;
} (END OF FUNCTION)

//- commet single line
Breakpoint- program will stop
\n to create new line
\t tab

// Second simple program. using a variable.

#include <iostream>
#include "conio.h"

using namespace std;

int main ()
{
int length; ------ declares variable

length = 7; ------ this assign 7 to length

cout<< "The length is ";
cout<< length; ---- this displays 7


getch();
return 0;

}
DOUBLE --- with decimal













// Second simple program. using a variable.

#include <iostream>
#include "conio.h"

using namespace std;


int main ()
{
int length;
int width;
int area;

length=7;
width=5;

area= length * width;

cout<< "The area is " << area;

getch();
return 0;
}

int main ()
{
double feet;
double meter;

cout<< "Enter the length in feet: ";
cin>> feet;

cout<< "\n";

meter = feet/3.28;

cout<< "The length in meter is ";
cout<< meter;

getch();
return 0;
}







#include <iostream>
#include "conio.h"

using namespace std;

int main ()
{
double farenheit;
double centigrade;

cout<< "Enter the temperature in farenheit: ";
cin>> farenheit;

cout<< "\n";

centigrade = 5*(farenheit-32)/9;

cout<< "The temperature in centigrade is ";
cout<< centigrade;

getch();
return 0;
}
#include <iostream>
#include "conio.h"

using namespace std;

int main ()
{
int x, y;

cout<< "Enter x number: ";
cin>> x;

cout<< "Enter y number: ";
cin>> y;

if (x>y)
cout << x << "is greather than " << y;

if (x<y)
cout << x << "is less than " << y;

if (x==y)
cout << x << "is equal to " << y;


getch();
return 0;
}







FOR LOOP:
#include <iostream>
#include "conio.h"

using namespace std;

int main ()
{
int count;

for(count=0; count<10; count++)
{
cout<< "line by line\n";
}

getch();
return 0;
}

FOR LOOP:
#include <iostream>
#include "conio.h"

using namespace std;

int main ()
{
double f, m;
int counter = 0;
for ( f = 1.0; f<=100; f++)
{
m = f/3,28;

cout<< f << "feet is" << m << "meters\n";

counter++;

//every 10th line, print blank line
if (counter==0)
{
cout<< "\n";
counter = 0;
}
}

getch();
return 0;
}

Vous aimerez peut-être aussi