- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find if a molecule can be formed from 3 atoms using their valence numbers in C++
As we know the valance number is the number that defines how-many bonds the atom must form with other atoms. We have the valance numbers of three atoms. We have to check whether they can make one molecule or not. Atoms can form multiple bonds with each other. So if the valance numbers are 2, 4, 2, then the output will be YES. As the bonds are like below −
1 – 2, 1 – 2, 2 – 3, 2 – 3.
Suppose the valance numbers are a, b and c. Consider c is largest. Then we have two cases in which they cannot form molecule −
- a + b + c is odd. Since every bond decreases the valance number of two atoms by 1, then the sum will be even number
- a + b < c, in this situation some unused connectors will be there.
Example
#include<iostream> using namespace std; bool canMakeMolecule(int a, int b, int c) { if ((a + b + c) % 2 != 0 || a + b < c) return false; else return true; } int main() { int a = 2, b = 4, c = 2; if(canMakeMolecule(a, b, c)){ cout << "They can form Molecule"; } else { cout << "They can not form Molecule"; } }
Output
They can form Molecule
- Related Articles
- Check if a string can be formed from another string using given constraints in Python
- Find the count of numbers that can be formed using digits 3 and 4 only and having length at max N in C++
- Print all distinct integers that can be formed by K numbers from a given array of N numbers in C++
- Find maximum number that can be formed using digits of a given number in C++
- Find if n can be written as product of k numbers in C++
- C++ program to find number of groups can be formed from set of programmers
- Count numbers which can be constructed using two numbers in C++
- Name two plants:(a) which can be grown from their broken stems.(b) which can be grown from their leaves.
- Complete the following statements :(a) Magnesium has 2 valence electrons in the ............. shell.(b) The valency of nitrogen in N2 molecule is .............(c) Isotopes have different mass numbers because their nuclei contain different number of .............(d) Some boron atoms have mass number 10 and some have mass number 11. These boron atoms with different mass numbers are called .............
- Maximum possible time that can be formed from four digits in C++
- Count of strings that can be formed from another string using each character at-most once in C++
- What is the general name of the elements having 8 electrons in the valence shell of their atoms?
- C++ code to check phone number can be formed from numeric string
- Buckminsterfullerene is a spherical molecule in which 60 carbon atoms are arranged in interlocking hexagonal and pentagonal rings of carbon atoms.(a) How many hexagons of carbon atoms are present in one molecule of buckminsterfullerene? (b) How many pentagons of carbon atoms are present in one molecule of buckminsterfullerene?
- Check if a number can be expressed as sum two abundant numbers in C++

Advertisements