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

How do I swap bytes?

0 Answers  


You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

0 Answers  


how many times of error occur in C

11 Answers  


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

2 Answers   Infosys,


What is the sizeof () a pointer?

0 Answers  






What is malloc and calloc?

0 Answers  


Write a program to swap two numbers without using third variable in c?

0 Answers  


Can you please explain the difference between syntax vs logical error?

0 Answers  


Write a function that will take in a phone number and output all possible alphabetical combinations

0 Answers   Motorola,


What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(ā€œ%d\nā€,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none

2 Answers  


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database

2 Answers   TCS, Unisys, Webyog,


How can I read in an object file and jump to locations in it?

0 Answers  


Categories