| Formatted Numbers
Limits 1s, 512 MB
Read an integer variable and print it in which the digits are separated into groups of three by commas.
Input
The input will contain an integer ().
Output
Print the formatted number.
Sample
Input | Output |
---|---|
1171123 | 1,171,123 |
N.B.: It's better if you solve this by your own. Thank you!
Toph Online Judge Formatted Number Solve in C :
//Solved by Intesar#include<stdio.h>#include<string.h>
int main(){ char s[20]; int i; gets(s); int k=0,j=0; int new[30]; for(i=strlen(s)-1;i>=0;i--) { if(j==3) { new[k++]=','; new[k++]=s[i]; j=0; } else new[k++]=s[i]; j++;
}
for(i=k-1;i>=0;i--) { printf("%c",new[i]); }}
0 Comments