//WAP to input a string and print the Square of all the Numbers // in a String. Take care of special cases. Input: wha4ts12ap1p and //Output: 16 1 4 1 3.
Tue May 07 2024 15:16:34 GMT+0000 (Coordinated Universal Time)
Saved by
@vedanti
#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;
}
content_copyCOPY
Comments