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

Located in Markham, I am working as an Automotive Display Driver Engineer at Qualcomm Canada Inc. Previously, I graduated as a Computer Engineering undergraduate student at the University of Toronto and worked as an ECE297 TA there. As I once tutored ECE243 and APS105 at EngFastlane, now I am also providing tutoring service at TopLogic Inc.. I am proficient with C, C++, JavaScript and Python and familiar with PSQL, Java, Intel FPGA Verilog and ARM Assembly(V7). My interest is in Software Design and Development.

0 Comments

Leave a Reply

Avatar placeholder

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