Program to print combination of 3 and 4

Program to print combination of 3 and 4

Question:

Write a program to print the combination of given two numbers ie, 3 and 4.

Logic:

  • Get the number of combinations from the user.
  • Find the length of the combination values.
  • Then calculate the values using some formulas.
  • And print the output values.

Algorithm:

  1. Get the number of combinations from the user.
  2. Find the length by using power function and gives the length of the array.
  3. Then the values are found by multiplying the previous number with 10.
  4. And add the numbers ie, 3 and 4 then store into the array.
  5. Then print the array values.

Program:

#include<stdio.h>
#include<math.h>
void main()
{
	int n,k=1,i,d=0;
	int a[100];
	a[0]=3,a[1]=4;//assign values of 3 and 4 into array
	clrscr();
	printf("enter the number of combinations:");
	scanf("%d",&n);
	d=power(n);//function that returns sum of all 2 power 1...n and stores in d
	for(i=0;i<d-2;i++)
	{       k++;//increments the position in array
		/* gives all combination of numbers by multiplying 10 and addition of 3&4*/
		a[k]=(a[i]*10)+3;
		k++;
		a[k]=(a[i]*10)+4;
	}
	for(i=0;i<d;i++)//prints the combinatioinal values
	{
		printf("%d ",a[i]);
	}
	getch();
}
int power(int x)//function that defined for finding length
{
	if(x!=0)
	{
		return pow(2,x)+power(x-1);
	}
}

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Vignesh

A Computer Science graduate who likes to make things simpler. When he’s not working, you can find him surfing the web, learning facts, tricks and life hacks. He also enjoys movies in his leisure time.
0 0 votes
Article Rating
Subscribe
Notify of
guest
5.4K Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
5.4K
0
Would love your thoughts, please comment.x
()
x