Roohansama 506 Posted February 21, 2019 Report Share Posted February 21, 2019 HI guys,i hope everyone is doing fine.so we are currently studying c++ basics in university.today we did a bit of "for loop".i wrote a multiplication table of 2. #include<iostream>#include<cstdlib>using namespace std;int main(){int i, b;cin >> i;cin >> b;for (int a =0; a <= b; a++){cout << i << "*" << a << "=" << i*a << endl; }system("pause");}can anyone write the table of 2 till the value of "b" but with skipping 2 numbers, like below for the multiplication table of "2"2 one times 2 then, (after skipping 2 numbers) 2 four times 8.. P.S: i know my explanation is the worst. Ramdallsn, Substanz and Mrozy like this Quote Link to post Share on other sites
Mrozy 391 Posted February 21, 2019 Report Share Posted February 21, 2019 I'm not sure I understand your explanation. You created a program that multiplies the number "i" by consecutive natural numbers from 0 to b.When I type for variables i=2, b=10 I'm getting: 2*0=0,2*1=2, ... , 2*10=20. What we wanna do is to multiply 2 by successive numbers, omitting 2 multiples every time, so we get: 2*0=0, 2*3=6, 2*6=12, ... , 2*b. #include<iostream>using namespace std;main(){int b;cin >> b;for (int a=0; a <= b; a+=3){cout << 2 << "*" << a << "=" << 2*a << endl;}return 0;} Substanz and Roohansama like this Quote http://csgo-stats.com/mrozy/graphic.png Link to post Share on other sites
Roohansama 506 Posted February 21, 2019 Author Report Share Posted February 21, 2019 I'm not sure I understand your explanation. You created a program that multiplies the number "i" by consecutive natural numbers from 0 to b.When I type for variables i=2, b=10 I'm getting: 2*0=0,2*1=2, ... , 2*10=20. What we wanna do is to multiply 2 by successive numbers, omitting 2 multiples every time, so we get: 2*0=0, 2*3=6, 2*6=12, ... , 2*b. #include<iostream>using namespace std;main(){int b;cin >> b;for (int a=0; a <= b; a+=3){cout << 2 << "*" << a << "=" << 2*a << endl;}return 0;} Thank you mrozy... ^^i was righting "a++3 " instead of "a+=3" thats all... Quote Link to post Share on other sites
Roohansama 506 Posted February 21, 2019 Author Report Share Posted February 21, 2019 javascript ftw to use this code, copy it, press ctrl+shift+j,paste it.love you ===========================var arr = [1,2,3,4,5,6,7,8,9]; for(let x =0;x<arr.length;x++){ console.log(arr[x] + " number of humans loves nN and Substanz");}=========================== I dont know whats that ^^,,, i think i dont have the compiler for that ^^ Quote Link to post Share on other sites
Acea 370 Posted February 21, 2019 Report Share Posted February 21, 2019 Why do you use system("pause")? You should use indentation for cleaner code. Quote http://nsa38.casimages.com/img/2016/06/14/16061405541885011.png Link to post Share on other sites
Roohansama 506 Posted February 22, 2019 Author Report Share Posted February 22, 2019 Roohan open chrome and vlick Ctrl + Alt + JThis is for loop in JavaScripti press ctrl+alt+j in chrome and nothing happens Quote Link to post Share on other sites
Roohansama 506 Posted February 22, 2019 Author Report Share Posted February 22, 2019 Why do you use system("pause")? You should use indentation for cleaner code.the program used to close in a millisecond after giving answer . i use sytem("pause") to make it stop Mrozy likes this Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.