| | |
Permutations Of A Number Or String
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
This program generates different combinations of a number or a string as given by the user.just a simple implementation of arrays.
///////////////////////////////////////////////////////////////// ////// This program will generate all the possible /////// ///// arrangement of the string or number ////// ////////////////////////////////////////////////////////////// #include<stdio.h> #include<string.h> # include<alloc.h> #include<conio.h> /////////////////////////////////////////////////////// ///////// Programmer : Harsh Chandra /////// ///////////////////////////////////////////////////// void swap(char*,int); void gotoloop(char*,int); void main() { char *ch; int i,j,k,l; ch=(char*)malloc(20); clrscr(); printf("Enter the string\n"); gets(ch); l=strlen(ch); gotoloop(ch,l); return 0; } void gotoloop(char *ch,int l) { int i,k; k=l; if(l<=1) return; for(i=0;i<k;i++) { swap(ch,k); l--; gotoloop(ch,l); l++; if(k==2) printf("\n%s ",ch); } } void swap(char *ch,int r) { char c; int i; c=ch[r-1]; for(i=r-1;i>0;i--) ch[i]=ch[i-1]; ch[0]=c; }
0
•
•
•
•
# include<alloc.h> - is nonstandard
#include<conio.h> - is nonstandard
void main() - is incorrect
ch=(char*)malloc(20) - the cast is unnecessary, you should check the return value
clrscr(); - nonstandard function
gets(ch); - never use gets()!
return 0; - returning a value from a void function?
#include<conio.h> - is nonstandard
void main() - is incorrect
ch=(char*)malloc(20) - the cast is unnecessary, you should check the return value
clrscr(); - nonstandard function
gets(ch); - never use gets()!
return 0; - returning a value from a void function?
Similar Threads
- Permutations of a String (C++)
- Permutations of a String (C)
- permutations of STRING Vs First n natural numbers (C++)
- How to generate a list of permutations for a given binary number (Java)
- write a program which take a string give it permutations and combination (C++)
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char command convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic executable fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab win32 windows.h



