Advertisement
Guest User

Exam-2

a guest
May 26th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define N 4
  4.  
  5. typedef struct el {
  6.     int inf; char name[15]; struct el * next;
  7. }unit;
  8.  
  9. int main()
  10. {
  11.     unit lst[N], *lstp[N + 1];
  12.     char p[] = "Kolumbia", x, y;
  13.     x = 8; y = 4; printf("1: %x %x\n", x << 2, y >> 1);
  14.     x = 0x80; y = 1; x <<= 1; y >>= 1; printf("2: %x %x\n", x, y);
  15.     x = 0x9; printf("3:%x %x %x\n", x | 3, x & 3, x ^ 3);
  16.     x = 0x9; printf("4:%x %x %x\n", x | 4, x & 4, x ^ 4);
  17.     x = 1; do{ x <<= 1; printf("5:%x\n", x); } while (!(x & 0x10));
  18.     x = 0x10; while (x){ printf("6:%x \n", x); x >>= 2; }
  19.     for (x = 0; x<N; x++)
  20.     {
  21.         lst[x].inf = x + 2; lst[x].next = lst + (x + 1) % N;
  22.         strcpy(lst[x].name, p); (*(p + x))++;
  23.         printf("7: %s\n", lst[x].name + 1);
  24.         lstp[x] = lst + x;
  25.     }
  26.     lstp[N] = lstp[0]; lstp[0] = lstp[1]; lstp[1] = lstp[N];
  27.     for (x = 0; x<N; x++)
  28.     {
  29.         printf(" 9:%d %s\n", lstp[x]->inf, lstp[x]->name);
  30.         printf("10:%d %s\n", lst[x].next->inf, lst[x].next->name);
  31.     }
  32.     return 0;
  33. }
  34.  
  35. /*
  36. !!!**Answers**!!!
  37. 1: 20 2                                                                                                                                                                        
  38. 2: 0 0                                                                                                                                                                          
  39. 3: b 1 a                                                                                                                                                                        
  40. 4: d 0 d                                                                                                                                                                        
  41. 5: 2                                                                                                                                                                            
  42. 5: 4                                                                                                                                                                            
  43. 5: 8                                                                                                                                                                            
  44. 5: 10                                                                                                                                                                            
  45. 6: 10                                                                                                                                                                            
  46. 6: 4                                                                                                                                                                            
  47. 6: 1                                                                                                                                                                            
  48. 7: olumbia                                                                                                                                                                      
  49. 7: olumbia                                                                                                                                                                      
  50. 7: plumbia                                                                                                                                                                      
  51. 7: pmumbia                                                                                                                                                                      
  52. 9: 3 Lolumbia                                                                                                                                                                  
  53. 10: 3 Lolumbia                                                                                                                                                                  
  54. 9: 2 Kolumbia                                                                                                                                                                  
  55. 10: 4 Lplumbia                                                                                                                                                                
  56. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement