Skip to content

Instantly share code, notes, and snippets.

@mattwelke
Last active June 8, 2017 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwelke/4a97c13b859d781f813cd9c32d5712ff to your computer and use it in GitHub Desktop.
Save mattwelke/4a97c13b859d781f813cd9c32d5712ff to your computer and use it in GitHub Desktop.
sgsgsgsfgsfg
#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