class sum_consucative
{
public void chk_sum_consucative(int n)
{
int i,j,t,f,chk=0,a;
for(i=1;i<n;i++)
{
t=0;
f=0;
for(j=i;j<=n;j++)
{
t+=j;
if( t == n)
{
chk=1;
f=1;
break;
}
else if(t>n)
break;
}
if( f == 1)
{
for(a=i;a<j;a++)
System.out.print(a+" + ");
System.out.print(a + " = " + n);
System.out.println();
}
}
if( chk == 0)
System.out.print("Sorry set not possiable................");
}
}
No comments:
Post a Comment