Advertisement
sbitnev

первая лаба на с++/c

Feb 6th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4.  
  5. int val() //Проверка на правильность введения числа
  6. {
  7.     int num1,str;
  8.     num1=0;
  9.     {
  10.         while ((str=getchar())!='\n')
  11.         {
  12.             num1++;
  13.         if((str==' ') || (str=='\t'))
  14.             num1--;
  15.         }
  16.     }
  17.  
  18.     return num1;
  19. }
  20.  
  21. int main()
  22. {
  23.  
  24.  
  25.     int A[1000],B[1000],C[1000],na,nb,nc=0,i,j,k,num;
  26.  
  27.     do
  28.     {
  29.         printf("Input lenght of array A= ");
  30.         num=0;
  31.         scanf("%d",&na);
  32.         num=val();
  33.         //na=atoi(nna);
  34.         if ((num!=0) || (na<0) || (na>1000) ) printf("Input error, write integers \n");
  35.     }
  36.     while ( (num!=0) || (na<0) || (na>1000)  );
  37.  
  38. printf("Input array A \n");
  39.     for (i=0;i<na;i++)
  40.     {
  41.         do
  42.         {
  43.             num=0;
  44.             scanf("%d",&A[i]);
  45.             num=val();
  46.             if (num!=0) printf("Input error, write integers, put again last digits \n");
  47.         }while (num!=0);
  48.     }
  49.  
  50.  
  51.     do
  52.     {
  53.         printf("Input lenght of array B= ");
  54.         num=0;
  55.         scanf("%d",&nb);
  56.         num=val();
  57.         if (num>0 || nb<0 || nb>1000) printf("Input error, write integers\n");
  58.     }while (num>0 || nb<0 || nb>1000);
  59.  
  60.  
  61. printf("Input array B\n");
  62.     for (i=0;i<nb;i++)
  63.     {
  64.         do
  65.         {
  66.  
  67.             num=0;
  68.             scanf("%d",&B[i]);
  69.             num=val();
  70.             if (num>0) printf("Input error, write integers, put again last digits\n");
  71.         }while (num>0);
  72.     }
  73.  
  74.  
  75.  
  76. //    uc=c;
  77.     for(i=0;i<na;i++)
  78.         if ( (A[i] < 0))
  79.         {
  80.             k=0;
  81.            for(j=0;j<nb;j++)
  82.            {
  83.                if(A[i]!=B[j])
  84.                    k++;
  85.            }
  86.            if ( (k==nb) || (k<nb-1))
  87.                 {
  88.                   C[nc]=A[i];
  89.                   nc++;
  90.                 }
  91.  
  92.         }
  93.  
  94.  
  95.     if (nc==0)  printf("array C is empty");
  96.     else
  97.         {
  98.             printf("array C:\n");
  99.             for (i=0;i<nc;i++) printf("%d   ",C[i]);
  100.         }
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement