hello everyone
I am anew in c++ programming and I missed my class last week it was about loop ,,I have ahomework I just found out and it due after 3 hours can you help to solve it plz?? Idon't understand any thing
these are the three Q ,,,,I will be greatfull to any one who help ,
1. Using for loop, write a program that reads an integer to generate all its divisors.
Example-1: if you read 11 the out put should be 1 11
Example-2: if you read 8 the out put should be 1 2 4 8
2. Using while loop, Write a program to get a triangle shape with a length entered by
the user. For example, if the user entered a length of 10 then the shape is:
*
**
***
****
*****
******
*******
********
*********
**********
3. Using do while loop, write a program that will calculate the following series:
Sum = 1 + x + x2 + x3 + x4 - - - - + xn
Notice that x and n values should be entered by the user.
his office hours conflictwith my other lecture ,,I tried to solve it but I didn't know how , I am very sorry for bothering you but it marked assig. and I really hate to ask people to do my work that not me and the other reason for ASKING A HELP THAT I just Knew about this homework it was attached to the class note ,
#include<iostream>
usingnamespace std;
void main(){ //void main() - NO! Main() must return an int and therefore only int main() is standard
int d,n;
//put the line where you cout << "The divisors of " << (user_input) << " = "; //end here
for(n=0;n>=0;n++); //infinite loop that's... useless? N = 0, if it's bigger than or EQUAL TO 0 (wtf?)
//change it so that instead of a ; use { } so it becomes a code block
if(n%d==0,d>0) //I assume D is user input (get it before your for loop
cout<<"the diviisor of "<<n<<"="<<d; //finish the previous statement here
//cout n and print a comma and a space
cout<<d; //unneeded line, remove
//end code block here
}
I have outlined some key mistakes
Post in [co.de][/co.de] tags next time please, not quotes.
Q2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream>
usingnamespace std;
void main() //int main()
{
int n,f;
cout<<"enter a number";
cin>>n;
f=0;
i=1; //what's i? int? double? char? string?
while(i<n) //should be <= if i is declared as 1, think about it
//you forgot code blocks again.. { ... }
f=f+1
cout<<"*"; // i don't understand this bit. It just prints a long line of asterisks
//think about it... print a newline after you have enough asterisks on a line
i++
//end code block here
let user_input be user input
get user input
print "The factors of " user_input " are: "for number i = 1, i <= user_input, i++
see if user_input modulo i gives you remainder 0
if it does
print that out followed by comma and a space
if it doesn't
go on
Enter a number: 8
The factor of 8 are: 1, 2, 4, 8,
Can you see how it goes?
The method I used is very inefficient, but once you get the structure working, you can easily expand + edit the code.
. . . .
EDIT: Instead of me hopelessly trying to explain this, read this site's detailed tutorial. This should fill you on what you missed during the lesson and will help you with your homework. http://www.cplusplus.com/doc/tutorial/control/Happy Homeworking . . .
thank iwill go know i have a midtearm exam I will not submit it toady but i will back to this topic on sat.
wait for me ^_^ I will ask your help to get this !!