C language is one of the programming languages that is near hardware code.
Here is the sample code of c:
Create a file with .c
#include <stdio.h>
#include <math.h>
#define PI 3.1415
int main() {
const double PI2 = 3.14;
int a = 0;
int b = 0;
int number = 1;
int i =0;
printf("Hello, World! \n");
printf("Enter the number a: ");
scanf("%d", &a);
printf("Enter the number b: ");
scanf("%d", &b);
while (number <=a) {
for (i = 1; i < b; ++i)
{
switch (i){
case 0:
break;
case 1:
if (b % 3 == 0) {
a=add(a);
break;
} else {
a=mult(a);
i=-1;
}
break;
case 2:
goto print;
break;
}
printf("%d ", i);
}
++ number;
}
// Print the results
print:
printf("The result of a is %d.\n", a);
printf("The size of a is %d.\n", sizeof(a));
printf("The result of PI is %d.\n", PI);
printf("The result of PI2 is %d.\n", PI2);
return 0;
}
int add(int a,){
a += number;
return a;
}
int mult(int a,){
a *= number;
return a;
}
Here are some other rules:
\n
newline
\t
tab
\b
backspace
\0
null
null
null
%d
For int number
%f
For float number
%lf
For double number
%c
For char
%s
For string
Sample of matrix:
int matrix[2][4][3] = {
{{3, 4, 3}, {0, 3, 5}, {23, 23, 2},{2, 9, 12}},
{{13, 4, 3}, {5, 3, 5}, {3, 1, 4}, {56, 11, 7}}
};
Sample of point:
int main() {
int* pd, i;
c = 1;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n", c); // 1
pc = &c;
printf("Address of pointer pd: %p\n", pd);
printf("Content of pointer pd: %d\n", *pd); // 1
c = 2;
printf("Address of pointer pd: %p\n", pd);
printf("Content of pointer pd: %d\n", *pd); // 2
*pc = 3;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n", c); // 3
return 0;
}