The formula of a metallic element is simply the element's symbol because though there is metallic bonding of the atoms, in the giant metallic structure, there is almost an infinite number of atoms: the atoms do not go round in groups with specific numbers of atoms.
Noble gases (group 8/0) are monoatomic so a noble gas' formula is just its symbol.
Any other element which is a gas at room temperature and atmospheric pressure consists of atoms which pair up to form diatomic molecules (X2). All the halogens (group 7) are diatomic whether solid, liquid or gases at room temperature. A useful mnemonic for diatomics is "I Never Bring Classwork Home On Fridays (I2, N2, Br2, Cl2, H2, O2, F2).
Some of these you just have to learn. The name can give a clue: mon_ means 1, di_ means 2, tri_ means 3 and tetra_ means 4. If you are given an oxidation number (in Roman numerals) in the name, then you can work out the formula by pretending that the compound is made of ions.
Strong acids have covalent bonding when pure in the absence of water but they become ionic when dissolved in water. Weak acids remain largely covalent and undissociated in water. You should memorise these because they are such important substances.