0
circular string triangle pattern Input: 5 ABCDE Output: A \n BC \n DEA \n BCDE \n ABCDE
i tried this but i need help..
3 Respuestas
0
It is not working because your logic is not correct
See carefully your j value of initialising to 0 again and again when your program reaches the 2nd for loop
So gotta do like this first you will need another variable say k and initialise it to 0 at first then try to this code in your 2nd for loop
for(j=0; j< i; j++)
{
printf("%c",s[k]);
k++;
if(k>n-1)
k=0;
}
Try to understand it carefully and in you first for loop that should be i<n not i<=n
0
i tried this ..
#include<stdio.h>
int main()
{
int n,i,j;
char s[10];
scanf("%d %s",&n,&s);
for(i=0;i<=n;i++)
{
for(j=0;j<i;j++)
{
printf("%c",s[j]);
}
printf("\n");
}
return 0;
}
0
but i got only this
A
AB
ABC
ABCD
ABCDE....