不提供正确的输出? [英] Don't give correct output?
本文介绍了不提供正确的输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序应该接受单词aba和所有长度均匀的单词,例如abababb它应该给出有效的答案,但它不给出....
这是代码:
The program should accept the words aba and all words of even length such as abababb it should give valid answer but it is not giving....
Here is the code:
#include<conio.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main(void)
{
clrscr();
int i=0;
char str[30];
printf("Enter the input string: ");
gets(str);
if(str[i]=='a')
{
str[i++];
if(str[i]=='b')
{
str[i++];
if(str[i]=='a')
{
str[i++];
if(str[i]==NULL)
{
printf("\nVALID");
}
else
{
loop:
;
if(str[i]=='a'|| str[i]=='b')
{
str[i++];
goto loop;
}
else
{
goto a;
}
a:
;
if(i%2==0)
{
printf("\nVALID");
}
else
{
printf("\nINVALID");
}
}
}
else
{
printf("\nINVALID");
}
}
else
{
printf("\nINVALID");
}
}
else
{
printf("\nINVALID");
}
getch();
}
Please correct my code??</string.h></stdio.h></conio.h>
推荐答案
一个错误是:
one bug is:
str[i++];
//its is enough
i++;
错误是
the bug is
if(i%2==0)
abababb
,因为它不均匀。
考虑改进你的代码风格。真的:疯了:
for abababb, coz its uneven.
Consider improving your codestyle. Really :mad:
这篇关于不提供正确的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文