#include <stdio.h> #include <ctype.h> #include <stdlib.h> void print_square_of_numbers(char *string) { char *endptr; while (*string != '\0') { if (isdigit(*string)) { long num = strtol(string, &endptr, 10); printf("%ld ", num * num); string = endptr; } else { string++; } } printf("\n"); } int main() { char input_string[] = "wha4ts12ap1p"; printf("Square of numbers in '%s': ", input_string); print_square_of_numbers(input_string); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter