Here is the simple program to find the multiples of 3. I can get the correct multiples of 3. But when I am trying to access a particular value. It’s throwing me garbage.
#include <iostream>
using namespace std;
int main()
{
int n,i;
std::cout <<" Enter number: "<< std::endl;
std::cin >> n;
int m3[n];
for (i = 1; i < n; i++) {
/* code */
if(i % 3 == 0){
m3[i]=i;
cout<<m3[i];
cout<<endl;
}
}
cout<<endl;
cout<<m3[1];
}
Output: