Hello Choto Bondhu!

When n = 1, ans = (n * n) % 10 = 1 % 10 = 1.

When n = 2, ans = (n * n) % 10 = 4 % 10 = 4.


This is a companion discussion topic for the original entry at https://toph.co/p/hello-choto-bondhu

#include<stdio.h>
int main()
{
int i,t;
scanf("%d",&t);
int n[t];
for(i=0;i<t;i++){
scanf("%d",&n[i]);
}
for(i=0;i<t;i++)
{
printf("%d\n",((n[i]*n[i])%10));
}

return 0;

}
//where is the problem?It passed test case 1 but failed in test case 2!

#include 

int main() {
	int t,i,n;
	scanf("%d",&t);
	for(i=0;i<t;i++){
		scanf("%d",&n);
		if(n%10==0){
			printf("%d\n",0);
		}
		else if(n%10==1 || n%10==9){
			printf("%d\n",1);
		}
		else if(n%10==2 || n%10==8){
			printf("%d\n",4);
		}
		else if(n%10==3 || n%10==7){
			printf("%d\n",9);
		}
		else if(n%10==4 || n%10==6){
			printf("%d\n",6);
		}
		else if(n%10==5){
			printf("%d\n",5);
		}
		else if(n%10==0){
			printf("%d\n",0);
		}
	}
	return 0;
}

What’s the bug here?
Why is it failing in test case 4?
Can anyone tell?

I’m no expert at this but I’ve to say it, bro, why did you used printf("%d\n",2); you could use printf(“2”); instead in the “cheat”(I thought the same way.).i also think you need long int or long long int in the function cause the squared number are very large than int .in that case every answer would be taken from 1st 8 digits(or maybe 9, I am not sure). so, try that & I’m very sorry for the delay Ana.

sorry but I checked more and found that my previous ans was partially wrong. cause in subtask 3 , " n" has highest value 10^100000 that means 1 lakh digits. I think string may work.

T=int(input())
for i in range(T):
n=int(input())
s=str(n**2)
print(int(s[len(s)-1:]))

I am exceeding CPU limit in the last case. Any suggestions on what i can do?