bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / khurapati-idea / KI001.c

KI001.c (801B)


      1 // khurapati idea no. : 1
      2 // Idea : we can use the side effect of printf function to get length of any string or number
      3 
      4 #include <stdio.h>
      5 int main()
      6 {
      7     // testing number
      8     int num, len = -13 /* here minus 13 because we will remove the massage characters in line 10 */;
      9     printf("Enter a number to get the length : ");
     10     scanf("%d", &num);
     11     len += printf("Your input : %d", num); // here the "Your input : ", this 13 characters are extra
     12     printf("\nLength : %d", len);
     13 
     14     // testing char
     15     char a[20];
     16     len = -13;
     17     while (getchar() != '\n')
     18         ;
     19     printf("\nEnter a word to get the length : ");
     20     scanf("%19s", &a);
     21     len += printf("Your input : %s", a);  // here the "Your input : ", this 13 characters are extra
     22     printf("\nLength : %d", len);
     23     return 0;
     24 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror