KI001.c (937B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 // khurapati idea no. : 1 8 // Idea : we can use the side effect of printf function to get length of any string or number 9 10 #include <stdio.h> 11 int main() 12 { 13 // testing number 14 int num, len = -13 /* here minus 13 because we will remove the massage characters in line 10 */; 15 printf("Enter a number to get the length : "); 16 scanf("%d", &num); 17 len += printf("Your input : %d", num); // here the "Your input : ", this 13 characters are extra 18 printf("\nLength : %d", len); 19 20 // testing char 21 char a[20]; 22 len = -13; 23 while (getchar() != '\n') 24 ; 25 printf("\nEnter a word to get the length : "); 26 scanf("%19s", &a); 27 len += printf("Your input : %s", a); // here the "Your input : ", this 13 characters are extra 28 printf("\nLength : %d", len); 29 return 0; 30 }