Advertisement
jovanovski

ЛВ1 СЕМ2

Feb 19th, 2012
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.84 KB | None | 0 0
  1. Задача 1:
  2. -------------
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. typedef struct tocka2D {
  7.     double x;
  8.     double y;
  9. } tocka2D ;
  10.  
  11. typedef struct tocka3D
  12. {
  13.     double x;
  14.     double y;
  15.     double z;
  16. } tocka3D;
  17.  
  18. float rastojanie ( tocka2D t1 , tocka2D t2) {
  19.     return sqrt (( t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y));
  20. }
  21.  
  22. float rastojanie3D ( tocka3D t1 , tocka3D t2) {
  23.  
  24.     return sqrt (( t1.x - t2.x) * (t1.x - t2.x) + (t1.y - t2.y) * (t1.y - t2.y) + (t1.z - t2.z)*(t1.z - t2.z));
  25. }
  26.  
  27. void ista_prava ( tocka2D t1 , tocka2D t2 , tocka2D t3) {
  28.     if( (t2.y-t1.y)/(t2.x-t1.x) == (t3.y-t2.y)/(t3.x-t2.x) )
  29.         printf("Tockite se na ista prava.");
  30.     else
  31.         printf("Tockite ne se na ista prava.");
  32. }
  33.  
  34. int main () {
  35.     tocka2D t1 = { 4.54 , -7.35 };
  36.     tocka2D t2 = { -3.76 , 10.45 };
  37.     printf (" Rastojanieto pomegu tockite t1 i t2 e: %.2f\n", rastojanie (t1 , t2));
  38. return 0;
  39. }
  40.  
  41. Задача 2:
  42. --------------
  43. #include <stdio.h>
  44.  
  45. int ccw(int a, int b, int c, int d, int e, int f){
  46. if (((f-b)*(c-a)) > ((d-b)*(e-a))) return 0;
  47. return 1;
  48. }
  49.  
  50. int main() {
  51. int a,b,c,d,e,f,g,h;
  52. scanf("%d %d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &g, &h);
  53.  
  54. if(ccw(a,b,e,f,g,h)==ccw(c,d,e,f,g,h)) printf("no");
  55. else if(ccw(a,b,c,d,e,f)==ccw(a,b,c,d,g,h)) printf("no");
  56. else printf("yes");
  57. return 0;
  58. }
  59.  
  60. Задача 3:
  61. -------------
  62. #include<stdio.h>
  63. typedef struct proizvod
  64. {
  65. char ime[20];
  66. int cena;
  67. int kolicina;
  68. }proizvod;
  69. int main()
  70. {
  71. int i,n;
  72. proizvod p[20];
  73. printf("Broj na proizvodi\n");
  74. scanf("%d", &n);
  75. for(i=0;i<n;i++)
  76. {
  77. printf("Ime: ");
  78. scanf("%s", &p[i].ime);
  79. printf("Cena: ");
  80. scanf("%d", &p[i].cena);
  81. printf("Kolicina: ");
  82. scanf("%d", &p[i].kolicina);
  83. }
  84. int vkupno=0;
  85. for(i=0;i<n;i++)
  86. {
  87. vkupno+=p[i].kolicina*p[i].cena;
  88. }
  89. printf("Vkupno: %d", vkupno);
  90. return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement