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