473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 1278
dev7060
636 Expert 512MB
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

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

Similar topics

4
by: QQ | last post by:
for example ~CcMessage() {} Thanks a lot! I am a beginner for C++, so please forgive my stupid questions
6
by: wintaki | last post by:
Given int x; What does x evaluate to? If x is 0, it equals 0x31, the ascii value of '1'. So for some reason, x evaluates to *(y+x) where x is a non pointer/array type.
2
by: SMichal | last post by:
Hi, I'm starting from my application simple bat data...test.bat. This file (test.bat) should start another aplication app.exe. I'm starting the test.bat from my application with Start() method of...
2
by: Metalzed | last post by:
I have 4 tabels tbOWNERS // PLAYERS ID , NAME 1 Mike 2 Rambo 3 Sam tbCARS // CARS THAT EXIST AND WHO OWNS THEM
2
by: mantrid | last post by:
in some php script ive seen $something==@$somethingelse whereas something==$somethingelse works the same what does the use of the @ do? Sorry if this is a stupid question
0
by: hini | last post by:
Hello, I see the N' in many asp , sql scripts at the beginning of a string usually and I don't know what's its meaning, I could not find anything about it when seraching google because of the...
5
by: mingle | last post by:
Hi, I have a .pm file, which was placed within my site when it got hacked, i've never used perl before, but after some googling I thought I'd ask the pros at these forums. Heres the code which...
2
by: sailormoon | last post by:
this information i put in data.txt 11221 MOHD IRFAN 80 70 11222 NURUL FITRAH 80 90 11223 MOHD FARHAN 70 80 11224 WAFFIN WARDAH 80 60 11225 SYAMSUL 50 50 99999 TAMAT 0 0 #include<fstream.h>
1
by: Monica Pnade | last post by:
what does /^/ mean in perl?
2
by: jayxxxx | last post by:
the code was for an overload method console.writeline(totalprice(price:=totalprice)) the name of the method was totalprice the parameter for it was price but I didn't know what does :=...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.