How to escape the % (percent) sign in printf with C

2 Answers

0 votes
#include <stdio.h>

int main(void) {
    int discount = 10;
    char ch = '%';
    
    printf("discount = %d%c\n", discount, ch);

    return 0;
}
  
   
   
/*
run:
  
discount = 10%
   
*/

 



answered Jun 27, 2024 by avibootz
0 votes
#include <stdio.h>

int main(void) {
    int discount = 10;

    printf("discount = %d%%\n", discount);

    return 0;
}
  
   
   
/*
run:
  
discount = 10%
   
*/

 



answered Jun 27, 2024 by avibootz

Related questions

1 answer 118 views
118 views asked May 14, 2022 by avibootz
1 answer 329 views
2 answers 1,211 views
1 answer 127 views
127 views asked Jul 11, 2022 by avibootz
1 answer 218 views
...