ode in not working i have tried just every thing to print the difference i have used typecaste in mycode but i have also tried the char - char,string -string
here is my code,what is wrong with my code.can you modify it
int main(){
string s;
cin>>s;
int diff;
int k=s.length();
for(int i=1;i<=k;i++){
diff=s[i]-s[i-1];
cout<<s[i-1]<<diff;
}
}
strings-Difference in ascii values
hi @dips123deepali_c25f140838182212
here is ur corrected code -->
#include <iostream>
#include<cstring>
using namespace std;
int main() {
string str;
cin>>str;
for(int i=1;i<str.size();i++){
int diff = str[i] - str[i-1];
cout<<str[i-1];
cout<<diff;
}
cout<<str[str.size()-1];
return 0;
}
its working fine and passing all test cases…
hi Deepali,
I hope ur doubt is cleared now… is there anything else??
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.