51. Example of Name Space
Answer :
#include<iostream.h>
#include<conio.h>
name space n1
{
int m = 10;
}
name space n2
{
int m = 100;
}
Void main()
{
int m=300;
cout<<"m="<<m;
cout<<"m="<<n1 :: m;
cout<<"m="<<n2 :: m;
using namespace n1;
cout<<"m="<<m;
getch();
}
...................................................................................................................................................................
52. Example of Nested Loop
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=-3; i++) //for rows
{
for(j=1; j<=3; j++) //for columns
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
53. Write a Program for print this
4 3 2 1
4 3 2 1
4 3 2 1
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=3; i++)
{
for(j=4; j>=1; j--)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
54. Write a Program for Print this
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=4; i++)
{
for(j=1; j<=9; j=j+2)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
55. Example of Classes in C++
Answer :
#include<iostream.h>
#include<conio.h>
class student
{
int rn;
char nm[20];
public:
Void input()
{
cout<<"Enter Roll No:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
}
Void show()
{
cout<<"rn:"<<rn;
cout<<"name:"<<nm;
}
};
Void main()
{
student Amit;
Amit.input();
Amit.show();
getch();
}
Answer :
#include<iostream.h>
#include<conio.h>
name space n1
{
int m = 10;
}
name space n2
{
int m = 100;
}
Void main()
{
int m=300;
cout<<"m="<<m;
cout<<"m="<<n1 :: m;
cout<<"m="<<n2 :: m;
using namespace n1;
cout<<"m="<<m;
getch();
}
...................................................................................................................................................................
52. Example of Nested Loop
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=-3; i++) //for rows
{
for(j=1; j<=3; j++) //for columns
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
53. Write a Program for print this
4 3 2 1
4 3 2 1
4 3 2 1
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=3; i++)
{
for(j=4; j>=1; j--)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
54. Write a Program for Print this
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
1 3 5 7 9
Answer :
#include<iostream.h>
#include<conio.h>
Void main()
{
int i,j;
for(i=1; i<=4; i++)
{
for(j=1; j<=9; j=j+2)
{
cout<<j<<" ";
}
cout<<"\n";
}
getch();
}
...................................................................................................................................................................
55. Example of Classes in C++
Answer :
#include<iostream.h>
#include<conio.h>
class student
{
int rn;
char nm[20];
public:
Void input()
{
cout<<"Enter Roll No:";
cin>>rn;
cout<<"Enter Name:";
cin>>nm;
}
Void show()
{
cout<<"rn:"<<rn;
cout<<"name:"<<nm;
}
};
Void main()
{
student Amit;
Amit.input();
Amit.show();
getch();
}
0 comments:
Post a Comment