Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define SIZE 50
- //is it appropriate to use this style? maybe not in main, but in some major function, which does few different zadacha
- int main()
- {
- int i,j,start,finish,temp,flag,arr[SIZE],multipl,rest ,zero_count,count=0;
- multipl=1;zero_count = j = 0;
- 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};
- for(i=0;i<SIZE;i++)arr[i]=rand()%5;//populate array
- for(i=0;i<SIZE;i++)printf("%d\t",arr[i]);//print array
- for(i=0;i<SIZE;i++)if(arr[i]==0){start=i;break;}//find start
- for(i=start+1;i<SIZE;i++)if(arr[i]==0){finish=i;break;}//find finish
- for(i=start+1;i<finish;i++){count++;multipl*=arr[i];}//calculate multiplication
- //of all elements between first and second zeros, and count those elms
- for(i=0;i<SIZE;i++)if(arr[i]==0)zero_count++;
- int arr2[zero_count];
- for(i=0;i<SIZE;i++)if(arr[i]==0)arr2[j++]=i;//populate arr2 with indexes of zero els
- for(j=0;j<zero_count;j++)printf("%d\t",arr2[j]);//print array
- for(i=0;i<SIZE;i++)
- {temp=arr3[i];flag =1;rest=temp%10;
- while(temp/10) //check if temp consists of the same digits 333,66...
- {
- temp/=10;
- if(temp%10!=rest)
- {flag=0;break;}
- }
- if(flag)
- printf("%d are great!\n",arr3[i]);
- }
- //printf("\nstart %d finish %d count %d multipl %d\n",start,finish,count,multipl);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement