Write a C program to print look and say sequence?
For example if u get the input as 1 then the sequence is
11 21 1211 111221 312211 12112221 .......(it counts the no. of 1s,2s etc which is in successive order) and this sequence is used in run-length encoding.
Answer / chuck dorris
#include <string>
#include <sstream>
std::string lookandsay(const std::string &s)
{
std::ostringstream r;
for (unsigned int i = 0; i != s.length(); ) {
unsigned int new_i = s.find_first_not_of(s[i], i+1);
if (new_i == std::string::npos)
new_i = s.length();
r << new_i - i << s[i];
i = new_i;
}
return r.str();
}
#include <iostream>
int main()
{
std::string laf = "1";
std::cout << laf << std::endl;
for (int i = 0; i < 10; i++) {
laf = lookandsay(laf);
std::cout << laf << std::endl;
}
return 0;
}
| Is This Answer Correct ? | 0 Yes | 8 No |
main() { char *p; p="Hello"; printf("%c\n",*&*p); }
void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }
main() { char a[4]="HELL"; printf("%s",a); }
# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }
main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?
int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().
int DIM(int array[]) { return sizeof(array)/sizeof(int ); } main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr)); }
prog. to produce 1 2 3 4 5 6 7 8 9 10
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b)); } a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above
4 Answers Corporate Society, HCL,
Write a program to receive an integer and find its octal equivalent?
Write a procedure to implement highlight as a blinking operation