C++ Programming Language: by Knowledge flow by Knowledge flow

C++ Programming Language: by Knowledge flow by Knowledge flow

Author:Knowledge flow [flow, Knowledge]
Language: eng
Format: epub, pdf
Publisher: Knowledge flow
Published: 2015-03-05T22:00:00+00:00


for loop Statement

Syntax

for(initialization; condition; increment)

Program

#include <iostream.h>

using namespace std;

int main(void)

{

int i;

for(i= 1;i<5;i++)

{

cout << "run for loop at: " << i << " :times" << endl;

}

}

Result

run for loop at: 1 :times

run for loop at: 2 :times

run for loop at: 3 :times

run for loop at: 5 :times

while loop Statement

Syntax

while(condition) statement;

Program

#include <iostream.h>

void main()

{

int n;

cout << "Enter a number > 0:";

cin >> n;

while(n>0)

{

cout <<"Decremented value is:"<< n <<
';

n--;

};

cout << "Enter a valid number" <<'
';

}

Result

Enter a number > 0:4

Decremented value is:4

Decremented value is:3

Decremented value is:2

Decremented value is:1



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.