nrk009

characters and strings

Aug 2nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.         string s;
  6.         cin>>s;
  7.         s+="x"; //add x in string
  8.  
  9.         for(int i=0;i<s.size();i++){
  10.         cout<<s[i]-'a'<<" "; //prints value equal to  their ascii-97;
  11.                                 // s[i] s like 'a','b';
  12.                                 //if u r using 's[i]' the in realiy u r using ''s[i]'' ....because s[i]='a';
  13.         cout<<int(s[i]-'a');
  14.  
  15.         if((s[i]-'a')>=0)      //u can also use int(s[i]-'a');
  16.                 printf("neeraj ");
  17.         }
  18.         cout << int('a'); // prints value =97;
  19.         char a='p';
  20.         cout<<('p'-'a')<<" ";  //prints asciii value of 'p'- ascii value of 'a';
  21.         cout<<'z'-a<<" ";       // print ascii value of 'z' - ascii value of 'p';
  22.       if(a>0)
  23.                 printf("%d neeraj",a);
  24.                 cout<<a<<" ";  //print p;
  25.                 cout<<'a'<<" ";  //print a;
  26.                 cout<<int(a)<<" ";  //prints ascii value of p;
  27.                 cout<<int('a')<<" ";  //prints ascii value of a;
  28.  
  29.  
  30.  
  31.  
  32.  
  33.                 return 0;
  34. }
Add Comment
Please, Sign In to add comment