-
-
Save mattwelke/4a97c13b859d781f813cd9c32d5712ff to your computer and use it in GitHub Desktop.
sgsgsgsfgsfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int main(void) { | |
// Without arrays | |
int x = 0; | |
int y = 0; | |
// Input | |
printf("Give me the 1st number: "); | |
scanf("%d", &x); | |
printf("Give me the 2nd number: "); | |
scanf("%d", &y); | |
// Now display it back | |
printf("1st number: %d", x); | |
printf("2nd number: %d", y); | |
// With arrays | |
int NUM_NUMBERS = 2; | |
// 2 is in square brackets to make it an array that holds 2 ints | |
int numbers[NUM_NUMBERS]; | |
// Input | |
// Loop will run two times | |
for (int i = 0; i < NUM_NUMBERS; i++) { | |
printf("Give me the %d number: ", i + 1); | |
scanf("%d", &numbers[i]); // i starts at zero remember | |
} | |
// Now display it back | |
for (int i = 0; i < NUM_NUMBERS; i++) { | |
printf("%d number: %d", i + 1, numbers[i]); // i starts at zero remember | |
} | |
// Done. Basically the idea is to use a for loop that iterates | |
// as many times as there are item slots in the array | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment