- #1
mbolhi
- 10
- 0
Hi all,
I am learning C language in S-Function Simulink
does anyone prgram in C?
I need help please
Thanks
I am learning C language in S-Function Simulink
does anyone prgram in C?
I need help please
Thanks
mbolhi said:here is my code and thanks for your help in advance!
double theta, A1, A2, phi, C, A0, L ;
theta = 1;
A0 = 0.7;
L = 0.160;
C = sqrt(A0*A0 + L*L);
phi = atan(A0/L);
//**************************************************************************
if (C*C + L*L - 2*L*C*cos(phi - theta)>0.0);<---- Remove semicolon
{
A1 = sqrt(C*C + L*L - 2*L*C*cos(phi - theta));
}
else if (C*C + L*L - 2*L*C*cos(phi - theta)<0.0);<---- Remove semicolon
{
printf("error -- sqrt_negative\n");
}
if (C*C + L*L - 2*L*C*cos(phi + theta)>0.0);<--- Remove semicolon
{
A2 = sqrt(C*C + L*L - 2*L*C*cos(phi + theta));
}
else if (C*C + L*L - 2*L*C*cos(phi + theta)<0.0);<--- Remove semicolon
{
printf("error -- sqrt_negative\n");
}
I get these errors:
syntax error; found `if' expecting `;'
unrecognized statement
The C programming language is a general-purpose programming language that was created in 1972 by Dennis Ritchie. It is a high-level language that is used for developing operating systems, applications, and other software. C is known for its efficiency, portability, and speed.
Learning C can provide a strong foundation for understanding other programming languages due to its low-level nature. It also allows for efficient memory management and has a large library of functions that can be used for various purposes. Additionally, many software applications and operating systems are written in C, making it a valuable skill for programmers.
The basic data types in C are integer, character, float, and double. Integers are used to represent whole numbers, characters are used to represent individual characters, and floats and doubles are used to represent decimals. There are also derived data types in C, such as arrays, structures, and pointers, which are made up of the basic data types.
To write a simple program in C, you will need to have a text editor and a C compiler. The program should start with the #include <stdio.h> statement, followed by the int main() function, which is where the program execution begins. You can then write your code within curly braces {} and use semicolons ; to end each line of code. Once you have written your program, you can compile it using the C compiler and then run it to see the output.
To improve your skills in C programming, it is important to practice regularly and work on different projects. You can also read books and online resources to learn new techniques and best practices. Collaborating with other programmers and participating in online communities can also help you learn from others and improve your skills. Additionally, setting small, achievable goals for yourself can help you track your progress and continuously improve.