Ulcer.... or. A gastric (stomach) or duodenal (first part of the small intestine) ulcer is common, but also there can be blood loss from diverticulitis in the colon or other conditions such as colitis, crohns - you need to get in and be seen by a gastroenterologist. Great question- well wishes!
Cancer versus ulcer. I would advise you to ask your doctor to set you up for a colonoscopy, and upper endoscopy. This is the age range where colon cancer is a concern. Other causes include small bleeding blood vessels within the intestinal tract. You should also have blood smear to make sure that your bone marrow is capable of making enough new blood. Finally, make sure you have a well-balanced diet.