c语言存储不知道个数的数组,在不使用数组的情况下用C语言存储多个值

Reverse Number Magic Sequence

Due: Wednesday January 27, 2016 11:59pm EST

A reverse number is a number written in arabic numerals, but where the

order of digits is reversed. The first digit becomes the last and vice

versa. For example, the number 1245 when its digits are reversed it

would become 5421. Note that all the leading zeros are omitted. That

means if the number ends with a zero, the zero is lost by reversing

(e.g. 1200 gives 21). Also note that the reversed number never has any

trailing zeros. Finally, every single digit number (i.e. 0-9) is its

own reverse number. In order to generate a magic number, we reverse a

given original number and store the absolute value of the difference

between the original number and its reversed version. For example,

given the number 476, we will generate the reverse number 674 and then

compute the absolute value of the difference between 476 and 674 to be

198. We then reverse 198 to display the number 891; we call that the magic number!

We need your help to compute the magic numbers of a given sequence.

Your task is to calculate the difference between a given number and

its reverse version, and output the reverse of the difference. Of

course, the result is not unique because any particular number is a

reversed form of several numbers (e.g. 21 could be 12, 120 or 1200

before reversing). Thus we must assume that no zeros were lost by

reversing (e.g. assume that the original number was 12).

Input

The

input consists of N numbers, where N is an arbitrary positive integer.

The first line of the input contains only a positive integer N. Then

follows one or more lines with the N numbers; these numbers should all

be non-negative and may be single or multiple digits. These are the

original numbers you need to generate their N corresponding magic

numbers.

Output

For each original number in the sequence, print

exactly one integer – its magic number. Omit any leading zeros in the

output. On a separate line, output the largest absolute difference

encountered in the sequence. Sample Input

6

24 1 4358 754 305 794

Sample Output

81 0 6714 792 891 792

4176

Specific Requirements: [15 pts]

[ 3 pts] Write a function called reverseInteger, that takes as input an unsigned integer and returns its reversed digits version as an

unsigned integer.

[ 3 pts] Write a function called generateMagicNumber, that takes as input an unsigned integer and return its magic number as described in

the problem.

[ 3 pts] Display the sequence of magic numbers correctly. (shown in the script file)

[ 2 pts] Display the largest absolute difference (shown in the script file)

[ 3 pts] Demonstrate the complete program using a main function capable of processing the input of any sequence and producing its

corresponding output.

[ 1 pt] Compilation on the CS server gcc compiler without errors and warnings.

Failure to properly document your entire code will receive a mark of

zero.

You are to submit the following:

Source code file: assign1.c

Script file demonstrating the compilation and execution : assign1.txt

To generate the script file use the following command from the CS

server:

cp assign1.c assign1.backup

typescript assign1.txt

cc assign1.c

a.out

[test your code here with at least 3 different input test cases in addition to the example given]

exit

[These steps will create a file called assign1.txt. Do not edit its contents - just submit it!]

Hint: This table explains the work done in this example:

Originalnumber

Reverse Absolute difference

Reverse (Magic number)

X Xr |X-Xr| |X-Xr|r

24 42 18 81

1 1 0 0

4358 8534 4176 6714

754 457 297 792

305 503 198 891

794 497 297 792

Note that your program should not use arrays and should be able to

read a sequence of N size, for any value of N (a 32 bit integer). Of

course, memory space optimization should be considered since there is

no need to store all the N numbers in memory all at once at any given

time.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值