Recommended time: 40 minutes.
For Loop
Q: What is a for loop?
A: A for loop …
- Initializes some index
- Checks if the condition is valid
- 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!
0 条评论