Molecule Atomic Wt (CHONS) Molecules - MATLAB Cody - MATLAB Central

Problem 1856. Molecule Atomic Wt (CHONS) Molecules

Difficulty:Rate
Given a molecular equation string determine its atomic weight.
Limited atoms of C H O N and S where wts are rounded to [12 1 16 14 32].
Example molecules and wts:
CH4 16; CH3OH 32; O2 32; C6H6 78; H2SO4 98; radical SO4 96;
Input: Molecular Eqn [string with no spaces, all Caps]
Output: Molecular Wt [approx wt]
Source: Saw this as a question on Matlab Answers.
Update: Test suite has been enhanced to include double digit numbers.

Solution Stats

44.54% Correct | 55.46% Incorrect
Last Solution submitted on Apr 14, 2024

Problem Comments

Solution Comments

Show comments
R2025a Pre-release highlights
This topic is for discussing highlights to the current R2025a Pre-release.
10
2

Problem Recent Solvers46

Suggested Problems

More from this Author308

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page