By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

What does it mean?I have this C++ progam but I don't know what

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a[20],n,i,b[20],j=0;
  8.  
  9.     cin>>n;
  10.     for(i=1;i<=n;i++)
  11.         cin>>a[i];
  12.     for(i=1;i<=n;i++)
  13.         if(a[i]%2==0)
  14.     {
  15.         j++;
  16.         b[j]=a[i];
  17.     }
  18.     for(i=1;i<=j;i++)
  19.         cout<<b[j]<<"3";
  20. }
Dec 11 '19 #1
Share this Question
Share on Google+
1 Reply


dev7060
Expert 100+
P: 162
n -> number of elements in the array
a[i] -> array to store numbers provided by the user
b[j] -> array to store the numbers divisible by 2

Expand|Select|Wrap|Line Numbers
  1. for(i=1;i<=j;i++)
  2. cout<<b[j]<<"3";
  3.  
"3" has no significance here.

To output the numbers divisible by 2, the variable used for index in the loop body should be 'i' instead of j.

Also, the 0th index is not used here. For an array a[20], the index ranges from 0 to 19. Using 20 as an index may work, but is not considered safe since that memory block is not occupied and can be allocated to others.
Dec 11 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.