Submission opens on: Sunday 05 September, 00:00:00 hours.
Deadline for Lab 1 Part 1: Tuesday 07 September, 23:59:59 hours.
This part of the lab is worth 1 mark.
For the first lab assignment, your task is to design a C program that reads in a number, and produce as output a corresponding number imploded by value.
For a given number, say, d1d2d3..dN where each di represents a digit from 0 to 9, the corresponding number imploded by value is given as
d1...d1 | d2...d2 | d3...d3 | ...... | dN...dN |
d1 times | d2 times | d3 times | dN times |
where each di is reproduced di times.
For example, the number 123 when imploded gives 122333. The number 305 when imploded gives 33355555 (since 0 is reproduced zero times).
You must submit your program by logging in to the sunfire UNIX system. The instructions on logging in and submitting are given in Lab 0.
You may wish to know that the Secure Shell Client also has a user-friendly program that allows you to transfer files between your home PC or laptop to your UNIX account. The File Transfer program can be accessed from Secure Shell Client under "Window -> New File Transfer".
Note that you are NOT to use any form of arrays in your program.
#include <stdio.h> int main() { int number; /** Fill in and declare other variables here **/ /* Input a number */ printf("Enter a number (not exceeding 9 digits; 0 or less to exit): "); scanf("%d", &number); while (number > 0) { /** Fill in your code to implode and print the number here **/ /** Fill in your code to implode and print the number in REVERSE here **/ /* Input another number */ printf("\nEnter a number (not exceeding 9 digits; 0 or less to exit): "); scanf("%d", &number); } /* Terminate program */ printf("\nProgram terminated\n"); return 0; }
The following is a sample session. User input is denoted in bold.
Enter a number (not exceeding 9 digits; 0 or less to exit): 123 Imploding number... 122333 Imploding number in reverse... 333221 Enter a number (not exceeding 9 digits; 0 or less to exit): 0405060 Imploding number... 444455555666666 Imploding number in reverse... 666666555554444 Enter a number (not exceeding 9 digits; 0 or less to exit): -1 Program terminated