If you use a = -4 and b = -7 then your code print (0, 4) base on your 1st condition if(abs(a)<abs(b)) but Right answer is (1, 3) so, it's problem on your code. :)
import java.util.Scanner; public class Main{ public static void main(String[]args){ Scanner sc=new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.printf("%d %d\n",a/b,a%b); } } 10% error.Can you do any help?
Hello sir, i am a new programmer and i am trying to solve the problem about one week but still did not get how does it work.....could you please explain.
8 Comments
Thanks for sharing this post. Your post is really very helpful its students. python online course
ReplyDeleteThanks for visit my site :)
Delete#include
ReplyDeleteusing namespace std;
int main()
{
int a1,b1,a,b,q,r,c;
cin>>a>>b;
if(abs(a)<abs(b))
{
cout<<0<<" "<<abs(a)<<endl;
}
if(b==0)
{
cout<<0<<" "<<0<<endl;
}
else{
for(r=0;r<abs(b);r++)
{
if(a-r==0)
{
q=0;
a1=(b*q)+r;
b1=0;
}
if(a-r!=0)
{
q=(a-r)/b;
a1=(b*q)+r;
b1=(a-r)/q;
}
if(a1==a&&b1==b)
{
cout<<q<<" "<<r<<endl;
break;
}
}
}
return 0;
}
What's wrong with my code. It’shown 5% error.I tried my best.
Please help me.
If you use a = -4 and b = -7 then your code print (0, 4) base on your 1st condition if(abs(a)<abs(b)) but Right answer is (1, 3) so, it's problem on your code. :)
Deleteimport java.util.Scanner;
ReplyDeletepublic class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.printf("%d %d\n",a/b,a%b);
}
}
10% error.Can you do any help?
you just find positive number divide and reminder value but problem say that a and b is positive or negative value. so you can follow my solution.
DeleteHello sir, i am a new programmer and i am trying to solve the problem about one week but still did not get how does it work.....could you please explain.
ReplyDeleteHello, What is your idea?
DeleteIf you have any doubts, Please let me know