Problem help!!.......................................

Hi
I need your help and I would appreciate if you help me.The question asks that (Increase by 2
The one-dimensional array A of integers is given. Increase by 2 each its non-negative element.


Specifications
Input

In the first line the number of elements h (h ≤ 100) in array is given. In the second line the elements of array are given, each of them by the absolute value does not exceed 100.

Output

Print h numbers in one line - the new elements of array, in the order they were given)
But whenever I write for example 4 and then 1,2,3,4 the code manipulates as 3,4,5,6,6 (the last number is repeated and I cannot solve that).Please help me..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include <stdio.h>
int n,i;
int array[100];
int main(int argc, char *argv[])
{
 scanf("%d",&n);
 for(i=0;i<n;i++)
{  scanf("%d",&array[i]);}

for(i=0;i<n;i++)
{if((array[i]>0)&&(array[i]<=100))
{ printf("%d ",array[i]+2);}
else
   printf("%d ",array[i]);}
  
 
if((array[n-1]>0)&&(array[n-1]<=100))
{printf("%d\n",array[n-1]+2);}
  else
  { printf("%d\n",array[n-1]);}
   system("pause");
 getchar();    
 return 0;
}
Last edited on
Topic archived. No new replies allowed.