Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


resumen programacion en C, Resúmenes de Ingeniería electrónica

Asignatura: Programación, Profesor: , Carrera: Ingeniería Electrónica Industrial y Automática, Universidad: UC3M

Tipo: Resúmenes

2014/2015

Subido el 21/06/2015

stella_escribano_ruiz
stella_escribano_ruiz 🇪🇸

4

(15)

12 documentos

1 / 14

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Computer:
Machine composed of electronic elements, able to accept data from an input device, to
process them automatically with a previously stored program, and to provide the resulting
information through an output device
Information?
Data?
• When data is processed, organized in a given context so as to make it useful.
• •
Data is raw facts that need to be processed. Computers process digital data (0 or 1)
• Computers classification:
– By size (computing capacity)
Computing capacity is the amount of processing that can be achieved by a computer
system per unit of time.
o Supercomputers:
o Mainframes:
o Workstations:
o Personal computers: o Mobile computers
Memory size is usually specified in bytes
A byte = 8 bits – so can represent a range of 28 = 256 values
A kilobyte (KB) = 1024 Bytes or characters
A megabyte (MB) = 1024 KB
A gigabyte (GB) = 1024 MB
• A terabyte (TB) = 1024 GB
Secondary memory is slower but cheaper
o use different technologies (magnetic signals on hard disk, reflective spots on CD)
o memory is permanent – useful for storing long-term data.
Input devices allow the computer to receive data and instructions from external sources.
• Output devices allow the computer to display or broadcast its results
A program is a set of instructions or sentences written in a specific language in order to
perform a defined task.
• A program is used to solve a problem with a computer
Machine Language (or Binary program or Object Code)
2 1
9 1
Very fast because talking to the computer with its own
idiom.
2 1
9 3
Very difficult because we must understand how the exact combination of 1s and 0s will
affect the program.
2 1
9 3
It cannot be used in different processor CPU, because the instructions use specific
hardware components
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Vista previa parcial del texto

¡Descarga resumen programacion en C y más Resúmenes en PDF de Ingeniería electrónica solo en Docsity!

Computer:

Machine composed of electronic elements, able to accept data from an input device, to process them automatically with a previously stored program, and to provide the resulting information through an output device Information?

Data?

  • When data is processed, organized in a given context so as to make it useful.
  • • Data is raw facts that need to be processed. Computers process digital data (0 or 1)

• Computers classification:

  • By size (computing capacity) Computing capacity is the amount of processing that can be achieved by a computer system per unit of time. o Supercomputers: o Mainframes: o Workstations: o Personal computers: o Mobile computers

Memory size is usually specified in bytes

  • A byte = 8 bits – so can represent a range of 28 = 256 values
  • A kilobyte (KB) = 1024 Bytes or characters
  • A megabyte (MB) = 1024 KB
  • A gigabyte (GB) = 1024 MB
    • A terabyte (TB) = 1024 GB

Secondary memory is slower but cheaper

o use different technologies (magnetic signals on hard disk, reflective spots on CD) o memory is permanent – useful for storing long-term data. Input devices allow the computer to receive data and instructions from external sources.

  • Output devices allow the computer to display or broadcast its results A program is a set of instructions or sentences written in a specific language in order to perform a defined task.
  • A program is used to solve a problem with a computer

Machine Language (or Binary program or Object Code)

2 19 1 Very fast because talking to the computer with its own

idiom. 2 19 3 Very difficult because we must understand how the exact combination of 1s and 0s will

affect the program. 2 19 3 It cannot be used in different processor CPU, because the instructions use specific

hardware components

Assembly language

  • It enables a programmer to use human readable commands (labels) instead of numbers.
  • Require the use of an assembler program to translate the textual language into machine code 2 19 1 It changes binary numbers by textual labels 2 19 3 Processor-dependent 2 19 3 Still complicated to solve complex problems because, it offers low-level instructions

High-level languages

  • It uses natural language elements, be easier to use, making the process of developing a program simpler and more understandable. There are more than 300 high-level programming languages (with more than 2400 with dialects): Fortran, Pascal, Cobol, Basic, C, C++, Java, Ada, Python, etc. 2 19 1 They are intended to bring programming languages closer to human language 2 19 1 Programs expressed in high-level languages do not depend on the internal architecture

of a specific CPU, the same program can be run on different CPU. 2 19 1 The same source program can be executed in different operating systems (but specific

compilers are required for each system) 2 19 3 a program must be translated into binary language, this translation is more complex than

the assembly process.

Compiler

It transforms the program in a high-level language (source code) to programs in a low-level language (object code) The compiler detects syntax errors; if any, it warns the programmer and the object code is not generated The generated program can be run on any other compatible computer (with the same operating system), even if the compiler is not installed

Putting everything together...

  • Solving a problem means to obtain output data from input data.
    • Computers process data by means of programs.
    • A program includes several instructions that implement an

algorithm created to solve the problem.

  • The program is stored in the computer memory and executed instruction by instruction.
  • As a result, the program provides the solution to the problem in the form of output data. Develop an algorithm that, given two numbers, find out the largest of them Programa Largest ENV START END VAL1: First value, real VAL2: Second value, real Read VAL Read VAL If ( VAL1>VAL2) Then Else End If

Example

  • Implement the basic functioning of an ATM machine
  • Basic: It requires the use of a password and has only one operation:
  • Withdraw money
  • Advanced: Three operations: – Withdraw money
  • Consult credit – View password

Read an integer value (larger than 0) and print all the positive integers lesser than this value. The operation is repeated until the user enters the value 0.

Read an integer value representing a day of the week and print the corresponding name. Ask the user to repeat the procedure.

Declaration and initialization of structures: Values are directly assigned struct Point3D point1 = {2.1, 3.4, 9.8};

  • Structure assignment: A copy of the structure is created struct Point3D point2; point2 = point1;
  • Individual member assignment: A copy of the member is assigned struct Point3D point = {1.1, 2.3, -1.4}; struct Point3D point4; point4.x = point3.x; point4.y = point3.y; point4.z = point3.z;

5. Structures: definition and use

Initialization, assignment and copy of structures An array of structures stores a list of entities Different from an array inside a structure! Syntax struct <structure_name> <array_name>[];

The entities of the array are grouped together and can be accessed with indexes as any other array element

The members of a structure can be basic or complex data types: integer, character, pointer... array, structure Example Entry of an address book (arrays inside a structure) struct AddressBookEntry { char name[256]; }; char surname[256]; char email[256]; int phone[4]; Example (structures inside a structure, array of structures inside a structure) struct Point2D { float x; float y; }; struct Triangle { struct Point2D a; struct Point2D b; struct Point2D c; }; struct Pentagon { struct Point2D points[5]; };

A function definition is the code to perform the intended task

Syntax Header () { }

  1. Function declaration and definition return

/* Example: Passing parameters by value */ Before calling demo function: n --> 10 Inside demo function: value --> 10 Inside demo function: value --> 999 After calling demo function: n --> 10 #include <stdio.h> void demoFunction1(int value); int main(void) { int n=10; } printf("Before calling demo function: n --> %i\n", n); demoFunction1(n); printf("After calling demo function: n --> %i\n",n); return 0; void demoFunction1(int value) { printf("Inside demo function: value --> %i\n", value); value= 999; printf("Inside demo function: value --> %i\n", value); }

BefoBefore calling demo function: n --> 10 Inside demo function: value --> 10 Inside demo function: value --> 999 After calling demo function: n --> 10 re calling demo function: n --> 10 Inside demo function: value --> 10 Inside demo function: value --> 999 After calling demo function: n --> 10 Write a C program that creates two 1-dimension arrays of integer values, copies the values of these arrays in a third array, and print the values of all of them on the screen by using functions #include <stdio.h> #define SIZE_1 5 #define SIZE_2 3 printf("Enter array 1 values: \n"); readArray(v1, SIZE_1); printf("Enter array 2 values: \n"); readArray(v2, SIZE_2); copyArrays(v1, v2, v3, SIZE_1, SIZE_2); printf("Array values: \n"); printArray(v1, SIZE_1); printArray(v2, SIZE_2); printArray(v3, SIZE_1 + SIZE_2); return 0; }

void readArray(int a[], int n) { int i; for (i=0; i<n; i++) scanf("%i", &a[i]); } void printArray(const int a[], int n) { int i; printf("[ "); for (i=0; i<n; i++)

printf ("%i ", a[i]); printf("] \n");

  1. Parameters – Arrays and structures } void copyArrays(const int a[], const int b[], int c[], int n1, int n2) { } } 11 int i; for (i=0; i< n1+n2; i++) { if (i<n1) else c[i]=a[i]; c[i]=b[i-n1];