Postări

Se afișează postări din mai, 2025

Program that counts "while" loops (excluding do-while loops)

  #include <iostream> #include <fstream> #include <string.h> using namespace std; ifstream fin ("whilecount.txt"); int main() {     char linie[100];     int nrtot_while=0, nr_linie=0;     while(!fin.eof())     {         fin.getline(linie,100);         nr_linie++;         if (strstr(linie,"while")>0 && !( strstr(linie,";")>0))         {             nrtot_while++;             cout << nr_linie << endl;         }     }         cout << "Number of 'while' instructions in the file: " << nrtot_while;     return 0; } //This program was designed in CodeBlocks - version 20.03 in the C /C++ language.

Program that counts all "for" instructions from a file

#include <iostream> #include <fstream> #include <string.h> using namespace std; ifstream fin ("in.ppc"); int main() {     char linie[100];     int nrtot_for=0, nr_linie=0;     while(!fin.eof())     {         fin.getline(linie,100);         nr_linie++;         if (strstr(linie,"for")>0)         {             nrtot_for++;             cout << nr_linie << endl;         }     }         cout << "Number of 'for' instructions in the file: " << nrtot_for;     return 0; } //This program was designed in CodeBlocks - version 20.03 in the C /C++ language.

Counts ascending FOR loops

According to the following rule (AVR035: Efficient C Coding for AVR, Rev. 1497D–AVR–01/04) : " 9. Use descending loop counters and pre-decrement if applicable."  , reducing code of the Atmel ( NXP ) company on AVR series microcontrollers, using the appropriate for loops, helps optimize the code at the file size level.  // THIS PROGRAM COUNTS THE NUMBER OF ASCENDING FORS AND OUTPUTS THE LINE WHERE THEY BELONG #include <iostream> #include <fstream> #include <string.h> using namespace std; ifstream fin ("file_in.ppc"); int main() {     int ct=0,lin=0;     char linie[101];     while(!fin.eof())     {         fin.getline(linie,100);         lin++;         if((strstr(linie,"for")>0) and (strstr(linie,"++")>0))         {             ct++;             cout<<lin<<endl; ...

Optimized SWAP gate-circuit

Imagine
      by Bocuț Teodora Ana, Brodețchi Anda Ioana      In the world of embedded software, efficiency isn't just a nicety—it's often a necessity. We're constantly striving to make our code smaller, faster, and more power-efficient, pushing the boundaries of what's possible on resource-constrained hardware.      This quest for optimization often leads us back to the very foundations of computer science. Even a task as seemingly simple as swapping two values can hold surprising depth. The legendary Donald Knuth, in his seminal work "The Art of Computer Programming," particularly Volume 4A, Fascicle 1 (page 52, for those following along!), delves into such bitwise wizardry, showcasing elegant solutions like the XOR swap for interchanging variables without a temporary holding space. This clever technique, along with others like the classic addition-subtraction swap or the "three-glass method", forms a bedrock of algorithmic thinking.   ...