[C language] Program about grains on a chessboard (Chapter 5)

From the fifth chapter of Stephen Prata’s book “C Primer Plus” – a program based on a well-known proverb that illustrates exponential growth.

Background:
The king offered to choose a reward for the hero’s service; the hero asked to put one grain on the first cell on the chessboard, two grains on the second, four on the third, and to double the grains in this way until the board is full. The king was struck by modesty and agreed .. What came of it:
Continue reading →

Posted in C language (en) | Leave a comment

[C language] Operations, Expressions, and Operators (Chapter 5)

The fifth chapter in Stephen Prata’s C Primer Plus. It deals with statements and the while loop. Curiously, in Prat’s book, while comes before if/else in terms of presentation; while in programming, loops are often taught already after conditional statements.

In addition to solutions, I will post my versions of some of the (most curious) programs from the listings. I do this – I look through the listing, then I close the book and write “in my own words”: Continue reading →

Posted in C language (en) | Leave a comment

Bitrix. We are getting certified.

In order to work effectively in bitrex, you need to read a lot.. Or better yet, get certified. Thankfully it’s free.

I recently had a need to get a Bitrix certificate. I thought it was simple.. Immediately, without first reading the documentation, I answered questions intuitively or found in the lessons, scored 82%. And for the certificate you need 90%

Briefly and without water:

1) download the engine, install it on localhost and study

2) read the documentation

3) learn courses (the most important)

4) register and pass the test (at the same time, you can use the documentation and courses)

5) add an extra line in your resume (smiley)

I will be glad to see your comments!

Posted in Bitrix (en), CMS (en) | Leave a comment

[C Language] Character Strings and Formatted I/O (Chapter 4)

The fourth chapter in Stephen Prat’s C Primer Plus.

Programming exercises and their solutions:

1. Write a program that asks for the first and last name and then outputs them in the format last name, first name.

Continue reading →

Posted in C language (en) | Leave a comment

[C language] Data in C (Chapter 3)

The third chapter in Stephen Prata’s C Primer Plus.

Programming exercises and their solutions:

1. Experiment with how your system handles integer and floating point overflows and floating point underflows; those. write a program that has such problems. (See the discussion of limits.h and float.h in Chapter 4 for the largest and smallest values.)

Continue reading →

Posted in C language (en) | Leave a comment

[C language] Introduction to C language (Chapter 2)

The second chapter in Stephen Prata’s C Primer Plus. Here the first practical tasks already appear; albeit extremely simple, for memorizing the basic syntax; therefore, I will not give their output separately. Before the tasks, a small reminder:

5 Types of Operators in C Language

  • Declaration statement
  • assignment operator
  • Function
  • Control operator
  • Empty statement

Programming exercises

1) Write a program that uses the first printf() to print your first and last names on one line, the second printf() to print your first and last names on two lines, and two more printf() calls to print your first and last names in one line. The output should look like this (but include your personal details):

Continue reading →

Posted in C language (en) | Leave a comment

[C language ] Background (Chapter 1)

So, the first chapter in Stephen Prata’s book “C Primer Plus”. Since there are no exercises in it (only one, theoretical), I will give a small summary of the chapter for the purpose of familiarization:

The advent of the C language

1972 at Bell Labs by Dennis Ritchie.

Reasons for the popularity of the C language

  • Design features
    – top-down planning
    – structured programming
    – modular design
  • Efficiency: compact and fast (only assembler is faster)
  • Portability

Continue reading →

Posted in C language (en) | Leave a comment

[C language] Introduction: Programming Exercises

I’m taking lessons from Stephen Prata’s book “C Primer Plus”. I have a book from 2000, which is very relevant to me, since the project I plan to work on adheres to the ANSI C standard. But in the process of going through the lessons, I got into the habit of taking additional exercises from the book of a later edition (2014); there are more tasks and some of them are very entertaining. Even in the old edition, there are a huge number of errors and typos, so peeping into the modern version sometimes helps to fix jambs.

I will keep my notes here on the material covered and post the “passage” of the exercises. At the beginning, it was rather lazy to post something on the blog, there were very simple things, but now I thought – why not 🙂 There are no “answers” to the exercises in the book, so the info can be useful. In the vastness of the network, people post their options for completing tasks, but there is no “conclusion” that can be useful to beginners. I also noticed that there are 100500 ways to write programs and my curly code is often different than other beginners, so it’s interesting to share it 🙂 Continue reading →

Posted in C language (en) | Leave a comment

Python: if, elif, else branching, while loops, random number generation

We continue to learn programming. Let’s move on to the study of the third chapter of the book: Michael Dawson “Programming in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where we will study if, elif, else conditional statements and while loops and learn how to generate random numbers using a module with the functions random.randint() and random.randrage().

Summary of chapter 3 with examples of programs I wrote:

Random Number Generation in Python

We load the import random module – it generates random numbers based on the built-in formula. To assign a random value to a variable, after calling the module, call one of its functions, for example,

Continue reading →

Posted in Python (en) | Leave a comment

Python: Challenges and Decisions (Chapter 2. Types, Variables, and Basic I/O. Useless Facts Program).

We continue to learn programming. After the second chapter in the book: Michael Dawson “We Program in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where I studied the features of working with text in the Python programming language, tasks were offered. Let’s do them together. I will give my solution, and you write your options in the comments.

1) Come up with two lists: valid and invalid variable names. Explain why each of the names is valid or not valid, respectively. Then come up with two more lists—of “good” and “bad” valid names—and explain your choice.

Valid variable names: name, price, password, age, size (these can be any words that are not reserved in the programming language for functions / operators)

Continue reading →

Posted in Python (en) | Leave a comment

Python: Challenges and Solutions (Chapter 1. Getting Started. The Game Over Program).

We continue to learn programming. After the second chapter in the book: Michael Dawson “We Program in Python”, 2014 (Michael Dawson “Python Programming for the Absolute Beginner”, 3rd Edition), where I studied the features of working with text in the Python programming language, tasks were offered. Let’s do them together. I will give my solution, and you write your options in the comments.

1) Learn how to trigger a bug: Interactively enter the name of your favorite ice cream brand. Then fix the error and create a command that will correctly display the name on the screen this type of ice cream.

Continue reading →

Posted in Python (en) | Leave a comment

Python: data types and the input() function

There are several data types in the Python programming language, for example:

  • integers int(x), for example, 1-2-3-4;
  • fractional numbers float(x), for example, 1.0-2.0-3.5;
  • str(x) strings, which can contain text and other characters.

The input() function has already been discussed earlier, this function allows the user to enter data into the program, this data can be further used.

Continue reading →

Posted in Python (en) | Leave a comment

Python: lifehacks for setting up a programming environment

Once you’ve installed Python on your computer, it’s best to take care of the little nuances that make life easier for programmers. Let’s go through the basic settings of the programming environment and Windows for comfortable work:

1. Changing System Environment Variables

This setting will allow you to run a program written in Python in the CMD of the Windows operating system (command line interpreter). To do this, click “Start” -> Change system environment variables:
Continue reading →

Posted in Python (en) | Leave a comment

Python: Basic Text Input and Output Operators

The very first text operations and basic information about Python that helps you start programming right away:

# Comments
Delimiters ” or “” and escaping characters \’ and \”
print(‘Hello world’) – newline
end=’…’ – next print will be glued
\ escape sequences:
\a – system speaker
\n – newline (empty line)
\t – tab type indent
+ string concatenation without delimiter
* repeat lines without delimiter
\ continuation of a line of code on the next line
input(‘Press Enter to exit’)
Basic mathematical operators (+,-,*,/,//,%).
Compound assignment statements
String methods (applied to a string with text): I am cat
.upper() I Am CAT
.lower() i am cat
.title() I Am Cat
.replace(old,new,max number of replacements) replaces the old text with the new one
.swapcase() reverse case i Am Cat
.capitalize() the first letter is capital, the rest are lowercase I am cat
.strip() string without intervals Iamcat

Continue reading →

Posted in Python (en) | Leave a comment

How to write Python code in Notepad++

If you love Notepad and want to program with it, then in the case of the Python programming language, you need to use a special plugin. There are several plugin options for Notepad++ that interpret Python:

  • nppexec;
  • Python script;
  • PyNPP.

Continue reading →

Posted in Python (en) | Leave a comment

Python – loops (for, while, break, continue)

Loops in Python are pieces of code that repeat multiple times.

range(start,stop,step) – this is how the forLoop loop looks in general, where start and stop describe the actual beginning and end of the loop, including the start point, but not including the end point; step – the step with which the computer moves from the start point to the end point (another step is called increment).

Example:
range(1,10,2) means 1, 3, 5, 7, 9

Continue reading →

Posted in Python (en) | Leave a comment

Python – ternary conditional statement (if, or, else)

Ternary operator (Ternary operator) – used in line to set conditions in assigning a value to a variable. It is easier to understand this with examples.

cat_say = “Mew”
me_say = “Hi,cat” if cat_say == “Mew” or cat_say == “Myavki” else “Who are you?”
print(me_say)
Hi,cat #result

The ternary operator essentially includes the name of the variable to which we assign a value and inside the same line we set the conditions described by the if / or / else statements. It is not necessary to use all three if/or/else statements, just if/else can be used in the condition.

Important: The ternary conditional operator in Python can be used with both strings and numbers.

Posted in Python (en) | Leave a comment