Help me in solving TRICOIN problem

My issue

code

My code

#include <stdio.h>

int main() {
	int N, k = 1;
	printf ( "Enter the number of gold coins;");
    scanf ( "%d", & N);
    while ( k*(k + 1)/2 <= N)
}


Problem Link: Coins And Triangle Practice Coding Problem

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
	while(t-->0){
	    int n=sc.nextInt();
	    int maxHeight=0;
	    for(int i=1;(i*(i+1))/2<=n;i++){
	        maxHeight=i;
	    }
	    System.out.println(maxHeight);
	}    
		}

	}

Problem Link: https://www.codechef.com/problems/TRICOIN
[/quote]

we will use the sum of n natural numbers formula, starting at i=1 and checking the condition of the sum of i numbers less than or equal to n.We will update maxHeight according to it.