Monday, 27 August 2012
Friday, 10 August 2012
Lecture: 137
Lecture 137
// Loop GoTo
#include
<iostream>
#include
<conio.h>
using
namespace std;
main ()
{
int i;
i=1;
cout<<"Odd number:
";
Loop1: //Label
cout<<i<<" ";
i+=2;
if(i>=10)
goto Loop2;
goto Loop1;
Loop2:
getch();
return 0;
}
Output:
Code:
// Loop GoTo
#include
<iostream>
#include
<conio.h>
using
namespace std;
main ()
{
int i;
i=1;
cout<<"Odd number:
";
Loop1: //Label
cout<<i<<" ";
i+=2;
if(i==10)
goto Loop2;
goto Loop1;
Loop2:
getch();
return 0;
}
Output:
Thursday, 9 August 2012
Monday, 6 August 2012
Sunday, 5 August 2012
Lecture 133
Lecture 133
// Loop do while
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
main ()
{
int x,y;
y=1;
do
{
x=1;
do{
if(x==y)
cout<<"\xDB";
else
if(x==2*y)
cout<<"\xB1";
else
cout<<" ";
x++;
}while(x<24);
cout<<endl;
y++;
}while(y<24);
getch();
return 0;
}
Output:
Lecture 132
// Loop do while
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
main ()
{
int x,y;
y=1;
do
{
x=1;
do{
if(x==y)
cout<<"\xDB";
else
if(x==24-y)
cout<<"\xDB";
else
cout<<"\xB0";
x++;
}while(x<24);
cout<<endl;
y++;
}while(y<24);
getch();
return 0;
}
Output:
Saturday, 4 August 2012
Friday, 3 August 2012
Lecture 130
Lecture 130
// Loop do while
//Draws a checkerboard on the screen
#include <iostream>
#include <conio.h>
using namespace std;
main ()
{
int x,y;
y=1;
do
{
x=1;
do
{
if((x+y)%2==0)
cout<<"\xDB\xDB";
else
cout<<" ";
x++;
}while(x<9);
cout<<endl;
y++;
}while(y<9);
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Thursday, 2 August 2012
Lecture 129
Lecture 129
// Loop do while
#include
<iostream>
#include
<conio.h>
using
namespace std;
main ()
{
int charcnt=0;
int wordcnt=0;
char ch;
cout<<"Type in a phrase:
\n";
do
{
charcnt++;
if(ch==' ')
wordcnt++;
}while((ch=getche()) != '\r');
cout<<"\nCharacter count is
:"<<charcnt;
cout<<"\nWord count is :
"<<wordcnt;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Wednesday, 1 August 2012
Subscribe to:
Posts (Atom)