ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How do I write a program to print proper subset of given 
string . Eg :input: abc
             output:{},{a},{b},{c},{a,b},{a,c},{b,c},
{a,b,c}.I desperately need this program please mail me to 
saravana6m@gmail.com
 Question Submitted By :: A Saravanan
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 1
aa
 
Is This Answer Correct ?    9 Yes 3 No
A
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 2
int combine(char in[])
{
	
	int len;
	char *out;
	len= strlen(in);
	printf("<<<<<<<<Combinations>>>>>>");
	out=(char *)malloc(sizeof(char)*(len+1));
	if(!out)return -1;

	DoCombine(in,out,len,0,0);
	free(out);
	return 1;
}


void DoCombine(char *in, char *out, int len, int 
recLevel,int start)
{
	int i;
	for(i=start;i<len;i++)
	{
		out[recLevel]=in[i];
		out[recLevel+1]='\0';
		printf("\n%s\n",out);
		if(i<len-1)
			
DoCombine(in,out,len,recLevel+1,i+1);
	}
}
 
Is This Answer Correct ?    1 Yes 2 No
Shashanktrip
 
 
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 3
#include<stdio.h>
long pow(long a,long b)     /*finds a power of b*/
  {
long i,j=1;
for(i=1;i<=b;i++)
j*=a;
return j;
  }
long bin(int n)            /*converts into binary equivalent */
  {
long i=0,j=1,r;
while(n)
  {
r=n%2;
i=i+r*j;
n/=2;
j*=10;
  }
return i;
  }
  main()
  {
 char a[25];
 long i,j,k,m,l=0,n=0;
  printf("\nEnter string:");
 scanf("%s",a);
 printf("\nAll possible substrings are:\n");
 while(a[l])
 l++;
 printf("%d)\t{ }\n",++n);
  for(i=1;i<pow(2,l);i++)
 {  k=bin(i);
    m=l-1;
  printf("%d)\t{  ",++n);
  while(m>=0)
  {
    j=k/pow(10,m);
    if(j==1)
  printf("%c",a[l-1-m]);

    k=k%pow(10,m);
  m--;
  }
  printf("\t}\n");
  }
  return 0;
  }
 
Is This Answer Correct ?    3 Yes 0 No
Raghuram.A
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 4
#include<stdio.h>
#include<conio.h>
long pow(long a,long b)     /*finds a power of b*/
  {
long i,j=1;
for(i=1;i<=b;i++)
j*=a;
return j;
  }
long bin(int n)            /*converts into binary equivalent */
  {
long i=0,j=1,r;
while(n)
  {
r=n%2;
i=i+r*j;
n/=2;
j*=10;
  }
return i;
  }
  main()
  {
 char a[25];
 long i,j,k,m,l=0,n=0;
  printf("\nEnter string:");
 scanf("%s",a);
 printf("\nAll possible substrings are:\n");
 while(a[l])
 l++;
 printf("%d)\t{ }\n",++n);
  for(i=1;i<pow(2,l);i++)
 {  k=bin(i);
    m=l-1;
  printf("%d)\t{  ",++n);
  while(m>=0)
  {
    j=k/pow(10,m);
    if(j==1)
  printf("%c",a[l-1-m]);

    k=k%pow(10,m);
  m--;
  }
  printf("\t}\n");
  }
 getch();
  return 0;
  }



 
Is This Answer Correct ?    4 Yes 0 No
Raghuram.A
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 5
#include <iostream>
#include <string>
using namespace std;
#include<math.h>

int main(int argc, char* argv[])
{
	char input[100];

	cout<<"input a string:"<<endl;
	gets(input);
	cout<<input<<endl;
	int strLen = strlen(input);
	int count = pow(2.0,strLen);
	string *str = new string[count];
	int num=0;
	cout<<"{}"<<endl;
	for(int i=0;i<strLen;i++)
	{
		str[num] = str[num]+input[i];
		cout<<"{"<<str[num]<<"}"<<endl;
		num++;
		for(int j=0;j<i;j++)
		{
			str[num] = str[j]+','+input[i];
			cout<<"{"<<str[num]<<"}"<<endl;
			num++;
		}
	}
	
}
 
Is This Answer Correct ?    1 Yes 1 No
Nkbinglei
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 6
# include<stdio.h>
# include<conio.h>
# include<alloc.h>
# include<string.h>
# include<math.h>

int bin[16];
void genbin(int);

void main()
{
	clrscr();
	char *str;
	int i=0,len=0;
	str = (char*)malloc(100);
	printf("Input a no. :");
	scanf("%s",str);
	len = pow(2,strlen(str));
	for(i=0;i < len;i++)
	{
		genbin(i);
		for(int j=0;j < strlen(str);j++)
		{
			if(bin[j] == 1)
			printf("%c",str[j]);
		}
		printf("\n");
	}
	free(str);
	getch();
}
void genbin(int n)
{
	for(int i=0;i<8;i++)
	{
	   bin[i] = n%2;
	   n /= 2;
	}
}
 
Is This Answer Correct ?    1 Yes 0 No
Vadivel
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 7
Here is a trivial Java function to do this.  At least two 
of the above answers do not work at all...???  The binary 
solution seems to have some merit but why make it so 
difficult and problem frought???  I put in an element 
counter to verify the correct number of elements in the set 
upon print out.  Call the function below using the obvious 
form:

printSubsets("", "abc");

static int m_cElements = 1;
private static void printSubsets(String prefix, String str)
{
   if(str.equals(""))
      System.out.println((m_cElements++)+": {"+prefix+"}");
   else
   {
      printSubsets(prefix, str.substring(1));
      printSubsets(prefix+str.substring(0,1), str.substring
(1));
   }
}
 
Is This Answer Correct ?    1 Yes 0 No
Gordon Roberts
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 8
find the no of bits required to represent the value n.i.e.
no of elements in the set.This can be done using following
algorithm.
int bin(int n)
{
  if(n==1)return 1;
return 1_n/2_1+1;
}
print(char c[12],int b)
{
    for(int i=0;i<b;i++)
       if(c[i]=='1')
         printf("%c",65+i);
}

combinations(int n)
{
    int b=bin(n);
    char c[12];
     for(int i=0;i<pow(2,b);i++)
     {
          for(int j=1;j<b;j++)
               if(i>>1)
                c[j-1]='1';
                else
                 c[j-1]='0';

     print(c,b);
}
 
Is This Answer Correct ?    0 Yes 0 No
Vijay Nag
 
  Re: How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com
Answer
# 9
i have written the program to find all the proper subsets,but it doesnt print them in order
ex:
{a,b,c}
it will print:
{}
{a}
{a,b}
{b}
{a,c}
so on
(not in order}
if u want it mail me(goodluck87@gmail.com)
 
Is This Answer Correct ?    0 Yes 2 No
Pankaj
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
Write a function to find the depth of a binary tree. Adobe8
write a program in c to merge two array  1
main() { int c=- -2; printf("c=%d",c); }  1
Printf can be implemented by using __________ list.  1
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18. Infosys6
How we print the table of 3 using for loop in c programing?  3
main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }  1
main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?  1
main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error HCL1
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }  1
Is this code legal? int *ptr; ptr = (int *) 0x400;  1
main() { extern out; printf("%d", out); } int out=100;  1
#if something == 0 int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }  1
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above HCL1
main() { printf("%x",-1<<4); }  1
void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }  1
How to read a directory in a C program?  4
main() { int i = 257; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }  1
main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }  1
#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d----%d",*p,*q); }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com