Q. How to Solve this Program ..... 1234 , 1324 ..... using C++ Progarmming language

How to Make this pattern using C++ Programming?
Pattern is ... 1234 ...1243....1324....1342,,,,,,,,,,3214 and so on 

Explanation of Program code:

The first thing you should for is to include the library files like iostream or iostream.h in older versions.These files are necessary for in order to go for input and output streams in program code. By Input and output streams i mean cout and cin. Cout is for output stream and Cin is for input stream.Similarly you also have to add conio.h or if you don't want to use this file you can go for return 0; statement at the end of program code.

After this all you need is to define main function which is necessary part of every C++ program.Now the second thing you have to do is to define array of data type integer type and array size of four and also define the members of array.This is actually array initialization.

Then you have to define four integers variables to have access to each member of array independently.These variables are as x,y,z,u in my program.You named them according to your choice.Then you have to go to use for loops and nested for loops if you do not know to how to use for loops read this recommended article given below. Then you can understand this program easily because this is main thing otherwise rest is simple , the operators like and ,  not equal to can understand easily

Recommended Article:



Program Code:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a[4]={1,2,3,4};

int x,y,z,u;
x=a[0];
y=a[1];
z=a[2];
u=a[3];

for (int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
for (int k=0;k<4;k++)
{
for(int p=0;p<4;p++)
{
if (i!=j&&i!=k&& i!=p && k!=p && j!=p && j!=k)
cout<<a[i]<<a[j]<<a[k]<<a[p]<<"    ";
}
}
}
}

getch();
}


Output: After compile and run , the output of program will be like this...




1 comment:

  1. So basically this is a program for finding out all the possible combinations of a number... or anagrams of a word...
    Nice one.

    However, it would be better to arrange the code (indentation) for clarity.

    8051 Microcontroller Programming Blog

    ReplyDelete

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.