[Error] return-statement with no value, in function returning ‘int’ [-fpermissive]
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
char str[100];
cin>>str;
int l = 0;
int h = strlen(str);
int k=h-1;
while (k > l)
{
if (str[l++] != str[k--])
{
cout<<"losses"<<endl;
return;
}
}
cout<<"wins"<<endl;
}
return 0;
}
write return 0 instead of return here.
no return 0 terminates the program there only
Use break then(if you just want to break out of the loop) .
Yeah, it won’t. Coz you have messed up many things. Firstly, use #include <bits/stdc++.h>
. This helps you avoid missing out on important headers. For example, you are using std::cin
here when you haven’t included iostream header. Also, you can’t take input char arrays in that manner. (Use std::string) instead. Thirdly, learn to Google wisely. (The most important point) .
thank you sir for your time no disrespected but some points to say if you dont mind
1)it was not showing here but i have used bits/stdc++ header file.there was no problem with that.
2)i figured out that else
cout<<"wins"<<endl;
was in wrong place which resolved my problem.there was nothing about taking arrays in diff way.
3)learn to Google wisely. i dont get that point.
i appreciate your responses thank you
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
//METHOD 1
bool isPalindrome=true;
int n = s.size();
for(int i = 0; i < n/2; i++)
{
if(s[i]!=s[n-i-1])
{
isPalindrome=false;
}
}
if(isPalindrome == true)
{
cout<<"Palindrome\n";
}
else{
cout<<"Not Palindrome\n";
}
//optimizing method 1
int n = s.size();
for(int i = 0; i < n/2; i++)
{
if(s[i]!=s[n-i-1])
{
cout<<"Not Palindrome\n";
return 0;
}
}
cout<<"Palindrome\n";
return 0;
}
HOPE THIS HELPS
1 Like