Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <math.h>
- #include <string.h>
- void datitos (char nombre[], int edad) // funcion
- {
- printf("tu nombre es: %s\n", nombre);
- printf("tu edad es: %d", edad);
- }
- int datitos2 (int number) {
- int rpta = 2 * number;
- return rpta;
- }
- void datitos3 (char nombre[], int numero); // function prototype.
- // the function prototype cause the compiler to flag an error if arguments are misssing.
- struct node
- {
- int a;
- int b;
- };
- int main (){
- /*
- printf("hola mundo \n"); // \x, these are called escape sequences.
- printf("como estas \n");
- printf("1\t2\t3\n4\t5\t6\n7\t8\t9\n"); // \n = salto de lina y \t = tab
- printf("\"yo quiero pizza\" - javier"); // \" = poner comillas en un string
- */
- /* declaration of variable
- int x = 12;
- x = 123;
- float gol = 2.05;
- char gra = 'c';
- char nombre[] = "hola que hace"; // array of characters, it emulate a String like in other programming languages.
- printf("you are %d years old \n",x); // C format Specifier = define data type
- printf("%s \n",nombre);
- // end of var. declaration
- */
- /*
- // data type
- char a = 'c'; // single character, %c
- char b[] = "javier"; //array of character, %s
- float c = 3.141592; //4 bytes, 6-7 digits, %f
- double d = 3.1415926535897993; // 8 bytes, 15-16 digits, %lf
- bool e = true; // 1 byte, "true" = 1 and "false" = 0, %d
- char f = 100; // its possible to store a num in "char", 1 byte (-128, 127), %d or %c
- printf("%d\n",f); // char as decimal, print the number.
- printf("%c\n",f); // chas is displayed as character according to ASCII table codes. ascii has a range from 0 to 127
- unsigned char g = 250; // 1 byte, 0 to 255, %d or %c, just to storage num in 1 byte.
- printf("%d\n",g);
- short int h = 32767; // 2 bytes, from -32,768 to +32,767, %d, short h = 32767 (otra forma)
- unsigned short int i = 65535; // 2 bytes, from 0 to 65,535, %d, unsigned short i = 65535
- int j = 234; // 4 bytes, -2,147,483,648 to 2,147,483,647; %d
- unsigned int k = 222; // 4 bytes, 0 to 4,294,967,295; %u
- long long int l = 123423421341;//8 bytes, -9 quintillion to 9 quintillion, %lld
- unsigned long long int m = 23423423424234;//8 bytes, 0 to 18 quintillion, %llu
- //end of data type.
- */
- /*
- //decimal presition
- // %.x; x = enteros, decimal precision
- // %x; x>=0, field width
- // %-; left align
- float numerito = 2.23;// without any decimal display change.
- printf("%f\n",numerito);
- printf("%.2f\n", numerito);
- printf("%8.2f\n", numerito);
- const float PI = 3.141592;
- */
- /*
- // input with scanf
- char name[25]; // when a char var doesn't have anything, must put # of bytes that will be in the array, 25 is the max. if we go above, we will produce a buffer overflow.
- int age;
- printf("what is your name: ");
- scanf("%s", &name);
- printf("write your age: ");
- scanf("%d", &age);
- printf("hello %s, how are you \n", name);
- printf("your age is %d", age);
- */
- /*
- // math functions examples
- double a1 = sqrt(9);
- printf("\n%.2lf\n", a1);
- double a2 = pow(2,4); // = 2^4
- printf("%.2lf\n", a2);
- int a3 = round(3.55); // round the number
- printf("%d\n", a3);
- int a4 = ceil(3.453); // always round the number up
- printf("%d\n", a4);
- int a5 = floor(3.89); // always round the number down
- printf("%d\n", a5);
- double a6 = fabs(-100); // give the absolute value. it work with INT var
- printf("%.2lf\n", a6);
- double a7 = log(3);
- printf("%lf\n", a7);
- double a8 = sin(45); // sin, cos , tan
- */
- /*
- // if-statement
- int age;
- printf("write a number: ");
- scanf("%d", &age);
- if (age == 8){
- printf("your are awesome");
- } else if (age <= 3){
- printf("you are not awesome");
- } else {
- printf("adios");
- }
- */
- /*
- // switch case
- char grade;
- printf("enter a letter: ");
- scanf("%c", &grade);
- switch(grade){
- case 'a':
- printf("you are top student");
- break;
- case 'b':
- printf("you are a good student");
- break;
- case 'c':
- printf("you are an average student");
- break;
- case 'd':
- printf("you need to put more effort");
- break;
- default:
- printf("we need to talk to your parents");
- }
- */
- /*
- // funcion of "datitos"
- char name[] = "javier";
- int age = 21;
- datitos(name, age);
- */
- /*
- // return statement in C
- int dato_numerico;
- printf("escribir un numero: ");
- scanf("%d", &dato_numerico);
- int x = datitos2(dato_numerico);
- printf("el numero es: %d", x);
- */
- /*
- //ternary operator - (condition) ? "value if true" : "value if false"
- // a shortcut to if/else when assigning/returning a value.
- int roman_numb = 15;
- int arab_numb = 9;
- int hold_numb;
- hold_numb = (roman_numb >= arab_numb) ? roman_numb : arab_numb;
- printf("%d\n", hold_numb);
- //another example96
- int edad_a = 23;
- int edad_b = 23;
- (edad_a == edad_b) ? printf("son iguales\n") : printf("son diferentes\n");
- */
- /*
- // prototype course
- char primer_nombre[] = "julian";
- int edad_alumno = 18;
- datitos3(primer_nombre, edad_alumno);
- */
- /*
- // for loop
- for(int i = 1; i <= 10; i++){ // e.g. i+=2 -> now counts by 2
- printf("%d\n", i);
- }
- */
- /*
- // do-while
- int numbercito = 0;
- int sumita = 0;
- do{
- printf("enter a number greater than 0: ");
- scanf("%d", &numbercito);
- if (numbercito > 0){
- sumita += numbercito;
- }
- }while (numbercito <= 10);
- printf("%d", sumita);
- */
- /*
- // nested loop
- for (int i = 0; i <= 10; i++){
- for(int j = i; j >= 0; j--){
- printf("%d ", j);
- }
- printf("\n");
- }
- */
- /*
- // pointers
- int civ = 22;
- int *pCiv = &civ;
- printf("valor de la variable es: %d\n", civ);
- printf("valor de la direccion es: %p\n", &civ); // shows civ's address
- printf("valor del puntero es: %p\n", pCiv); // show value of var. "pCiv", == civ's address
- printf("\n");
- printf("the value of civ is %d\n", civ);
- printf("the values of the stored address is %d\n", *pCiv);// print the value at the address stored in the var. *pCiv, == civ's address
- */
- //struct node peru;
- //printf("valor de dir. es: %p\n", &peru.a);
- //printf("valor de dir. es: %p", &(peru.b));
- int array1[6] = {1,2,3,4,5,6};
- for (int i=0; i==6; i++){
- }
- }
- // prototype of a functions.
- void datitos3 (char nombre[], int numero){
- printf("\nel nombre es %s y el numero es %d", nombre, numero);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement