Basic programming course: Lesson #3 Operations

in #devjr-s20w32 months ago

Hi friends,

I am Jyoti from India. Hope you are all well and safe, here I am going to participate in the SEC S20 W3 contest: https://steemit.com/devwithseven/@alejos7ven/basic-programming-course-lesson-3-operations-esp-eng organised by @alejos7ven .

I have already learned C and C Plus Language Course so these lessons are very easy for me to learn but since it has been a long time it is very helpful for me to recall.


Copy of @jyoti-thelight (2).jpg

SOURCE

Operations

Give a brief summary of what arithmetic, comparison and logical operations are for.

Arithmatic operations are used to deal with mathematic calculation such as addition, subtraction, multiplication, division, percentage etc.

Arithmetic Operator

OperatorOperationUsage
Addition +Sum A and BA + B = 23
Subtraction −Difference of A and BA − B = 17
Multiplication *A multiplied by BA * B = 60
Division /Divides A by BA / B = 6.666667
Percentage%Reminder of the divisionA % B = 2

image.png

Relational Operator(Comparison Operator)

Comparing two values ​​with each other is called Relational Operator.

NameOperatorDescriptionResult
Less than<g=40g, s=80g(g<s)? Does that mean gold is less than silver?true
Less than or equal<=g=30g, s=60g(g<=s)? Does that mean gold is less than silver? Or is there an equal-again?is less. true
Greater than>g=20g, s=23g(g>s)? Does that mean gold is more expensive than silver?is less. false
Greater than or equal>=g=35g, s=35g(g>=s)? Does that mean gold is more expensive than silver? Or is there an equal-again?There is equal-again. true
Equal==g=68g, s=35g(g==s)?Does that mean gold and silver are equal? No. false
Not equal!=g=68g, s=35g(g!=s)? So gold and silver are not equal? Yes. Both have different weightstrue

Logical Operator

Evaluating two or more relational operators simultaneously is called a logical operator

All logical operators can be used to evaluate conditon simultaneously. Also can be used many times.

NameOperatorDescriptionResult
AND&&p=70, d=75, g=3000, s=780((g<s) && (p>d))? That is, return true only if all conditions are true. otherwise return falsefalse
ORORp=70, d=75, g=300, s=780((p>d) OR (g<s))? That is, return false only if all conditions are false. otherwise return truetrue
NOT!g=20, s=23!(g>s)? When applying the logical not(!) operator with a condition, it will return false if the condition is true or if the condition is false, it will returntrue

Note: In the second row "OR" operator code is "||" due to coding dificulties I typed OR instead of ||

Make a program that asks the user for 2 numbers and evaluates if both numbers are the same.

I 'll create a C program that asks the user for two numbers and evaluates if they are the same.

Here's a simple C program that accomplishes this task:

Step 1:

I use to C compiler to make this program, in the main function, I declare two variables of type double to store the numbers. I use double to allow for decimal numbers.
We can use printf to prompt the user to enter the first number, and we can use scanf to read the user's input and store it in number1. The % lf format specifier is used for reading double values.

We can use an " If-else statement" to compare the two numbers:

If number1 is equal to number2, print "The numbers are the same."

Otherwise, print "The numbers are different."

image.png

Step 2:

image.png

Step 3:

image.png

When I hit enter to execute the result, it shows the result as the two number are diffrent. So our coding is sucessful.

This application provides a basic command-line interface for entering and comparing two values. It works with both integers and decimals. It should be noted that comparing floating-point integers for exact equality might be difficult at times owing to accuracy difficulties, but this simple comparison will work for the majority of applications.

Transform the following mathematical expressions into arithmetic expressions on your computer:

Fine the value of X , Y and Z

X=8/2+5/5, Y= (8-2) (5+4), Z =( ((4+8)3))/2)/3

Here I use code to sovle the sum using arithmatic operations and found the value of X,Y and Z.

image.png

image.png

I would like to invite
@sur-riti
@max-pro
@abdullahw2

to take part in this contest.

💚THANK YOU 💚

Discord : @jyoti-thelight#6650 Telegram :- https://telegram.org/dl

jo.gif

Sort:  
Loading...

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

Thank you very much for invitation but I dont know about computer and c++ or jawa.

Thank you for the response, although if you don't know, you can try with this course's lessons

Good luck, Jyoti! It’s great to see you revisiting programming through this contest. Even though you’ve already learned C and C++, refreshing your knowledge is always valuable. Your explanation of operators and the example program you shared are helpful for anyone new to coding. Keep up the great work, and I look forward to seeing more of your contributions. Best of luck with the contest!

Coin Marketplace

STEEM 0.20
TRX 0.19
JST 0.034
BTC 91295.19
ETH 3130.58
USDT 1.00
SBD 2.89