When you start learning to code in any language you first learn the method of creating programs that are direct and static that is they already have everything defined before the program is run.
For example if you want to add two numbers then you by initialize two integers and simply add them. This is the case where results are static.
Second method is something we call dynamic programming i.e where we take inputs by the user and now you can take inputs after the program is run and in this case you can perform the same program with different inputs.
Let us learn dynamic programming in C. This is a simple lesson of multiplication and addition program in C.
Here is the program itself.
You can copy the entire code from below.
#include <stdio.h>
int main() {
int num1, num2, num3;
char operation;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("Enter the third number: ");
scanf("%d", &num3);
printf("Enter '*' for multiplication or '+' for addition: ");
scanf(" %c", &operation);
if (operation == '*') {
printf("The result of multiplying the numbers is: %d\n", num1 * num2 * num3);
} else if (operation == '+') {
printf("The result of adding the numbers is: %d\n", num1 + num2 + num3);
} else {
printf("Invalid operation.\n");
}
return 0;
}
To run the program, compile it using a C compiler and then run the resulting executable. The program will prompt the user to enter three numbers and a character representing the operation to perform ('*' for multiplication or '+' for addition). It will then perform the specified operation on the numbers and print the result.
Now let us see some examples/outputs to understand how the program will work.
There can be three scenarios , either the user use '+' sign for addition operation or '*' sign for multiplication operation, or any other sign that gives us a error message.
So with these example we have learnt a very beginning of dynamic programming.
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.