Task 1 : Give 2 Numbers and type them Respectively

learn C++

In this task we should write a program that gets 2 numbers then write them from big to small .

Lang : C++

 For this task you need to know :

1. cout
2. if
3. cin
4. variables

step 1 : first you should make 3 variables . name of varibales is'nt important but try to choose a name that is relevant to your work.we need 3 integer variables !

      | int num1,num2,change;

What is change variable for ?

it used to change Amount ( Content ) of num1 and num2 variables .



step 2 : use " cout " command to tell users to type 2 numbers .

     | cout << " Enter 2 Numbers ";



step 3 : now we should get 2 numbers with " cin " command .

    | cin >> num1 >> num2;


step 4 : this is most important part , we make a Condition with " if " command , we say the program to print numbers from big to small.

    | if (num1 < num2)
          {
               num1=change;
                  num2=num1;
                      num2=change;
              }

        cout << num2 << num1;


in this Condition if first number 1 is smaller than number 2 program Displaces the content of numbers then publish.

Result :

learn c++


2 comments:

  1. I can't understand last part :!

    ReplyDelete
    Replies
    1. First you should learn about if syntax : https://pico-learn.blogspot.com/2019/03/if-syntax-in-c.html#more

      Delete

Powered by Blogger.