Professional Documents
Culture Documents
ICP-Programming Assignment-V PDF
ICP-Programming Assignment-V PDF
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 B C
A B C D
4. Given a set of n student’s 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
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.
1 2 4 8 16 32 ...
1 -1 1 -1 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.
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).
**********