Advertisement
Lisaveta777

Work with array,no functions

Dec 29th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define SIZE 50
  4. //is it appropriate to use this style? maybe not in main, but in some major function, which does few different zadacha
  5. int main()
  6. {
  7.     int i,j,start,finish,temp,flag,arr[SIZE],multipl,rest ,zero_count,count=0;
  8.     multipl=1;zero_count = j = 0;
  9.     int arr3[SIZE]={76,809,395,333,66,2323,999,22,10,0,76,809,395,333,66,2323,999,22,10,0,76,809,395,333,66,2323,999,22,10,0,76,809,395,333,66,2323,999,22,10,0,76,809,395,333,66,2323,999,22,10,0};
  10.     for(i=0;i<SIZE;i++)arr[i]=rand()%5;//populate array
  11.     for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
  12.     for(i=0;i<SIZE;i++)if(arr[i]==0){start=i;break;}//find start
  13.     for(i=start+1;i<SIZE;i++)if(arr[i]==0){finish=i;break;}//find finish
  14.     for(i=start+1;i<finish;i++){count++;multipl*=arr[i];}//calculate multiplication
  15.     //of all elements between first and second zeros, and count those elms
  16.     for(i=0;i<SIZE;i++)if(arr[i]==0)zero_count++;
  17.  
  18.     int arr2[zero_count];
  19.     for(i=0;i<SIZE;i++)if(arr[i]==0)arr2[j++]=i;//populate arr2 with indexes of zero els
  20.     for(j=0;j<zero_count;j++)printf("%d\t",arr2[j]);//print array
  21.  
  22.     for(i=0;i<SIZE;i++)
  23.     {temp=arr3[i];flag =1;rest=temp%10;
  24.         while(temp/10)    //check if temp consists of the same digits 333,66...
  25.         {
  26.             temp/=10;
  27.             if(temp%10!=rest)
  28.                 {flag=0;break;}
  29.         }
  30.         if(flag)
  31.             printf("%d are great!\n",arr3[i]);
  32.     }
  33. //printf("\nstart %d finish %d count %d multipl %d\n",start,finish,count,multipl);
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement