labprog1-2010

# labprog1-2010 - table borders#include<stdio.h> int...

This preview shows page 1. Sign up to view the full content.

Swinburne University of Technology Faculty of Engineering and Industrial Sciences HES1300 Laboratory worksheet 1: The following program reads an integer from the console and calculates and prints its factorial (n!=1*2*3*…*(n-1)*n, where * represents multiplication). By carefully studying this program, write a program that draws a table with two columns. The first column should show a series of natural integers (up to 10) and the second column should represent their factorial. Use ASCII characters to draw the
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: table borders. #include<stdio.h> int main() { int input, indx; long fact = 1; printf("Enter an integer number \n"); scanf("%d", &input); printf("n = %d\n", input); for(indx=1; indx <= input; indx++) { fact = fact * indx; printf("n = %d n! = %d \n", indx, fact); } printf("factorial(%d)= %d\n", input, fact); return(0); } For drawing a line, one can use the following program: #include<stdio.h> int main() { int count; for(count = 0; count < 20; count ++) { printf("-"); } printf("\n"); return(0); }...
View Full Document

• Three '10
• lauren
• Natural number, #include, Swinburne University of Technology, Faculty of Engineering and Industrial Sciences

{[ snackBarMessage ]}

Ask a homework question - tutors are online