Programs To Take a Number From User and Print the SUM of SQUARE of ALL the Numbers Till The Entered Number
For Instance:
Input=4
Output=1*1+2*2+3*3+4*4=30
class sqsum
{
public static void main(int a)
{
int sq=0,add=0;
for(int i=1;i<=a;i++)
{
sq=i*i;
add+=sq;
}
System.out.print(add);
}
}
Input: 3 and 8
Output:
No comments:
Post a Comment