can any one help me in my code | SoloLearn: Learn to code for FREE!

+1

can any one help me in my code

#include <stdio.h> #include <stdlib.h> #include <string.h> int longage2(char phe[ ]){ if (strlen(phe)==1||strlen(phe)%2!=0||phe[strlen(phe)]=='a'){ return 0; } for(int i=0;i<strlen(phe);i++){ if(i%2==0){ if(phe[i]!='a'){ return 0; }}else{ if(phe[i]!='b'){ return 0;}} }return 1;} void longage4(char phe[]){ int a;char ph1[10]; for( int i=0;i<=strlen(phe)-1;i++){ ph1[i]=phe[i]; printf("%d\n",longage2(ph1)); if(longage2(ph1)==1){ a=i; }} printf("a=%d\n",a); char ph2[a]; for(j=0;j<=a;j++){ ph2[j]=ph1[j]; } printf("%s\n",ph2); printf("%d",longage2(ph2)); } int main() {char phe[20]; printf("donnez un mot\n"); scanf("%d",phe); longage4(phe); return 0; }

10/21/2020 9:15:55 PM

mar ia

11 Answers

New Answer

+5

mar ia the problem is that ph2 has no terminating character '\0' Also if you want ph2 to contain ph2[3] you should declare char ph2[4]; so char ph2[a+1]; adding another space for \0 it become: char ph2[ a + 2 ] for(j=0; j <= a; j++) { ph2[i] = ph1[i]; } ph2[a+1] = '\0';

+4

The scanf in the main() should have %s And you need to declare int j; into longage4()

+4

Can you tell me what to enter as input?

+3

Thank you very much for helping me. I don't know😦 how to express my thanks to you😀😊

+1

I fex it but wan yo but (donne un mot and you raet abab l hav proplem in resolt of line 32

+1

He raet to me "abab?" I didnt no whay but (?)qustshen marc

+1

#include <stdio.h> #include <stdlib.h> #include <string.h> int longage2(char phe[ ]){ if (strlen(phe)==1||strlen(phe)%2!=0||phe[strlen(phe)]=='a'){ return 0; } for(int i=0;i<strlen(phe);i++){ if(i%2==0){ if(phe[i]!='a'){ return 0; }}else{ if(phe[i]!='b'){ return 0;}} }return 1;} void longage4(char phe[]){ int a;char ph1[10];int j; for( int i=0;i<=strlen(phe)-1;i++){ ph1[i]=phe[i]; if(longage2(ph1)==1){ a=i; }} char ph2[a]; for(j=0;j<=a;j++){ ph2[j]=ph1[j]; } printf("%s\n",ph2); } int main() {char phe[20]; printf("donnez un mot\n"); scanf("%s",phe); longage4(phe); return 0; }

+1

thes is beter an clen and the input is abab and mast be the reasolte is abab

+1

The program works like this When we enter (ab)^n n>0 the reasolt is (ab)^n wen we but like exp : aba the resolt shod be :ab He is looking for (ab)^n Consecutive and he Display it

0

Hug me 🤗🤗🤗

0

Hhhhh😊