Metrick

Untitled

Sep 7th, 2011
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.12 KB | None | 0 0
  1. //===== BE10
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6.  
  7. void main()
  8. {
  9.   clrscr();
  10.   randomize();
  11.   int x,n,a,p,c=0;
  12.   printf("Vvedite X,N,A\n");
  13.   scanf("%i%i%i",&x,&n,&a);
  14.   printf("\n");
  15.   for (int i=0;i<=n;i++)
  16.   {
  17.     p=-a+random(a*2)+1;
  18.     printf("%i ",p);
  19.     if (x<p)
  20.       c++;
  21.   }
  22.   printf("\nKolichestvo bolshih %i chisel: %i",x,c);
  23.   getch();
  24. }
  25. //--------------------------------------------------------------------------------------------
  26. //===== BE11
  27.  
  28. #include <stdio.h>
  29. #include <conio.h>
  30. #include <stdlib.h>
  31.  
  32. void main()
  33. {
  34.   clrscr();
  35.   randomize();
  36.   int a[10], y=0, i;
  37.   for (i=0;i<10;i++)
  38.   {
  39.     a[i]=-5+random(11);
  40.     printf("%i ",a[i]);
  41.     if (a[i]<0)
  42.       y++;
  43.   }
  44.   printf("\nkolichestvo otricatelnih chisel: %i",y);
  45.   getch();
  46. }
  47. //--------------------------------------------------------------------------------------------
  48. //===== BE13
  49.  
  50. #include <stdio.h>
  51. #include <conio.h>
  52. #include <stdlib.h>
  53. #define max 25
  54.  
  55. void main()
  56. {
  57.  
  58.   int a[max][max], n, i, j;
  59.   clrscr();
  60.   randomize();
  61.   printf("Vvedite razmer massiva n\n");
  62.   scanf("%i",&n);
  63.   for (i=0; i<n; i++)
  64.   {
  65.     for (j=0; j<n; j++)
  66.     {
  67.       a[i][j]=3+random(23);
  68.       printf("%3i",a[i][j]);
  69.     }
  70.     printf("\n");
  71.   }
  72.   printf("\nrezultat:\n");
  73.   for (i=0; i<n; i++)
  74.     for (j=i+1; j<n; j++)
  75.       a[i][j]=0;
  76.  
  77.   for (i=0; i<n; i++)
  78.   {
  79.     for (j=0; j<n; j++)
  80.       printf("%3i",a[i][j]);
  81.     printf("\n");
  82.   }
  83.   getch();
  84. }
  85. //--------------------------------------------------------------------------------------------
  86. //===== BE17
  87.  
  88. #include <stdio.h>
  89. #include <conio.h>
  90.  
  91. void rect(int a,int b)
  92. {
  93.   printf("ploshchad pryamougola ravna %i",a*b);
  94. }
  95.  
  96. void main()
  97. {
  98.  
  99.   clrscr();
  100.   int a,b;
  101.   printf("Vvedite dlini pryamougolnika a b\n");
  102.   scanf("%i%i",&a,&b);
  103.   rect(a,b);
  104.   getch();
  105. }
  106. //--------------------------------------------------------------------------------------------
  107. //===== BE18
  108.  
  109. #include <stdio.h>
  110. #include <conio.h>
  111.  
  112. int coll(float a, float b, char type)
  113. {
  114.   if (type!='l')
  115.     return (a+b);
  116.   else
  117.     return (a*b)/(a+b);
  118. }
  119.  
  120. void main()
  121. {
  122.   clrscr();
  123.   float a,b;
  124.   char c;
  125.   printf("Введите значения сопротивлений a и b\n");
  126.   scanf("%f%f",&a,&b);
  127.   printf("\nУкажите тип соединения (l-послед,p-параллел)\n");
  128.   do
  129.   {
  130.     c=getch();
  131.     if ((c=='l')||(c=='p'))
  132.       break;
  133.   } while (1);
  134.   printf("Rezultat: %i", coll(a,b,c));
  135.   getch();
  136. }
  137. //--------------------------------------------------------------------------------------------
  138. //===== BE19
  139.  
  140. #include <stdio.h>
  141. #include <conio.h>
  142. #include <stdlib.h>
  143.  
  144. int i,c,u;
  145.  
  146. void fun(int n, int a,int b)
  147. {
  148.   printf("\n");
  149.   for (i=0; i<n; i++)
  150.   {
  151.     c=a+random(a+b-1);
  152.     printf("%i ",c);
  153.     u=u+c;
  154.   }
  155.   printf("Srednee arifmeticheskoe: %i",u/2);
  156. }
  157.  
  158. void main()
  159. {
  160.   clrscr();
  161.   int a,b,n;
  162.   printf("Vvedjte n,a,b\n");
  163.   scanf("%i%i%i",&n,&a,&b);
  164.   fun(n,a,b);
  165.   getch();
  166. }
  167. //--------------------------------------------------------------------------------------------
  168. //===== CH11
  169.  
  170. #include <stdio.h>
  171. #include <conio.h>
  172. #include <stdlib.h>
  173.  
  174. void main()
  175. {
  176.   clrscr();
  177.   randomize();
  178.   int n, a[10], b[11];
  179.   printf("Vvedite N\n");
  180.   scanf("%i",&n);
  181.   printf("\n");
  182.   for (int i=0; i<10; i++)
  183.   {
  184.     a[i]=2+random(6);
  185.     printf("%i ",a[i]);
  186.   }
  187.   printf("\n");
  188.   for (i=0; i<n; i++)
  189.   {
  190.     b[i]=a[i];
  191.     printf("%i ",b[i]);
  192.   }
  193.   b[n]=0;
  194.   printf("%i ",b[n]);
  195.   for (i=n+1; i<11; i++)
  196.   {
  197.     b[i]=a[i-1];
  198.     printf("%i ",b[i]);
  199.   }
  200.   getch();
  201. }
  202. //--------------------------------------------------------------------------------------------
  203. //===== CH12
  204.  
  205. #include <conio.h>
  206. #include <stdio.h>
  207. #include <stdlib.h>
  208.  
  209. void main()
  210. {
  211.   clrscr();
  212.   randomize();
  213.   int A[10], i, j, exc;
  214.   for (i=0; i<10; i++)
  215.   {
  216.     A[i]=-5+random(11);
  217.     printf("%i ",A[i]);
  218.   }
  219.   printf("\n");
  220.   for (i=10; i>0; i--)
  221.     for (j=9; j>0; j--)
  222.       if (A[j]<A[j+1])
  223.       {
  224.     exc=A[j];
  225.     A[j]=A[j+1];
  226.     A[j+1]=exc;
  227.       }
  228.   for (i=0; i<10; i++)
  229.   {
  230.     printf("%i ",A[i]);
  231.   }
  232.   getch();
  233. }
  234. //--------------------------------------------------------------------------------------------
  235. //===== CH13
  236.  
  237. #include <stdio.h>
  238. #include <conio.h>
  239. #include <stdlib.h>
  240. #define maxl 10
  241.  
  242. void main()
  243. {
  244.   clrscr();
  245.   randomize();
  246.   int A[maxl][maxl], B[maxl][maxl];
  247.   int max,i,j;
  248.   printf("Введите размерность массива (n<%i) \n",maxl);
  249.   scanf("%i",&max);
  250.   if (max>maxl)
  251.     printf("Вы ввели слишком большое число");
  252.   else
  253.   {
  254.     for (i=0; i<max; i++)
  255.     {
  256.       for (j=0; j<max; j++)
  257.       {
  258.         A[i][j]=1+random(5);
  259.         B[j][i]=A[i][j];
  260.         printf("%i ",A[i][j]);
  261.       }
  262.       printf("\n");
  263.     }
  264.     printf("\n\n");
  265.     for (i=0; i<max; i++)
  266.     {
  267.       for (j=0; j<max; j++)
  268.       printf("%i ",B[i][j]);
  269.       printf("\n");
  270.     }
  271.   }
  272.  getch();
  273. }
  274. //--------------------------------------------------------------------------------------------
  275. //===== CH17
  276.  
  277. #include <stdio.h>
  278. #include <conio.h>
  279.  
  280. void main()
  281. {
  282.   float a,b;
  283.   char st;
  284.   printf("Введите значения сопротивлений a и b\n");
  285.   scanf("%f%f",&a,&b);
  286.   printf("\nУкажите тип соединения (l-послед,p-параллел)\n");
  287.   do
  288.   {
  289.     st=getch();
  290.     if ((st=='l')||(st=='p'))
  291.       break;
  292.   } while (1);
  293.   if (st!='l')
  294.   {
  295.     printf("1Последовательное соединение\nРезультат %f",a+b);
  296.   }
  297.   else
  298.   {
  299.     printf("2Параллельное соединение\nРезультат %f",(a*b)/(a+b));
  300.   }
  301.   getch();
  302. }
  303. //--------------------------------------------------------------------------------------------
  304. //===== CH18
  305.  
  306. #include <stdio.h>
  307. #include <conio.h>
  308.  
  309. int puty(int v,int t)
  310. {
  311.   if ((v<0)||(t<0))
  312.     return -1;
  313.   else
  314.     return v*t;
  315. }
  316.  
  317. void main()
  318. {
  319.   int v,t,a;
  320.   clrscr();
  321.   printf("Vvedite V i T\n");
  322.   scanf("%i%i",&v,&t);
  323.   if (puty(v,t)>=0)
  324.     printf("peshehod proshel %i km",puty(v,t));
  325.   else
  326.     printf("oshibka");
  327.   getch();
  328. }
  329. //--------------------------------------------------------------------------------------------
  330. //===== CH19
  331.  
  332. #include <stdio.h>
  333. #include <conio.h>
  334. #include <stdlib.h>
  335.  
  336. int sum(int *a, int n)
  337. {
  338.   int s=0;
  339.   for (int i=0; i<n; i++)
  340.     s=s+a[i];
  341.   return s;
  342. }
  343.  
  344. void outa(int *a,int n)
  345. {
  346.   for (int i=0; i<n; i++)
  347.     printf("%i ",a[i]);
  348.   printf("\n");
  349. }
  350.  
  351. int cmp(int *a,int *b, int n)
  352. {
  353.   if (sum(a,n)<sum(b,n))
  354.     return -1;
  355.   else if (sum(a,n)==sum(b,n))
  356.     return 0;
  357.   else
  358.     return 1;
  359. }
  360.  
  361. void main()
  362. {
  363.   randomize();
  364.   clrscr();
  365.   int a[10], b[10], i;
  366.   for (i=0;i<10;i++)
  367.   {
  368.     a[i]=random(10);
  369.     b[i]=random(10);
  370.   }
  371.   outa(a,10);
  372.   outa(b,10);
  373.   switch (cmp(a,b,10))
  374.   {
  375.     case -1:{printf("perviy menshe vtorogo"); break;}
  376.     case 0:{printf("oni ravni"); break;}
  377.     case 1:{printf("perviy bolshe vtorogo"); break;}
  378.   }
  379.   getch();
  380. }
  381. //--------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment