How to subtract character in C

2 Answers

0 votes
#include <stdio.h>

int main()
{
    char ch = '9';
    int n = ch - '1';
    
    printf("%c\n", ch);
    printf("%d\n", n);

    return 0;
}


          
/*
run:
       
9
8

*/

 



answered Dec 25, 2020 by avibootz
0 votes
#include <stdio.h>

int main()
{
    char ch = '9';
    int n = ch - 49; // '1' = 49
    
    printf("%c\n", ch);
    printf("%d\n", n);

    return 0;
}


          
/*
run:
       
9
8

*/

 



answered Dec 25, 2020 by avibootz

Related questions

1 answer 79 views
79 views asked Jan 24, 2023 by avibootz
1 answer 137 views
2 answers 183 views
183 views asked Jul 6, 2020 by avibootz
2 answers 186 views
1 answer 197 views
197 views asked Sep 14, 2014 by avibootz
1 answer 109 views
1 answer 115 views
...