<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexandru</title>
    <description>The latest articles on DEV Community by Alexandru (@alexandruv156).</description>
    <link>https://dev.to/alexandruv156</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3982557%2F864581d8-c476-4809-8c92-a0c0cafecfa3.png</url>
      <title>DEV Community: Alexandru</title>
      <link>https://dev.to/alexandruv156</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alexandruv156"/>
    <language>en</language>
    <item>
      <title>🚀 Math vs. Strings: Two Ways to Manipulate Digits in C++</title>
      <dc:creator>Alexandru</dc:creator>
      <pubDate>Sun, 14 Jun 2026 11:03:37 +0000</pubDate>
      <link>https://dev.to/alexandruv156/math-vs-strings-two-ways-to-manipulate-digits-in-c-geb</link>
      <guid>https://dev.to/alexandruv156/math-vs-strings-two-ways-to-manipulate-digits-in-c-geb</guid>
      <description>&lt;p&gt;In programming, there’s rarely just one way to solve a problem. In this article, we’ll take a classic coding challenge—replacing even digits in a number with 1—and tackle it using two completely different paradigms: pure mathematical logic and modern string manipulation.&lt;/p&gt;

&lt;p&gt;Along the way, we’ll explore how to handle tricky edge cases (like 0 and negative numbers) and highlight a common, dangerous C++ rookie mistake: accidentally destroying your variables inside a loop. Whether you are looking for raw performance or clean, readable code, this quick guide has got you covered!&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;

using namespace std;

int main()
{
    int number;
    int number_copy;
    int nt = 0; // Stores the result for the first method

    cout &amp;lt;&amp;lt; "Enter your number: ";
    cin &amp;gt;&amp;gt; number;

    // --- EDGE CASE HANDLING ---
    // Rule 1: We only accept positive numbers for this algorithm
    if (number &amp;lt; 0) {
        cout &amp;lt;&amp;lt; "Please enter a positive number!" &amp;lt;&amp;lt; endl;
        return 0;
    }

    // Rule 2: Handing zero separately because it's an even number 
    // and mathematical division loops won't process it.
    if (number == 0) {
        cout &amp;lt;&amp;lt; "The changed number for the first method is: 1" &amp;lt;&amp;lt; endl;
        cout &amp;lt;&amp;lt; "The changed number for the second method is: 1" &amp;lt;&amp;lt; endl;
        return 0;
    }
    else {
        // CRITICAL STEP: Back up the original number.
        // The while loop below will destroy the 'number' variable (reducing it to 0).
        number_copy = number;

        long long p = 1; // Base 10 multiplier to reconstruct the number in the correct order

        // --- METHOD 1: THE MATHEMATICAL APPROACH ---
        while (number != 0) {
            int l = number % 10; // Extract the last digit

            // Check if the digit is odd
            if (l % 2 != 0) {
                nt = nt + l * p; // Keep the odd digit as it is
            }
            else {
                nt = nt + 1 * p; // Replace the even digit with 1
            }

            p = p * 10;       // Move to the next decimal place (units, tens, hundreds...)
            number = number / 10; // Remove the last digit from the number
        }
    }
    cout &amp;lt;&amp;lt; "The changed number for the first method is: " &amp;lt;&amp;lt; nt &amp;lt;&amp;lt; '\n';

    // --- METHOD 2: THE STRING MANIPULATION APPROACH ---
    // We use 'number_copy' because 'number' is now 0.
    string numberStr = to_string(number_copy); // Convert the integer to a string

    // Loop through each character of the string
    for (int i = 0; i &amp;lt; numberStr.length(); i++) {
        // Check if the current character represents an even digit
        if (numberStr[i] == '0' || numberStr[i] == '2' || numberStr[i] == '4' || numberStr[i] == '6' || numberStr[i] == '8') {
            numberStr[i] = '1'; // Replace the character with '1'
        }
    }

    // Convert the modified string back into a 64-bit integer (long long) to prevent overflow
    long long nt2 = stoll(numberStr);
    cout &amp;lt;&amp;lt; "The changed number for the second method is: " &amp;lt;&amp;lt; nt2 &amp;lt;&amp;lt; endl;

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>cpp</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>C++ Basics: How to Determine a Triangle Type Using IF-ELSE Statements</title>
      <dc:creator>Alexandru</dc:creator>
      <pubDate>Sat, 13 Jun 2026 11:11:55 +0000</pubDate>
      <link>https://dev.to/alexandruv156/c-basics-how-to-determine-a-triangle-type-using-if-else-statements-ccf</link>
      <guid>https://dev.to/alexandruv156/c-basics-how-to-determine-a-triangle-type-using-if-else-statements-ccf</guid>
      <description>&lt;p&gt;A classic problem when learning C++ is checking what type of triangle you have based on 3 sides given by the user. Let's see how to write this logic cleanly using if-else structures without nesting too many conditions.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#include &amp;lt;iostream&amp;gt;
using namespace std;

int main() {
    double a, b, c;
    cout &amp;lt;&amp;lt; "Enter three sides of the triangle: ";
    cin &amp;gt;&amp;gt; a &amp;gt;&amp;gt; b &amp;gt;&amp;gt; c;

    // Check if the sides can actually form a triangle
    if (a + b &amp;gt; c &amp;amp;&amp;amp; a + c &amp;gt; b &amp;amp;&amp;amp; b + c &amp;gt; a) {
        if (a == b &amp;amp;&amp;amp; b == c) {
            cout &amp;lt;&amp;lt; "The triangle is Equilateral" &amp;lt;&amp;lt; '\n';
        }
        else if (a == b || b == c || a == c) {
            cout &amp;lt;&amp;lt; "The triangle is Isosceles" &amp;lt;&amp;lt; '\n';
        }
        else {
            cout &amp;lt;&amp;lt; "The triangle is Scalene" &amp;lt;&amp;lt; '\n';
        }
    } else {
        cout &amp;lt;&amp;lt; "These sides cannot form a valid triangle" &amp;lt;&amp;lt; '\n';
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>cpp</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
