You've probably heard at some point in your life that cows have 4 stomachs (or a 4-chambered stomach)
The purpose for that is because in their natural environment cows eat grass (not that there's really "natural" cows anymore, the aurochs is long-extinct, but other ruminants like bison are similar)
Grass is kind of a shitty food source for most animals, it has very little sugar and starch that your body can use for energy.
But it is full of fiber. Most animals can't really digest fiber very well, but ruminants with those extra stomachs and the help of some bacterial fermentation can. Grass and such basically gets churned around in those extra stomach chambers with some bacteria to ferment and break down into something the cows can actually use for energy.
Fermentation, of course, creates gases like CO2 which is why beer is fizzy and bread rises.
And while that bacteria can and will ferment fiber, it will ferment sugars and starches even better.
So grains like corn end up creating more gases than if they were eating grass.