Chapter 6:
Looping Structures
Programming Exercise
Problem # 33:
Write a program to generate all possible combinations of 1, 2, 3 and 4.
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i, j, k, l;
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
for(k=1;k<=4;k++)
{
for(l=1;l<=4;l++)
cout<<i<<j<<k<<l<<"\t";
}
}
}
}
#include<conio.h>
using namespace std;
int main()
{
int i, j, k, l;
for(i=1;i<=4;i++)
{
for(j=1;j<=4;j++)
{
for(k=1;k<=4;k++)
{
for(l=1;l<=4;l++)
cout<<i<<j<<k<<l<<"\t";
}
}
}
}
Let me know in the comment section if you have any question.
Previous Post:
32. Program to calculate sum of the following series using for and do while loop: 1/3 + 3/5 + 5/7 + ... + 97/99
Comments
Post a Comment