586. Check whether a number is positive.
587. #include
588. int main ()
589. {
590. int a;
591. // read the numbercout << "a ="; cin >> a;
592. // check if the number is positive
593. if (a> = 0) cout << "positive number";
594. else cout << "negative number";
595. return 0;
596. }
597. Check whether a number belongs to the interval [a, b], where a and b are real
numbers read from the keyboard.
598. #include
599. int main ()
600. {float a, b, c;
601. // we read the input data: a, b and the given number
602. cout << "a ="; cin >> a;
603. cout << "b =" cin >> b;
604. cout << "C"; cin >> n;
605. // check if n belongs to interval [a, b] using
606. operator && and
607. if (n> = a && n <= b) cout << n << "belongs to the interval [a, b]";
608. else cout << n << "does not belong to the interval [a, b]";
609. }
610. Check to see if 3 numbers read from the keyboard are null.
611. #include
612. int main ()
613. {float x, y, z;
614. // read the input data
615. cout << "x =" cin >> x;
616. cout << "y =" cin >> y;
617. cout << "z =" cin >> z;
618. // check if the numbers are invalid
619. if (x == 0 && y == 0 && z == 0) cout << "numbers are null";
620. else cout << "are not all null";
621. return 0;
622. }
623. The 3 numbers are read from the keyboard. Check to see if they were read
in ascending order.
624. #include
625. int main ()
626. {float a, b, c;
627. // read the input data
628. cout << "a ="; cin >> a;
629. cout << "b =" cin >> b;
630. cout << "C"; cin >> C;
631. // check if the numbers are in ascending order
632. if (a <= b && b <= c) cout << "the 3 numbers are in order
633. increasing ";
634. else cout << "are not in increasing order";
635. return 0;
636. }
637.
Niciun comentariu:
Trimiteți un comentariu
Rețineți: Numai membrii acestui blog pot posta comentarii.