0% found this document useful (0 votes)
10 views

Assignment 3

The document provides instructions for submitting Assignment III. Students are to submit each program separately in the Moodle system and provide the output of each program in a separate text file named "result_assignmentnumber.txt". It provides examples of using output redirection to write program output to a file rather than printing it to the screen. The document then lists three programming problems to solve for the assignment - computing a sum series, printing a triangle of asterisks given an integer input, and calculating the sum of prime numbers less than a given integer. Students are to provide outputs for sample inputs for each problem in the "result.txt" file using output redirection.

Uploaded by

jitbitan.kgpian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment 3

The document provides instructions for submitting Assignment III. Students are to submit each program separately in the Moodle system and provide the output of each program in a separate text file named "result_assignmentnumber.txt". It provides examples of using output redirection to write program output to a file rather than printing it to the screen. The document then lists three programming problems to solve for the assignment - computing a sum series, printing a triangle of asterisks given an integer input, and calculating the sum of prime numbers less than a given integer. Students are to provide outputs for sample inputs for each problem in the "result.txt" file using output redirection.

Uploaded by

jitbitan.kgpian
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment III

Submit all the programs separately against each assignment in the


Moodle System. Provide the result in a separate output file (named,
result_<assgn><no>.txt). Use standard output redirection feature to
generate the output file.

Hints. If you run the program with the following command

./a.out >result.txt

Output of your program (generated by printf(.) function) will be


written in the file result.txt. You need to provide input from your
keyboard, by remembering the sequence of inputs to be given or
writing them in a text file in the same sequence.

Otherwise you may use the redirection for the standard input file,
such as,

./a.out <input.txt

For the above all your printing by printf(.) function would be


displayed on your monitor.

For both reading from a file and writing to a file use the following.

./a.out <input.txt >result.txt

If you execute the program multiple times, you may concatenate the
outputs in a single file by using the following redirection command:

./a.out >>result.txt

or

./a.out <input.txt >> result.txt


1. Read the value of an integer number N, and compute
the sum S.
S = 1 +1/2+ 2/3 + 3/4 +4/5+ 5/6 + ... to N terms
Note that the sum S must be a floating-point number
(float or double). Provide outputs for N=5, 10, 15 and 20.
2. Write a program, which reads an integer N and prints N
rows in the form of triangle with ‘*’ in the following
manner (shown for N=10) , such that i th row (i=1,2, ..N)
prints i ‘*’ consecutively.

*
**
***
****
*****
******
*******
********
*********
**********

Provide outputs for N=6, and 15.

3. Write a program that reads an integer N, and prints the


sum of prime numbers, which are less than N. Compute
the values for N=2, 4, 8, 16, 32, 64 and 128, and provide
the result in a separate output file (named result.txt).
Use standard output redirection feature to generate the
output file.

You might also like