-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp5.cpp
54 lines (43 loc) · 1.28 KB
/
app5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Using Vectors
An array (vector) is a common-place data type, used to hold and describe
a collection of elements. These elements can be fetched at runtime by one
or more indices (identifying keys)
Description:
The system will accept user input and store the numbers in a vector.
Then it will show all the elements in the vector in order and
then in the inverse order.
Iteration statements
The iteration statements repeatedly execute a statement
for ( init_clause ; expression(optional) ; expression(optional) ) statement(1)
Author: Borin (https://br.linkedin.com/in/borinvini)
Edited by j3
date: jun, 12/2020
*/
#include<stdio.h>
#include<stdlib.h>
#define VECTOR_SIZE 5
int main()
{
int vec[VECTOR_SIZE] = { 0 };
// Scanning the vector w/ for loop
for (int i = 0; i < (VECTOR_SIZE); i++)
{
printf("Please enter the number at position %d :", i);
scanf_s("%d", &vec[i]);
}
// Displaying the vector w/ for loop
printf("Displaying the Vector of size %d:\n ", VECTOR_SIZE);
for (int i = 0; i < (VECTOR_SIZE); i++)
{
printf("%d\t", vec[i]);
}
// Displaying the vector inverted w/ for loop
printf("\nDisplaying the Vector inverted: \n");
for (int i = (VECTOR_SIZE - 1); i >= 0; i--)
{
printf("%d\t", vec[i]);
}
//system("pause");
return 0;
}