Write a program to write a given string in maximum
possibilities?
i.e str[5]="reddy";
i.e we can write this string in 120 ways
for that write a program

Answers were Sorted based on User's Feedback



Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i..

Answer / ram

Hi thanks for this answer
But i need all that possibilities to be printed
If u can make that answer let me know?

Is This Answer Correct ?    4 Yes 2 No

Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i..

Answer / sunil singh

Hello dear....
sorry for my misunderstanding for the question..
please check this code it might help you..
************************************************************
#include "stdafx.h"
#include "string.h"
#include "conio.h"

#define BUFFER_SIZE 256

int fcto(int value)
{
int result;

if(value <= 1)
{
return 1;
}
else
{
return (value*fcto(value-1));
}
}
void PrintAllValues(char *ptr,int number)
{
char backup[BUFFER_SIZE],*first, *second,*temp1;
int loop, length;
char result[BUFFER_SIZE];
char temp,temp12;
int count =0,i;
static int serial =0;
memset(backup,0x00, BUFFER_SIZE);
memset(result,0x00, BUFFER_SIZE);
memcpy(result,ptr,BUFFER_SIZE);
memcpy(backup,ptr,BUFFER_SIZE);
first = second = result;
temp1 = backup;
length= strlen(result);
printf("\r\n%s - %d",result,serial);
for(loop=1;loop<=number;)
{
second += count;
first += count;
if(*(first+1) == '\0')
{
temp = result[0];
for(i = 0 ; i < length;i++)
{
if(i == 0)
{
temp =result[i];
result[i] = result[length-1];
}
else
{
temp12 = result[i];
result[i] = temp;
temp = temp12;
}
}
memcpy(backup,result,BUFFER_SIZE);
first = second = result;
count = 0;
loop++;
serial++;
printf("\r\n%s - %d",result,serial);
}
while((*second != '\0') && (loop <= number))
{
serial++;
loop++;
if(*first != *second)
{
temp = *first;
*first = *second;
*second = temp;
second++;
first++;
printf("\r\n%s - %d",result,serial);
}
else
{
printf("\r\n****** - %d",serial);
second++;
}

}
memcpy(result,backup,BUFFER_SIZE);
first = second = result;
count++;
}
}

int main()
{
char *ptr = "abcdef";// enter the string
int data1;

data1 = fcto(strlen(ptr));
PrintAllValues(ptr,data1);

getch();
return 0;
}
************************************************************

Please let me know if you face any problem.

Thanks
sunil

Is This Answer Correct ?    2 Yes 1 No

Write a program to write a given string in maximum possibilities? i.e str[5]="reddy"; i..

Answer / sunil singh

Here is an example program...

#include "stdafx.h"
#include "string.h"

int recursive(int length)
{
if ( length <= 1 )
return 1;
else
return length*recursive(length-1);
}

int main(int argc, char* argv[])
{
char data[] = "ready";

printf("maximum possibilities - %d \n", recursive
(strlen(data)));
return 0;
}

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C Interview Questions

Given an unsigned integer, find if the number is power of 2?

5 Answers  


why ordinary variable store the later value not the initial

1 Answers  


write a program to convert a expression in polish notation (postfix) to inline (normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix

0 Answers  


what is the diference between pointer to the function and function to the pointer?

2 Answers   Infosys,


How do you define CONSTANT in C?

0 Answers   ADP,






How to write a multi-statement macro?

0 Answers  


write a program to swap bits in a character and return the value prototype of function char fun (char a, charb flag c) where fun returns a char, char a is a the value char b is the bit to be changed and flag c is the bit value for eg: x=fun(45,7,0) since 45 is 0010 0101 and ow x should contain the value 65 (0110 0101)

1 Answers   Bosch, College School Exams Tests,


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,


What is a symbolic constant?

1 Answers  


A B C D E F G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A

2 Answers  


program to find the ASCII value of a number

8 Answers  


main() { clrscr(); } clrscr();

6 Answers   ME, Wipro,


Categories