Recommended time: 40 minutes.

For Loop

Q: What is a for loop?
A: A for loop …

  1. Initializes some index
  2. Checks if the condition is valid
  3. If the condition is valid, do something
    If the condition is not valid, go below the for-loop

Nested For-Loop

Q: What is a nested for-loop?
A: Well… Basically it is some for-loop inside another for-loop…

Sample Question 1

Use nested for loops to print the following:

abcde
bcdea
cdeab
deabc
eabcd

Try it yourself!

Sample Question 2

Given a string and its size in C Language, reverse the order of the characters.
e.g.
“abc” -> “cba”
“StudyHard123” -> “321draHydutS”

A function prototype is given as follows:

#include <stdio.h>

void reverseString(char* s, int sSize){

}

int main(){
    char myString[128] = "StudyHard123";
    int mySSize = 12;
    reverseString(myString ,mySSize);
    printf("%s\n",myString);
    return 0;
}

Try it yourself!


Junhao

I work at YScope, a company known for providing innovative log management and troubleshooting tools for software systems. Prior to this, I worked as an Automotive Display Software Engineer at Qualcomm Canada ULC in Markham, Canada. I am proficient with C, C++, ARM Assembly(V7), and Intel Verilog HDL, and I also have a good command of Python, JavaScript, PSQL, Java, and Go-lang. My interests lie in Embedded/Web Software Design, Development, and Integration. I developed iCtrl, a simple web application for remote graphical / terminal connections and file transfers, which has garnered over 52,000 downloads as of August 2023. Previously, I graduated as a Computer Engineering undergraduate student at the University of Toronto and worked as an undergraduate ECE297 TA there.

0 Comments

Leave a Reply

Avatar placeholder

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