C Programlama Dersleri #4 || Diziler (Array), Girdi Alma, Matematik İşlemleri || ENGINARING

Hello friends, I am Berkay Cagli,
Welcome to the Enginaring Channel C programming tutorial lesson 4 In this lesson, I will teach you arrays, getting input and math operators. Now, lets start with what are the things that we call arrays. Array is actually a feature that allows us to declare multiple variables with one command Now, actually in the last video, we used arrays to make string without knowing what it is. Of course we will learn how we did that in this video. Normally while declaring variables, we were writing our variable type, and variable name afterwards. To make an array, we write our variable type, we write variable name afterwards, and in square braces we are writing how many variables we want to declare For example, let’s do it right now. We call it “int”, we call it degisken, afterwards
we’ve opened our square brackets, now I Let’s say I want to declare 3 different variable and afterwards we are writing equal. then we are opening our square brackets, look normally we weren’t opening square brackets. but in this we are opening. We’re entering our values ​​in turn. I entered 1, 2, 3 now. Next we put semicolon at the end Then we came to printf. printf is still the same as integer
how do we print it, ie format specifier we are writing it. %d Then we put our comma, followed by
degisken, then we are opening square brackets and we choose the value we want to print. Now look here is a very important thing here. Normally people start counting from 1. But computers start counting from zero. So this is not actually the 1st variable, it’s actually
the value here is actually the 0th variable. That’s 1st variable. That’s second variable. So, for example,
if you type 1 in brackets we are actually not printing the value 1,
as you see it 2. Likewise, we just did an integer
now we are making float. The same things applies when we change to float. For example, we wrote here 1.22, after that
we put a comma, we wrote 2.33, we put comma We wrote 3.44, followed by the parentheses
We put a semicolon next to it. Again we are writing %f to printf Afterwards degisken, in square brackets we are writing which variable we want to print. At the moment, for example, 2, 0 1 2 will print this value. Do not you believe? Here you go. Look, it prints a value of 3.44. Of course the float is very similar to the double
I do not even need to make a double. You are writing double here in the same way in float. No need to change anything else. It prints in the same way. Now finally, there is a place where thing changes and it is character. Character arrays are a little different from these arrays. Now I will show the character array
to you. Now we can assign the character sequence in two ways. Firstly as we have seen in last video, I will talk about assigning as string. I wrote a char aynidesigken(same variable in turkish) here because the variable doesn’t change it’s same variable. they will write the same thing. I wrote dort(four) here, between two quotes,
actually, between two double quotes, yeah seems odd I wrote dort between two doublequotes. Now
the square braces next to this variable if you leave it empty,
it will calculate how many characters will be assigned then automatically assigns. But you write it on your own so you won’t have problem later on. Now here we have 4 characters. But as we saw on the last video,
We do this 5 because there is a string terminator on the side. Now for the second assignment type. This time, we will write 4 again, but this time
we will assign each character separately. We came here now. First we opened our single quotes,
We wrote d in the middle. Look, this is unique to character, this
is something specific to the character variable type. You wrote it, followed by a comma. For example, how else can you assign this,
you can assign it with an ASCII value. So for example we wrote d, followed by 111 which is the ASCII value of “o” Look I did not use quotes when writing 111i. Let’s write the rest normally. We wrote it like this. Again, we set the size of our variable to 5. Now in PrintF I wrote it directly to you. For the sake of keeping the video short. When we type% c, we can print only one character. When we type% s, we can print all character array
at the same time. Now, for example, how can this be useful ?
I would say for example that I want to change one of the characters of “dort” here I came here, I want, for example,
I wanted to change one variable. Then I write degisken, I open square brackets next to it
afterwards for example The variable that i want to change, 0
1 2 3, for example I want to change the two, not the two, the second variable, ie 0 1,
I am writing the variable 1 I write=Then I’m writing the value I will assign. For example I say “o”. By putting a semicolon at the end, for example
in this way, in an array you can change you can specifically change one of the values. But I will not change it now
I already assigned these values ​​myself. But, for example,
I want to print them seperately. I said% c % C % C I wrote% c here, degisken[0] it starts counting from 0
do not forget, degisken[1], degisken[2], degisken[3], afterwards I came to % s I came to% s because I wrote degisken here as variable I wrote% s afterwards
And I wrote aynidegisken variable here Now I’m running this program. At first it printed “d” as you see it,
so it printed the first variable Printed the second variable Printed the third variable Printed the fourth variable Later converted this into a string,
it printed it, followed by printing aynidegisken variable Now let’s get programming to the next level
and communicate with the user. And get input from the user. First of all, I have two variables to declare. First is string. Our variables name will be “ad” since we will get name in it (name=ad in turkish) We can get a name of about 50 characters. I also declared one float. We will take “boy”(height) as a float. Now we are going to first want couple values from user Let’s say printf, your name afterwards Let’s write “your name”. Or let’s write “what is your name” Look we’re now going to get input.
We are writing scanf. After writing scanf we write double quotes and then
We are writing which format specifier we want we want to get the input,
So for example I am taking a string right now I’m writing %s for what I want. After you’ve closed the double quotes, comma and we are writing the name of our variable. So for example, our current variable is ad(name),
ad(name) variable, followed by a semicolon We put it. Now, let’s say printf “How tall are you” Now something different comes into place We wrote the same again, we wrote% f, but
From now on we can not write here “boy” directly. Here, before the variable we have to write ampersand “&” When I talk about pointers in the future
you will understand but you don’t have to understand at the moment Just, know it as a symbol that you will place before variables other then strings. Let’s say, then, printf “%s is a perfect guy that is %.2f tall” Then we put our comma behind,
Name, boy, we normally wrote. Now let’s run this program. It asked what is your name as you’ve seen. Let me write, Berkay. How tall are you ? 1.83. “Berkay is a great person 1.83 tall”
it prints on the screen. Yes friends now lets do the same
with an integer. We’ve declared as int para(money). printf how much money is there in your pocket
We wrote, and we used escape character afterwards I mean we used escape character to switch to the new line scanf is called, followed by %d, that is format specifier of integer followed by ampersant sign, we wrote our money afterwards,
I mean we wrote the money (para) variable. Then printf “now there is this much, %d, amount of money in your pocket” it will print. Now, for example. How much money do you have in your pocket right now? Let’s say we have 0 There’s 0 amount of money in your pocket right now. Yes, the sentence may have been pointless
but it is still an example. Now let’s come to math operations. Let us say, for example, how much money we have now
there is someone who will give us money and how much money we will have at the end, we want to learn that So I write a program right now. Let’s use math operations now. I set two variables as float
of course. one is para (money) other one is gelir (income) So printf, we’re printing at first. We printed “How much money you have at the moment” Then, with %f, we assigned a value to money variable. Then we asked for amount of income, and assigned a value to income (gelir) After that, look, we say total money.
I printed it as .2 You do not need to print as .2
We will give it in terms of .2 So I wanted it to print with .2 Money + income comes after the comma, I can write money + income See here it does the mathematical operation here What its doing here is it sums money with income Let’s see the program working. How much money do we have right now? Let’s say
Take 20 pounds, 20.00 actually. How much is your income this month? Let it be 15 pounds. Your total: 35 TL, not TL
Turkey, of course, but we’re in Turkey I said in the form of TL Now what can we write here ? We can write minus instead of plus for example What happens when we write minus? How much money you have at the moment, 20 How much is your income this month? 15. Your total is 5 tl. We wrote cross here instead of minus. So we put this star sign. As you can see, your total balance is 300
says. Let’s say we put a division sign here,
We started from behind. And the time we run … 20, let’s divide by 4. it prints as 5. I mean, it’s doing the division. Now friends let’s do this division with integer. The division process in Integer changes slightly. At the Integer, for example,
I’m running. Look exactly the same as int
version, ie format specifiers% d, this is an integer. See when we hit it now. I want to write something right now, 23
I want to write, and how much money do you have this month I want to write 5. Now when you normally divide 23 to 5
what will be the result? Something around 4.6 right ? But you get 4 directly. Because this is a complete integer
division. I mean there are 4 5s in 23 but the remaining 3 is none of my business program says. Now for getting reminder what can you do ? In order to obtain reminder, you do like this You put the “%” sign here. When you put the% sign, watch
I will give the same inputs How much do you have now? When we write 23, 5 it gives the remaining from this operation. Yes friends now, let’s come to our last example In this case, our currency in TL
we will turn to other currencies I wrote three type here and wrote the coefficients here afterwards i wrote Printf “Enter the amount of money that you want to change currency of” After that, we forgot & here Look, I can forget about it sometimes, but
if you forget, your program won’t work It will give error, don’t forget that scanf %f, you are assigning a value to the para variable. Let’s also make this like this so it sends to the new line After that you enter a certain money variable. After that it will print as “your money is this much american dollar, euro, british pound” Let’s test it now. Now let’s say I have 1200 lira, let’s play a little big huh ? 1200.50 lira for example, I also want to convert that 50 kurus My money, for example, converts to this much american dollars, this much euro, this much British pound Now, after a few more examples
I think I’ve showed you what kinda programs you can make with getting input from user Thank you so much for listening to me,
Hope to see you in next video.

Leave a Reply

Your email address will not be published. Required fields are marked *