+ 1

Distribution of Coins

You are a teacher and you have N coins. You want to distribute these coins maong your students. You have to make sure that all the studentsget distinct number of coins. Now, you have to calculate the maximum number of students. S among which you can distribute the coins. Note: Not necessay tp distribute all the coins. Input: Each case consists of integer N i.e., number of coins Output: Print single integer denoting the value of S(Maximum number of students) Ex: Input: 5 Output: 2 5 coins can be divided distinctly in at max 2 students.

6th May 2022, 5:33 AM
Codebeforechill
2 Respuestas
0
import java.util.Scanner; class Test { public static int maxStudents(int N){ int student_count = 0; int sum = 0; for(int i =1; i<=N; i++){ sum+=i; if(sum>N){ break; }else{ student_count+=1; } } return student_count; } public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.println("Input: "); int N = sc.nextInt(); System.out.println("Output: "); System.out.println(maxStudents(N)); } }
6th May 2022, 7:01 AM
Thineshan Panchalingam
Thineshan Panchalingam - avatar
+ 1
where is your attempt? which programming language?
6th May 2022, 6:12 AM
Vishal
Vishal - avatar