I got one assingment to do,which I did but my code is hardcoded ,but my processor wants generic code.

The requirement for the assingment is-------->

Given input n,find out the largest number with "n" digits such that:

a. All the digits in its are just 1 or 2 or 3.

b. No two adjacent substrings of the given number is same

some of the examples are :3 323 3231 3231323

Examples of the numbers that do not fit the requirements are:33 3232 3223 321321

* 33 as 3 follows 3.

* 3232, because the substring "32" is present adjacent to the substring "32"

* 3223, because the substring "2" follows "2".

* 321321 because the substring "321" is adjacent to substring "321"

321312 is a good number because there are no two adjacent substrings repeating

themselves. But given n = 6,it is not the largest 6- digit number we are looking for.

The largest 6-digit number that fits our requirments would be 323132

Below is my code

#include<stdio.h> #include<string.h> char str[20] = "323132131232132"; main() { int i,k,n,count = 0; char *ptr; ptr = str; printf("Enter no\n"); scanf("%d",&n); //printf("%d->", n); for(k = 1; k <= n; k++) { printf("%c",*ptr); ptr++; if(*ptr == '\0') { count++; for(i = 0;i <= strlen(str);i++) { switch(count) { case 1: ptr = &str[2]; break; case 2: ptr = &str[7]; break; case 3:ptr = &str[8]; count =0; break; } } } } printf("\n"); }

So plz help me out in making generic code as soon as possible

This post has been edited by **skan_33**: 11 March 2008 - 05:33 AM