Today we will learn a new concept that is found in most of the programing language. It is one of the essential topics and it helps alot when it comes to coding with real life solutions.
I am talking about Arrays. Arrays are collection of similar types of data together under a single entity or name. This definition can vary from different programing languages.
For example in C the array can either be containing numbers or characters but in python array can contain different data types together.
Let us look at the program itself :
Copy the basic code from below :
#include <stdio.h>
int main() {
int array[5];
printf("Enter 5 numbers: ");
for (int i = 0; i < 5; i++) {
scanf("%d", &array[i]);
}
printf("You entered: ");
for (int i = 0; i < 5; i++) {
printf("%d ", array[i]);
}
return 0;
}
Here our array is on int type that means it will store integer values like 1,2,3,4,5 etc. We have used a for loop and this is the way we define array's elements.
The output of the array program will depend on the input provided by the user.
In this example, the user enters the numbers 1 2 3 4 5 as input, and the program stores them in an array called "array". Then the program prints the numbers in the array.
It's important to note that the program uses a for loop to iterate through the array and print each element. And also the input format should be the same as the format that is mentioned in the scanf statement.
It's also worth noting that the numbers in the array are separated by spaces, this may vary depending on how the program is written.
What do you think will happen if we enter a character at the time of input. Here is what i saw in the output.
Can anyone tell what is the logic behind this output ?
If you also want to learn coding then find your teacher according to your language. For me i am comfortable with hindi language and follow hindi teachers.
You can refer to my teacher below in case you are also comfortable with hindi.
I will soon call myself a trader and a small programmer together.
Happy trading and keep learning what you love.
@tipu curate
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Upvoted 👌 (Mana: 3/4) Get profit votes with @tipU :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit