Commit 779a6dcd by phkarl

Upload New File

parent 03869229
Showing with 86 additions and 0 deletions
#include <stdio.h>
#include <stdlib.h> /* this library contains the rand() function */
#include <string.h>
int main(){
//Nested loops
for(int i = 0; i < 3; i++){
printf("%d\n", i);
//perform the following FOR EACH loop
for(int j = 0; j < 9; j++){
//perform the following FOR EACH loop
printf(">>%d\n", j);
}
}
printf("\n");
//2D arrays
int array[3][5] = { //this is a way to fill an array at creation
{4, 2, 4, 2, -1}, //this fills a single row
{-3, 55, 1, 223, 2}, //notice a comma between each row
{2, 4, 5, 2, 1} //and notice that this block is indented: STYLE
}; //and a closing curly-brace to match the opöening brace at line 5
/* this nested loop pair reads the matrix */
for(int i = 0; i < 3; i++){ /*i tracks with row we're on */
for(int j = 0; j < 5; j++){ /* j tracks wich column we're on */
printf("%d, ", array[i][j]);
}
printf("\n");
/* i increments to the next row onlz after we have read ALL colums */
}
printf("\n");
//2D arrays with random function
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
array[i][j] = rand() % 500 ;
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
/* this generates a random number 0-499 */
printf("%d, ", array[i][j]);
}
printf("\n");
}
printf("\n");
// string
char array2[40] = "this is a string";
//int breakPoint;
printf("|");
for(int i =0; i < 40; i++){
printf("%c", array2[i]);
}
printf("|\n|");
printf("%s", array2);
printf("|");
printf("\n\n");
// string with string.h library
char string1[40] = "this is a string";
char string2[] = "so is this";
int length = strlen(string1);
printf("%d", length);
printf("\n");
strcat(string1, " ");
strcat(string1, string2);
printf("%s", string1);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment