0

Subtraction problem

Hello everyone! I practically have a problem coding an algorithm. In practice I have to enter two numbers and then compare which is the largest and then subtract the minor from the greater; and then print the differences 3 times. For example if I enter 20 and 5, I have to print 15, 10 and 5 finally. Now I managed to print 15, but in the other two results it always gives me 15 and not 10 and 5. How can I do? Thank you in advance!!! Sorry for my English. This Is my code: #include<stdio.h> main() { int num1,num2,i=0,subtract; printf("First number : "); scanf("%d",&num1); printf("\nSecond number : "); scanf("%d",&num2); do{ if(num1>num2) subtract=num1-num2; else subtract=num2-num1; printf("\nResults \n%d",subtract); i++; }while(i<3); }

30th Mar 2020, 11:41 AM
Computer_King20
Computer_King20 - avatar
3 ответов
+ 1
~ swim ~ Thank you for the answer. You are the best!!!
30th Mar 2020, 10:47 PM
Computer_King20
Computer_King20 - avatar
+ 1
It works perfectly
30th Mar 2020, 10:48 PM
Computer_King20
Computer_King20 - avatar