Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- int a[100], n, i;
- int b[100], suma, j, k=0;
- scanf("%d", &n);
- for(i=0; i<n; i++) {
- scanf("%d", &a[i]);
- }
- for(i=0; i<n; i++){
- suma=0;
- for(j=0; j<i; j++){
- suma+=a[j];
- }
- if(i == 0) {
- b[k] = a[i];
- k++;
- }
- else {
- if(a[i] > suma) {
- a[i] = 0;
- }
- else {
- b[k] = a[i];
- k++;
- }
- }
- }
- for(i=0; i<k; i++)
- printf("%d ", b[i]);
- return 0;
- }
- // 7 2 0 0 3 0 5
- //[7,2,0,3,5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement