Examen de PS
Examen de PS
Examen de PS
Input :
Hola Mundo
Output :
255
127
-128
4294967295
2147483647
-2147483648
65535
32767
-32768
18446744073709551615
9223372036854775807
-9223372036854775808
main() {
int len;
char line[MAXLINE];
Output :
Hola Mundo
Ejercicio 2-3. Escriba la funcin htoi(s), que convierte
una cadena de dgitos hexadecimales (incluyendo 0x 0X
en forma optativa) en su valor en tero equivalente. Los
dgitos permitidos son del 0 al 9, de la a a la f, y de la A a
la F.
#include <stdio.h>
#define MAXLINE 1000
int get_line(char line[], int maxline);
unsigned long htoi(char s[]);
return l;
}
unsigned long htoi(char s[])
{
unsigned long n;
int i, c;
n = 0;
for (i = 0; s[i] != '\0'; ++i) {
c = s[i];
return 0;
int main(void)
{
int len;
char s1[MAXLINE];
char s2[MAXLINE];
printf("Input string s1:\n");
int main(void)
{
printf("%u\n", setbits(5732, 6, 3, 9823));
return 0;
}
unsigned setbits(unsigned x, int p, int n, unsigned y)
{
// xxxxx00000xxxxx
unsigned a = x & ~(~(~0U << n) << (p + 1 - n));
// 00000yyyyy00000
unsigned b = (y & ~(~0U << n)) << (p + 1 - n);
// xxxxxyyyyyxxxxx
return a | b;
Input :
Hola
Output :
Mundo
if(x & 1)
x = (x >> 1) | ~(~0U >> 1);
else
x = x >> 1;
return x;
Output :
2147484364
Niveles jerrquicos[editar]
Ejercicio 2-9. En un sistema de nmeros de complemen to Los niveles que componen la jerarqua de memoria
a dos, x & = (x 1) borra el bit 1 de ms a la derecha en habitualmente son:
x. Explique el porqu . Utilice esta observacin para
escribir una versin ms rpida de bitcount.
Nivel 0: Registros del microprocesador o CPU
#include <stdio.h>
Nivel 1: Memoria cach
Nivel 2: Memoria primaria (RAM)
int bitcount(unsigned x);
Nivel 3: Memorias flash
Nivel 4: Disco duro (con el mecanismo de memoria virtual)
int main(void)
Nivel 5: Cintas magnticas (consideradas las ms lentas,
{
con mayor capacidad, de acceso secuencial)
printf("%d\n", bitcount(01111));
Nivel 6: Redes (actualmente se considera un nivel ms de
return 0;
la jerarqua de memorias).
}
printf("%.2f\n", x);
int bitcount(unsigned x)
{
hellomake.c
int b;
#include <hellomake.h>
for (b = 0; x != 0; x &= (x - 1)){
b++;
}
return b;
}
Output:
int main() {
// call a function in another file
myPrintHelloMake();
return(0);
hellofunc.c
Ejercicio 2-10. Reescriba la funcin flower, que convierte #include <stdio.h>
le tras maysculas e minsculas, con una expresin
#include <hellomake.h>
condicio n al en vez de un if-e lse .
#include <stdio.h>
void myPrintHelloMake(void) {
int lower(int c);
printf("Hello makefiles!\n");
int main(void)
{
char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
return;
i = 0;
while (s[i] != '\0') {
printf("%c -> %c\n", s[i], lower(s[i]));
i++;
}
return 0;
int lower(int c)
}
hellomake.h
/*
example include file
*/
void myPrintHelloMake(void);
Makefile 1
hellomake: hellomake.c hellofunc.c
gcc -o hellomake hellomake.c hellofunc.c -I.
LISTA.C
#include <stdio.h>
#include <stdlib.h>
int length();
struct node* BuildOneTwoThree();
struct node{
int data;
struct node *next;
};
struct node* BuildOneTwoThree() {
struct node* head = NULL;
struct node* second = NULL;
struct node* third = NULL;
|head = malloc(sizeof(struct node));
second = malloc(sizeof(struct node));
third = malloc(sizeof(struct node));
// allocate 3 nodes in the heap
head->data = 1;
head->next = second; // setup first node
// note: pointer assignment rule
second->data = 2;
second->next = third; // setup second node
third->data = 3;
third->next = NULL; // setup third link
// At this point, the linked list referenced by
"head"
// matches the list in the drawing.
return head;
}
int length(struct node* head) {
struct node* current = head;
int count = 0;
while (current != NULL) {
count++;
current = current->next;
}
return count;
}
main(){
int num = length(BuildOneTwoThree());
printf("%d \n",num);
}
BASH.BH
#!/bin/bash
for i in {100..110}
do
echo $i >> t.txt
gcc z.c
./a.out < t.txt > $i".txt"
rm t.txt
echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
echo "PARA EL CASO M >> N"
gcc Mn.c
time ./a.out < $i".txt"
./a.out < $i".txt"
echo "-----------"
echo "PARA EL CASO N >> M"
gcc Nm.c
time ./a.out < $i".txt"
./a.out < $i".txt"
echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
done
#include<stdio.h>
int sumarrayrows(int m, int n, int a[][n]) {
int i, j, sum = 0;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
sum += a[i][j];
return sum;
}
main() {
int x, y;
scanf("%d %d", &x, &y);
int a [x][y];
int m, n;
for(m = 0; m < x; m++)
for(n = 0; n < y; n++)
scanf("%d", &a[m][n]);
printf("Suma: %d\n", sumarrayrows(x, y, a));
}
#include<stdio.h>
main(){
int x;
scanf("%d", &x);
printf("%d %d\n", x, x);
int cont = 1;
int n, m;
for(n = 0; n < x; n++){
for(m = 0; m < x; m++)
printf("%d ", cont++);
printf("\n");
}
}
8086: (1978, 29 K transistors). One of the first singlechip, 16-bit microprocessors. The 8088, a variant of the 8086 with an 8-bit