C++ Conditional Operator Example
C++ Conditional Operator Example
Symbol - ?
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter the value of a and b is:"<<endl;
cin>>a>>b;
c=a>b?a:b;
cout<<"The value of c is:"<<c<<endl;
getch();
}
While program
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
clrscr();
cout<<"Enter the value of a is:"<<endl;
cin>>a;
while(a<=10)
{
cout<<"santhosh"<<endl;
a++;
}
getch();
}
Do while program
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
clrscr();
cout<<"Enter the value of a is:"<<endl;
cin>>a;
do
{
cout<<"santhosh"<<endl;
a++;
}
while(a<=10);
getch();
}
For program
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
cout<<"Enter the value of n is:"<<endl;
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"santhosh"<<endl;
}
getch();
}
0 Comments