Jump to content

Recommended Posts

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. 
Mrozy, Substanz and Ramdallsn like this

L8RKZiW.png

Link to post
Share on other sites

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
Link to post
Share on other sites

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...

L8RKZiW.png

Link to post
Share on other sites

 

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 ^^

L8RKZiW.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...