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

ICP Programming Assignment V

This document outlines 18 programming assignments involving fundamental algorithms in Java. The assignments include: 1) Exchanging the values of 3 variables without and with a temporary variable. 2-3) Exchanging the values of variables in different orders. 4) Counting the number of students who passed an exam based on a pass mark. 5) Reading student marks from a file, counting passes and calculating pass percentage. 6-7) Counting positives/negatives and summing a list of numbers. 8-10) Computing the sum of squares, harmonic mean, and first n terms of a sequence. 11-12) Printing a sequence and computing the sum of its first n terms. 13-15) Computing n factorial, 1/n!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

ICP Programming Assignment V

This document outlines 18 programming assignments involving fundamental algorithms in Java. The assignments include: 1) Exchanging the values of 3 variables without and with a temporary variable. 2-3) Exchanging the values of variables in different orders. 4) Counting the number of students who passed an exam based on a pass mark. 5) Reading student marks from a file, counting passes and calculating pass percentage. 6-7) Counting positives/negatives and summing a list of numbers. 8-10) Computing the sum of squares, harmonic mean, and first n terms of a sequence. 11-12) Printing a sequence and computing the sum of its first n terms. 13-15) Computing n factorial, 1/n!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CSE 1001: Introduction to Computer Programming

Programming Assignment-V
(Fundamental Algorithms)
1. Given three variables of integer type A, B and C. Write a java program to exchange their
values using fourth temporary variable.

2. Write a java program to make the following exchanges without using the fourth
temporary variable.
A

(The arrows indicate that B is to assume the value of A, C the


value of B and so on)

3. Write a java program to make the following exchanges.


A

(The arrows indicate A is to assume the value of B, B the value


of C, C the value of D and D the value of A)

4. Given a set of n students examination marks (in the range 0 to 100). Write a java
program to count the number of students that passed the examination. A pass is awarded
for all marks of 40 and above.

5. Let the marks of the students in the above question be stored in a data file named as
marks.dat. Write a java program to read the marks until an end-of-file is encountered.
For this set of marks determine the total number of marks, the number of passes, and the
percentage of pass rate.

Hints: Code template


public class Student {
public static void main(String[] args) throws IOException

/* Read the data from the file */

Scanner inFile=new Scanner (new FileReader ("marks.dat"));


/* Read the data
encountered*/

values

from

the

file

until

an

EOF

is

while (inFile.hasNextInt())
{

mark=inFile.nextInt();

inFile.close ();
}
}

6. Write a java program that reads a list of numbers and makes a count of the number of
negatives and the number of non-negative members in the set.

7. Given a set of n numbers. Write a java program that adds these numbers and returns the
resultant sum and compute the average. Assume n is greater than or equal to zero.

8. Write a java program to compute the sum of the square of n numbers. That is,

   


9. Write a java program to compute the harmonic mean. The harmonic mean is defined by




1 

10. Write a java program to generate the first n terms of the sequence without using
multiplication.

16

32

...

-1

11. Write a java program to prints out n values of the sequence

-1

-1

12. Write a java program to compute the sum of the first n terms (n>=1) of the series.

S=1-3+5-7+9-

13. Input a number n, write a java program to compute n factorial (written as n!) where
n>=0.

14. For a given n, write a java program to compute 1/n!.


15. For a given x and a given n, write a java program to compute xn/n!.

16. Write a java program to determine whether or not a number n is a factorial number.

17. For some integer n, write a java program to find the largest factorial number present as
factor in n.

18. Write a java program to simulate multiplication by addition. Your program should accept
as input two integers (they may be zero, positive, or negative).

**********

You might also like