0

A full 4-digit number is given. Determine if the sum of the first two digits is equal to the other two.

C#. visul studio

25th May 2018, 9:25 AM
iulian vlas
iulian vlas - avatar
3 Antworten
0
public static int isHalvesSumsEqual(int num){ if(num>9999 || num < 1000) return false; int d4 = num%10; int d3 = (num/10)%10; int d2 = (num/100)%10; int d1 = num/1000; return (d1+d2)==(d3+d4); } Didn't test but probably works.
25th May 2018, 10:10 AM
BlazingMagpie
BlazingMagpie - avatar
+ 2
What is your question exactly? How to solve this in C#? What part of the code do you have already?
25th May 2018, 9:28 AM
Maart
Maart - avatar
25th May 2018, 9:38 AM
Ulisses Cruz
Ulisses Cruz - avatar