Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

C

Biblioteca
#include<stdio.h>
#include <math.h> pt functii matematice

Scriere
printf(" ")

initializare
scanf("%d", &myNum);

Pt a insera o noua linie


printf("Hello world\nI am learing C.\It's amazing")

Hello world!
I am learning C.
It's amazing

\t pune spatiu mare pe rand


\\ insereaza o bara
\" insereaza ghilimele
// insereaza un comentariu
/* insereaza un comentraiu pe mai multe linii*/
& adresa
* pointer

Tipuri de variabile
int "%d\n" sau "%i\n" printf("%d\n", sum);
float "%f\n"
char "%c\n"
string (text) "%S\n"
long unsigned int "%lu\n"

const cand nu vreau overwrite


ex: const int nr=15;

#include<stdio.h>
int main()
{prinf("Hello world");

structuri

if(conditie){ }
else {}

sau short if-else

int time=15;
(time<18){}
else{}

switch()
exemplu
int day=3
switch(day){
case 1:
printf("luni");
break;
case 2:
printf("marti");
break;
case 3:
printf("miercuri"):
break;
defalut:
printf("nu e niciuna");
}

//Scrie mircuri

while

while(conditie)
{}

do while
do{
}while(conditie);

for

exemplu
for(i=1;i<=5;i++)
{}

break&continue;
continue
exemplu
for (i = 0; i < 10; i++) {
if (i == 4) {
continue;
}

scrie
0
1
2
3
5
6
7
8
9

VECTORI
printf("%d", myNumbers[0]);

int myNumbers[] = {25, 50, 75, 100};

MATRICE
int matrix[2][3] = { {1, 4, 2}, {3, 6, 8} };
printf("%d", matrix[0][2]);

STRING
char greetings[] = "Hello World!";
sau char greetings[] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!',
'\0'};
printf("%s", greetings);
printf("%c", greetings[0]); //afiseaza doar prima litera

Escape character Result Description


\' ' Single quote
\" " Double quote
\\ \ Backslash

Functii matematice
abs(x) Returns the absolute value of x
acos(x) Returns the arccosine of x
asin(x) Returns the arcsine of x
atan(x) Returns the arctangent of x
cbrt(x) Returns the cube root of x
cos(x) Returns the cosine of x
exp(x) Returns the value of Ex
sin(x) Returns the sine of x (x is in radians)
tan(x) Returns the tangent of an angle
ceil() rotunjeste la mai mare
fl0or() rotunjeste la mai mic
pow()

You might also like