C Programming Tutorial is a much searched discussion on Google, Yahoo and Bing.
Up to now the topic of Learning C ProgrammingC Programming Guide For Beginners, and C Programming PDFs are currently being searched for in 1 hour.
For that we will discuss Learning C Programming which you can read later.
Curious about Learning C Programming? If so, let’s see our article.
C Programming
C Programming Reviews is a hot topic of discussion.
Why did the topic of the C Programming Guide for Beginners go viral? because there is news media.
In addition, there is also a group that participates in the discussion.
So the review of the C Programming Guide For Beginners is getting more and more viral and we are interested in making a review.
The following are the results of our research regarding the C Programming Tutorial
C Programming Tutorials
C language is a programming language created by Kernigan and Ritchie in 1972. Time has proven that C is a classic language that is so elegant and universal, that:
- used in any class of hardware from microprocessors to supercomputers.
- available on any operating system, from UNIX, DOS, Windows to Linux.
- for any application, from creating games, databases, operating-systems, to real-time.
- inspired other languages, starting from C++, C#, Java, PHP.
- always popular, only ever beaten by Java [1].
Learn C now, if you can, learning another language will be easy. To start learning, first prepare:
- C compiler, if it’s on Linux, it’s usually there
- Integrated_Development_Environment_(IDE) C/C++.
Program Structure
The C language is very simple and consistent (this is one of its strengths). If someone says it’s difficult, it’s more because the syntax is a lot of cryptic, difficult to understand. But once I understand, I will be happy to write it because it is short, dense and powerful.
To start writing C programs, you have to create a text file called “what_saja.c”. In the file, the minimum contents are:
int main() {
return 0;
}
It’s simple.
If you want more details then
/* Nama File: pertama.c */
// include pustaka dasar
#include <stdio.h>
// Fungsi utama
int main() {
// panggil fungsi print
printf("Hello worldn");
return 0;
}
Data
There is a classic formula that says “program = data structure + algorithm”. It can’t be helped, the software’s job is to process data. Therefore, the first step in every language is to define data.
Data Type
In the real world, there are various types of data, such as names, ages, telephone numbers, addresses. Therefore the C language provides various types (types) of data, namely:
| Type | Information | Usage Example |
|---|---|---|
| bool | logic true or false | alarm condition, light condition |
| int | round number | telephone number, number of students |
| float | fractional number | weight, height |
| char | letter | one-letter choice, one-type input |
| char[] | array of char | sentence |
What’s a bit weird compared to other languages is, C doesn’t know the string data type! But don’t worry, it can be arranged.
Variable
A variable is a chunk of memory to store data. Imagine a variable like a “pot” to hold data, which can be filled with any data value (as long as it’s not full). To use a variable, you must:
- Order it in memory
- Determine the type
- Give him a name
After that, you can fill it (write) and then re-read the contents.
constant
Constants are data whose values do not change while the program is running. Useful for creating names for hard-to-remember numbers. There are three ways to create constants, as in the following example:
/* Program Data */
// konstanta, cara 1
// pakai pragma #define
#define MAX 10
// konstanta, cara 2
# pakai kata kunci const, diikuti dengan pendefinisian tipe, nama dan nilai
const int MIN=0;
// enumeration
// khusus untuk bilangan integer, bisa mendefinisikan banyak konstanta sekaligus
enum {SATU=1, DUA, TIGA};
int main() {
// pesan variabel
int a, b, c;
a = MIN;
b = MAX;
c = TIGA;
printf("A = %dn", a);
printf("B = %dn", b);
printf("C = %dn", c);
printf("Ukuran integer = %dn", sizeof(a));
return 0;
}
Output
The second step, output, is useful for displaying data to humans. This is important, because what’s the use of data in computer memory if it can’t be seen by people. For this output, the technique is highly dependent on the user interface, whether TUI or GUI. This time we use TUI first.
/*
* File: main.c
* Author: kocil
*
* Created on June 19, 2010, 10:02 AM
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int angka = 123;
float pecahan = 456.789;
char huruf="a";
char kata[] = "abc";
printf("Angka : %dn", angka);
printf("Pecahan : %fn", pecahan);
printf("Huruf : %cn", huruf);
printf("Kata : %sn", kata);
// pakai posisi dan lebar
printf("Angka : %5dn", angka);
printf("Pecahan : %5.2fn", pecahan);
printf("Huruf : %10cn", huruf);
printf("Kata : %-10sn", kata);
}
Input
The opposite of Output, Input is a move to receive input from the user, and enter it into a variable.
/*
* File: main.c
* Author: kocil
*
* Created on June 19, 2010, 10:15 AM
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int angka = 123;
float pecahan = 456.789;
char huruf="a";
char kata[] = "abc";
printf("Silahkan Masukkan datan");
printf("Sebuah angka: ");
scanf("%d", &angka);
printf("Sebuah pecahan desimal: ");
scanf("%f", &pecahan);
printf("Sebuah huruf: ");
huruf = getchar();
printf("Sebuah kata: ");
gets(kata);
printf("Ini masukan dari andan");
printf("Angka : %dn", angka);
printf("Pecahan : %fn", pecahan);
printf("Huruf : %cn", huruf);
printf("Kata : %sn", kata);
return (EXIT_SUCCESS);
}
Operator
Finally, about the data, of course the data must be processed. The simplest data processors are called operators (more complicated ones will use functions). There are many operators, depending on the type of data. Similarly, for different data types, the same operator can have different meanings.
For example, let’s create the following gunnery program:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <tgmath.h>
/* Penembak meriam
*
*/
int main() {
const float g = 9.8;
float v, alpha;
float rad, vx, vy, t;
float xm,ym;
// baca input
printf("Penembak meriamn");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
// hitung memakai operator
rad = alpha / 180 * M_PI;
vx = v * cos(rad);
vy = v * sin(rad);
// mencapai maks ketika ... vy - 2 g t = 0
t = vy / (2 * g);
// maksimum adalah
ym = vy * t;
xm = vx * 2 * t;
// tulis output
printf("Tinggi maksimum: %6.2fn", ym);
printf("Jarak maksimum: %6.2fn", xm);
return (EXIT_SUCCESS);
}
branch
If you pay attention to the previous examples, computers always run commands sequentially, starting from the first written to the last.
Like a road, this means a straight path without any deviation. Now, branching is a feature where the program can veer to one path, and there is no need to do another path. Before turning, the computer will calculate a condition to select the path. Seems simple, many say that branching is the key to computer intelligence. If you don’t believe me, please program a complicated case. There will definitely be a lot of branching
In C, there are two basic branching constructs:
- If – else
- switch – case
Just an example, okay?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*
* Menembak sasaran
*/
int main() {
const float g = 9.8;
const float akurasi = 2;
const float xtarget = 100;
float v, alpha;
float rad, vx, vy, t;
float xm;
// baca input
printf("Menembak sejauh 100 m n");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
// hitung memakai operator
rad = alpha / 180 * M_PI;
vx = v * cos(rad);
vy = v * sin(rad);
// mencapai maks ketika ... vy - 2 g t = 0
t = vy / (2 * g);
// jarak tembak maksimum adalah
xm = vx * 2 * t;
printf("Jarak tembakan: %6.2fn", xm);
// periksa apakah memang mengenai sasaran
if ((xm > (xtarget - akurasi)) && (xm < (xtarget + akurasi))) {
printf("KENA !!!n");
}
else {
printf("LUPUT !!!n");
}
return (EXIT_SUCCESS);
}
Repetition
If branching is the key to computer intelligence, repetition is the key to computer craft. This feature makes the computer willing to process millions of data without complaining, and is always consistent (right or wrong).
In C, there are three basic repetition constructs:
Let’s see how it works:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
/* Menembak sasaran, tiga kali kesempatan
*
*/
int main() {
const float g = 9.8;
const float akurasi = 2;
float xtarget;
float v, alpha;
float rad, vx, vy, t;
float xm;
int ulang;
// random, posisi sasaran
xtarget = (time(NULL) % 100) + 10;
printf("Menembak sasaran pada posisi %6.2f mn", xtarget);
printf("Anda punya 3 pelurun");
// tiga kali kesempatan
for (ulang=1; ulang <= 3; ulang++) {
// baca input
printf("Tembakan %dn", ulang);
printf("Kecepatan awal:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
// hitung memakai operator
rad = alpha / 180 * M_PI;
vx = v * cos(rad);
vy = v * sin(rad);
// mencapai maks ketika ... vy - g t = 0
t = vy / (g);
// jarak tembak maksimum adalah
xm = vx * 2 * t;
printf("Jarak tembakan: %6.2fn", xm);
// periksa apakah memang mengenai sasaran
if ((xm > (xtarget - akurasi)) && (xm < (xtarget + akurasi))) {
printf("KENA !!!n");
break;
}
else {
printf("LUPUT !!!nn");
}
}
return (EXIT_SUCCESS);
}
Here’s more action:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* Pengulangan menghitung trayektori peluru
*
*/
int main() {
const float g = 9.8;
float v, alpha;
float rad, vx, vy, t, dt;
float x, y;
// baca input
printf("Trayektori Tembakann");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
// hitung memakai operator
rad = alpha / 180 * M_PI;
vx = v * cos(rad);
vy = v * sin(rad);
dt = ceil(vy / (g)) / 10;
x = y = 0;
t = 0;
printf("Waktu X Yn");
printf("%6.3f %6.2f %6.2fn", t, x, y);
do {
t = t + dt;
x = vx * t;
y = (vy * t) - (g * t * t / 2);
printf("%6.3f %6.2f %6.2fn", t, x, y);
} while (y > 0.0);
return (EXIT_SUCCESS);
}
Subroutine
The seventh move, is a move that allows us to write programs in a modular manner. In essence, the parts of the program that we consider ‘one unit’ we collect into one function. The function can take input (called parameters) and provide output (called return values). Thus our program:
- Easier to read
- Shorter written
Here’s an example:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// konstanta gravitasi global
const float g = 9.8;
/* fungsi menghitung jarak X
*/
float jarakX(float v, float a, float t) {
float vx;
vx = v * cos(a / 180 * M_PI);
return vx * t;
}
/* fungsi menghitung jarak Y
*/
float jarakY(float v, float a, float t) {
float vy;
vy = v * sin(a / 180 * M_PI);
return (vy * t) + (g / 2 * t * t );
}
/* menghitung trayektori peluru
*
*/
int main() {
float v, alpha;
float t, dt;
float x, y;
// baca input
printf("Trayektori Tembakann");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
t = 0;
dt = 0.1;
printf("Waktu X Yn");
do {
x = jarakX(v, alpha, t);
y = jarakY(v, alpha, t);
printf("%6.3f %6.2f %6.2fn", t, x, y);
t = t + dt;
} while (y > 0.0);
return (EXIT_SUCCESS);
}
More advanced use of subroutines, we can distinguish variables as global or local variables. This can make the program easier to follow, or faster.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// konstanta gravitasi global
const float g = 9.8;
// variabel global
float vx, vy;
/* mulai tembak
*/
void mulaiTembak(float v, float a) {
vx = v * cos(a / 180 * M_PI);
vy = v * sin(a / 180 * M_PI);
}
/* fungsi menghitung jarak X
*/
float jarakX(float t) {
return vx * t;
}
/* fungsi menghitung jarak Y
*/
float jarakY(float t) {
return (vy * t) - (g / 2 * t * t );
}
/* menghitung trayektori peluru
*
*/
int main() {
float v, alpha;
float t, dt;
float x, y;
// baca input
printf("Trayektori Tembakann");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
t = 0;
dt = 0.1;
mulaiTembak(v, alpha);
printf("Waktu X Yn");
do {
x = jarakX
y = jarakY
printf("%6.3f %6.2f %6.2fn", t, x, y);
t = t + dt;
} while (y >= 0.0);
return (EXIT_SUCCESS);
}
Structure
Now we enter the advanced stance. A structure (or record) is a feature for creating a data structure, in which some data is put together. This will be very helpful in understanding the problem, as well as programming.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// konstanta gravitasi global
const float g = 9.8;
typedef struct {
float x, y;
} data_xy;
// variabel global
data_xy velocity;
/* mulai tembak
*/
void mulaiTembak(float v, float a) {
velocity.x = v * cos(a / 180 * M_PI);
velocity.y = v * sin(a / 180 * M_PI);
}
/* fungsi menghitung jarak
*/
data_xy jarak(float t) {
data_xy s;
s.x = velocity.x * t;
s.y = (velocity.y * t) - (g / 2 * t * t );
return s;
}
/* menghitung trayektori peluru
* pakai struktur data
*/
int main() {
float v, alpha;
float t, dt;
data_xy j;
// baca input
printf("Trayektori Tembakann");
printf("Kecepatan awal peluru:");
scanf("%f", &v);
printf("Sudut tembak:");
scanf("%f", &alpha);
t = 0;
dt = 0.1;
mulaiTembak(v, alpha);
printf("Waktu X Yn");
do {
j = jarak
printf("%6.3f %6.2f %6.2fn", t, j.x, j.y);
t = t + dt;
} while (j.y >= 0.0);
return (EXIT_SUCCESS);
}
Programming
That’s all the C Programming Tutorial articles that you’ve read to the end, on the KepoWin site.
I hope Study review C ProgrammingC Programming Guide For Beginners, and C Programming PDF can be useful and thank you for visiting
if you have time please share on social media Whatsapp, Twitter, Instagram, Telegram, TikTok, Facebook and others.
c programming language tutorials for beginners, c programming language tutorials, c++ programming tutorials, c++ programming tutorials, c++ programming language tutorials pdf, c++ programming language learning tutorials, how to make c++ programs in visual studio, how to make c++ programs on android, learn languages c programming for beginners, c++ program tutorials, how to make c++ programs calculate the area of a rectangle