You get a bonus - 1 coin for daily activity. Now you have 1 coin

An example of solving problems in C (C ++) if switch for do while while Arrays User-defined functions

Lecture



Examples of solving problems in C - branching


Determine the maximum and minimum values ​​of two different real numbers.

#include <iostream.h>
#include <conio.h>

int main (int argc, char * argv [])
{
float a = 2.14, b = 3.54;

if (a> b)
cout << a << "-Max"
<< b << "-Min \ n";
else
cout << b << "-Max"
<< a << "-Min \ n";
getch ();
return 0;
}


The year and month of birth of a person are known. Determine the person's age for March (3 month) 2008

#include <iostream.h>
#include <conio.h>

int main (int argc, char * argv [])
{
int year = 1967, month = 8;

if (month <3)
cout << "His age:" << (2008 - year - 1) << '\ n';
else
cout << "His age:" << (2008 - year) << '\ n';
getch ();
return 0;
}

Determine whether among the digits of a given three-digit integer are the same

#include <iostream.h>
#include <conio.h>

int main (int argc, char * argv [])
{
int a = 144, edinici, decjatki, sotni;
sotni = a / 100;
decjatki = (a% 100) / 10;
edinici = a% 10;

if (sotni == decjatki)
cout << "There are identical numbers!";
if (sotni == edinici)
cout << "There are identical numbers!";
if (decjatki == edinici)
cout << "There are identical numbers!";

getch ();
return 0;
}

Choose the largest of the three given numbers

#include <iostream.h>
#include <conio.h>

int main (int argc, char * argv [])
{
int a = 15, b = 12, c = 35;

if (a> b && a> c)
cout << "a is the largest number";
if (b> c && b> a)
cout << "b is the largest number";
if (c> a && c> b)
cout << "c is the largest number";

getch ();
return 0;
}

created: 2016-09-08
updated: 2021-03-13
261



Rating 9 of 10. count vote: 2
Are you satisfied?:



Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

C ++ (C plus plus)

Terms: C ++ (C plus plus)