Navigation Bar

Showing posts with label loop. Show all posts
Showing posts with label loop. Show all posts

Program Generate all possible combinations of 1, 2 & 3



#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
int a,b,c;
cout<<”All possible combinations are as: “;
for (a=1;a<=3;a++)                                                                                                            
{                   
for (b=1;b<=3;b++)
{
for (c=1;c<=3;c++)
{
                               cout<<a<<" "<<b<<" "<<c<<endl;
}
}
}
getch();
}


Output


All possible combinations are as:
1 1 1       1 2 1       1 3 1
1 1 2       1 2 2       1 3 2
1 1 3       1 2 3       1 3 3

2 1 1       2 2 1       2 3 1
2 1 2       2 2 2       2 2 2
2 1 3       2 2 3       2 3 3


3 1 1       3 2 1       3 3 1
3 1 2       3 2 2       3 3 2
3 1 3       3 2 3       3 3 3

Programe read input and print its table up to giver limit



#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
long n, l, i;
cout<<"Enter the Number: ";
cin>>n;
cout<<"Enter limit: ";
cin>>l;
for (i=1;i<=l;i++)
{
cout<<n<<"*"<<i<<"="<<n*i<<endl;
}
getch();
}

Output


Enter the Number: 7
Enter limit: 4
7*1=7
7*2=14
7*3=21
7*4=27

Transpose the value by using while loop



#include<conio.h>
#include<iostream.h>
void main()
{

clrscr();
int n,a;
cout<<"Enter number: ";
cin>>n;
cout<<”Transpose of number is: ”;
while (n>0)
{
a=n%10;
n=n/10;
cout<<a;
}
getch();
}

Output


Enter number: 7890
Transpose of number is: 0987