Program to calculate the value of triangular number

 Program to calculate the value of triangular number


class P6
{
    public static void main(String args[])
    {
        int n , tri_num ;

        n = 6;
        tri_num = n * (n+1) / 2 ;
               
            System.out.println("The value of the triangular number "+n+" is "+tri_num);
    }
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|