3. Program to print all possible substrings.

ex: String
S
St
Str
Stri
Strin
String
t
tr
tri
trin
tring
r

Answers were Sorted based on User's Feedback



3. Program to print all possible substrings. ex: String S St ..

Answer / rafiq

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int i,j,n,k;
char a[10]="String";
i=0;
n=strlen(a);
for(i=0;i<n;i++)
{

for(j=i;j<n;j++)
{
for(k=i;k<j+1;k++)
{
printf("%c",a[k]);
}
printf("\n");
}

}

getch();
}

Is This Answer Correct ?    51 Yes 23 No

3. Program to print all possible substrings. ex: String S St ..

Answer / siraj

#include<stdio.h>

int main()
{

char a[10]="String";
substringTest(a);
getch();
return 0;
}
void substringTest(char *a)
{
int i,j,n,k;
for(n=0; a[n]!='\0'; n++) {}
// n=strlng(a);
for(i=0; i<n; i++)
{

for(j=i; j<n; j++)
{
for(k=i; k<j+1; k++)
{
printf("%c",a[k]);
}
printf("\n");
}

}


}

Is This Answer Correct ?    1 Yes 2 No

3. Program to print all possible substrings. ex: String S St ..

Answer / nik

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main(){
int i,j=0,k=0,n;
char str[50],str1[25],str2[25],temp;
puts("Enter String");
gets(str);
n=strlen(str);
for(i=0;i<n;i++){
for(j=i;j<n;j++){
for(k=j;k<n;k++){

printf("%c",str[k]);
}

printf("\n");
}

printf("\n");
}
getch();
}

Is This Answer Correct ?    15 Yes 21 No

Post New Answer

More C Interview Questions

How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?

1 Answers  


What are logical errors and how does it differ from syntax errors?

0 Answers  


Do string constants represent numerical values?

0 Answers  


Why c is called object oriented language?

0 Answers  


Who is the main contributor in designing the c language after dennis ritchie?

0 Answers  






Is javascript written in c?

0 Answers  


The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?

0 Answers  


write a program which counts a product of array elements lower than 10.

1 Answers  


Difference between Class and Struct.

13 Answers   Ericsson, Motorola, Wipro,


which header file contains main() function in c?

17 Answers   Google, HCL, TCS,


Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 2. Enter alphanumeric characters and form 2 array alphaets and digits.Also print the count of each array.

0 Answers  


Explain what header files do I need in order to define the standard library functions I use?

0 Answers  


Categories