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
What is the use of in c?
Explain what is the benefit of using an enum rather than a #define constant?
What is an expression?
What is integer constants?
using for loop sum 2 number of any 4 digit number in c language
What is the difference between new and malloc functions?
What is scanf_s in c?
Is c language still used?
a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);
Explain the advantages of using macro in c language?
Why is c not oop?
Study the following C program :call_me (myvar)int myvar;{ myvar +- 5; }main(){int myvar;myvar = 3;call_me(myvar);printf("%d ",myvar);What will be printed a) 3 b) 5 c) 8 d) symbol
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
What is the size of array float a(10)?
What is a stream water?