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
Answer Posted / 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 |
Post New Answer View All Answers
Write a simple code fragment that will check if a number is positive or negative.
What are runtime error?
Write a program to print ASCII code for a given digit.
What is malloc calloc and realloc in c?
Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?
Can we assign integer value to char in c?
What are external variables in c?
What do you mean by Recursion Function?
Not all reserved words are written in lowercase. TRUE or FALSE?
Explain enumerated types in c language?
What is a pointer on a pointer in c programming language?
How can you restore a redirected standard stream?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
How can I sort a linked list?
What is file in c preprocessor?