正在加载图片...
-5- Problem 2-Strings(15 points) When large numbers are written out on paper,it is traditional-at least in the United States-to use commas to separate the digits into groups of three.For example,the number one million is usually written in the following form: 1,000,000 To make it easier for programmers to display numbers in this fashion,implement a function string AddCommasToNumericstring(string digits); that takes a string of decimal digits representing a number and returns the string formed by inserting commas at every third position,starting on the right.For example,if you were to execute the main program main ( f string digits; while (TRUE){ printf("Enter a string of digits:") digits GetLine(); if (StringEqual(digits,"")break; printf("&s\n",AddCommasToNumericstring(digits)); } your implementation of the AddcommasToNumericstring function should be able to produce the following sample run: Enter a string of digits:17 17 Enter a string of digits:1001 1,001 Enter a string of digits:12345678/ 12,345,678 Enter a string of digits:999999999/ 999,999,999 Note that AddcommasToNumericstring takes a string rather than an integer.On some machines, the range of the type int may be too small to allow interesting examples.If you want to use this function with integers,you could always call Integerrostring before calling AddCommasToNumericstring.– 5 – Problem 2—Strings (15 points) When large numbers are written out on paper, it is traditional—at least in the United States—to use commas to separate the digits into groups of three. For example, the number one million is usually written in the following form: 1,000,000 To make it easier for programmers to display numbers in this fashion, implement a function string AddCommasToNumericString(string digits); that takes a string of decimal digits representing a number and returns the string formed by inserting commas at every third position, starting on the right. For example, if you were to execute the main program main() { string digits; while (TRUE) { printf("Enter a string of digits: "); digits = GetLine(); if (StringEqual(digits, "")) break; printf("%s\n", AddCommasToNumericString(digits)); } } your implementation of the AddCommasToNumericString function should be able to produce the following sample run: Enter a string of digits: 17 17 Enter a string of digits: 1001 1,001 Enter a string of digits: 12345678 12,345,678 Enter a string of digits: 999999999 999,999,999 Note that AddCommasToNumericString takes a string rather than an integer. On some machines, the range of the type int may be too small to allow interesting examples. If you want to use this function with integers, you could always call IntegerToString before calling AddCommasToNumericString
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有