Nonnaofitaly - Tin tức sức khoẻ, làm đẹp, thể thao siêu hot
  • Home
  • Công Nghệ
  • Kinh Doanh
No Result
View All Result
  • Home
  • Công Nghệ
  • Kinh Doanh
No Result
View All Result
Nonnaofitaly - Tin tức sức khoẻ, làm đẹp, thể thao siêu hot
No Result
View All Result

C Programming Tutorial 32 – Modulus Operator

admin by admin
May 29, 2020
in Công Nghệ
21
C Programming Tutorial 32 – Modulus Operator



This video is going to introduce you to a new operator called the modulus operator (%).

In the last video I gave you this example:

int y = 5 / 2;

I told you that the value of y is going to be 1. Did you figure out what this operator does? Well it actually takes the remainder. I’ve always been pretty bad at visualizing a remainder, so I use imagery. Imagine you have a pizza with 5 slices and you want to share the pizza with your pet rat, Pepper Jack.
 
Well you give a piece to Pepper Jack, a piece to you, a piece to pepper jack, and then another piece to you. Now, you have one left over:
 
int piecesOfPizza = 5;
int numberOfEaters = 2;
int leftOver = piecesOfPizza % numberOfEaters;
 
Now you might suggest just ripping the pizza in half, but you have to realize that piecesOfPizza is an integer. This means that we cannot split the piece in half.
 
This brings up the good point that the modulus operator is designed to work with integers. That’s because if you were using numbers of type double here, you and your pet rat would both get 2.5 pieces of pizza and the remainder would be zero. The modulus operator would be useless working with floating point numbers.
 
You can do a lot of cool things with the modulus operator. One example is figuring out if a number is even or odd. if you divide a number by 2 and the remainder is anything but 0, then you do not have an odd number.
 
That is all for the modulus operator. In the next video we are going to learn our first unary operator.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support me!

Subscribe to my newsletter:

Donate!:

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content:
Facebook:
Google+:
Twitter:

Amazing Web Hosting – (The best web hosting for a cheap price!)

Nguồn: https://nonnaofitaly.com

Xem thêm bài viết khác: https://nonnaofitaly.com/cong-nghe/

Xem thêm Bài Viết:

  • Bật mí cách mod thanh trạng thái android đơn giản, không cần root
  • SSHD vs SSD: Các bước nâng cấp cho máy tính để bàn trên PC
  • Bật mí cách tạo checkbox trong excel 2007 và một số thủ thuật đơn giản
  • Cách sử dụng Excel: 18 Mẹo, Thủ thuật và Phím tắt dễ dàng trong Excel
  • Hướng dẫn lắp chảo mobiTV và cách dò kênh.
Previous Post

Toán học lớp 6 - Ôn tập chương 2 - Tiết 1

Next Post

Top 5 Game Bóng Đá Hay Nhất Cho PC Cấu Hình Yếu (Có Link Download)

Next Post
Top 5 Game Bóng Đá Hay Nhất Cho PC Cấu Hình Yếu (Có Link Download)

Top 5 Game Bóng Đá Hay Nhất Cho PC Cấu Hình Yếu (Có Link Download)

Comments 21

  1. Caleb Curry says:
    2 years ago

    Learn Javascript – http://bit.ly/JavaScriptPlaylist
    Learn Java – http://bit.ly/JavaPlaylist
    Learn C# – http://bit.ly/CSharpTutorialsPlaylist
    Learn C++ – http://bit.ly/CPlusPlusPlaylist
    Learn C – http://bit.ly/CTutorialsPlaylist

    Reply
  2. András Paranici says:
    2 years ago

    Thank you! I understand now what and how modulus operator is and works.

    Reply
  3. iamzumie says:
    2 years ago

    Sharing your pizza with your pet rat, imagine that 😀 great content, very clear videos.

    Reply
  4. Samuel Villman says:
    2 years ago

    Great educational video series, keep up the good work!

    Reply
  5. Can Kavas says:
    2 years ago

    Am I the only one who got annoyed by the way he talks?

    Reply
  6. Conrad Dierchen says:
    2 years ago

    b) I'm a total geek and already know most of this stuff so I'm watching it at 1.5x speed

    Reply
  7. Marlond Sanchez says:
    2 years ago

    Good video

    Reply
  8. Marlond Sanchez says:
    2 years ago

    if i apply the modulus operator between 4 and 8 the remainder would be 0.5, but when I run the program the answer is 4, What is wrong with fractions?

    Reply
  9. Gage McGilvra says:
    2 years ago

    me and my friend are both coders and would like for u to stop being so nerdy; we aren't all like this and it's disconcerting. that being said, good explanation… ur just corny as hell

    Reply
  10. Tim Shikali says:
    2 years ago

    Yo' IDE too dark can't see clearly

    Reply
  11. [CØV]RuИCodeX says:
    2 years ago

    Can someone please explain what a modulator sign is? I'm so confused on how to work out a modulus operation

    Reply
  12. MizManTheFryingP says:
    2 years ago

    Straight to the point with great visual explanations and a fun attitude.
    Fantastic tutorial Caleb, keep it up!

    Reply
  13. C Language says:
    2 years ago

    https://youtu.be/zyK_cctGwYs

    Calculate modulus without using %
    Watch my video to click the above link…..thank you

    Reply
  14. woke zombie says:
    2 years ago

    wise words, about time, agreed.

    Reply
  15. Alaa Altinawi says:
    2 years ago

    what about the remainder of floating numbers

    Reply
  16. Learn Crap Quick says:
    2 years ago

    thanks

    Reply
  17. Learn Crap Quick says:
    2 years ago

    i gave myself this example: 13 % 3 is 1, because if all the 3 in 13 get eaten there will be 1 left
    there is four "3" inside 13
    1 is extra and it remains
    or 1 doesn't count as 3 so it remains

    Reply
  18. Ethan Ungar says:
    2 years ago

    i love your vids thank you

    Reply
  19. FBI says:
    2 years ago

    i guess this is what haha sounds like when someone texts it

    Reply
  20. Chemik says:
    2 years ago

    you are really annoying

    Reply
  21. neo nkuna says:
    2 years ago

    I want the modulus where the first number is smaller than the second number

    Reply

Leave a Reply Cancel reply

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

Tin Hàng Ngày

Hướng dẫn chi tiết cách ứng tiền 20k cho thuê bao Vietnamobile

Hướng dẫn chi tiết cách ứng tiền Vietnamobile 20k nhanh nhất

September 13, 2021
Zippo thương hiệu nổi tiếng của Mỹ

Bật lửa zippo là gì? Vì sao thương hiệu Zippo nổi tiếng như vậy? 

June 9, 2021
Tủ đựng tài liệu là thiết bị nội thất được nhiều người quan tâm

Lựa chọn tủ tài liệu thế nào là tốt nhất cho văn phòng

April 16, 2021
Bình hút tài lộc mang vận may cho gia chủ

Cách chọn bình hút lộc theo bản mệnh gia chủ

April 3, 2021
Số 79 và 39 mang đến nhiều may mắn

Tuyệt chiêu mua trúng sim Thần Tài Ông Địa không phải ai cũng biết!

January 24, 2021
Tượng Phật Di Lặc – gợi ý quà mừng tân gia bạn không nên bỏ qua

Tượng Phật Di Lặc – gợi ý quà mừng tân gia bạn không nên bỏ qua

October 5, 2020
  • Chính Sách Bảo Mật
  • Liên Hệ

© 2022 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Công Nghệ
  • Kinh Doanh

© 2022 JNews - Premium WordPress news & magazine theme by Jegtheme.