|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Registered Member
Last Online: 05-28-2013
Join Date: Jun 2006
Posts: 781
Thanks: 168
Thanked 303 Times in 187 Posts
Groans: 23
Groaned at 22 Times in 18 Posts
|
Assignment 4.1 1) Write a program that uses one loop and one if-else statement, such that given an input N, it prints N integers following the pattern: 1 2 3… N/2 (N/2-1) (N/2-2) (N/2-3)… 3 2 1, for example, if N = 11 it prints: 1 2 3 4 5 6 5 4 3 2 1, for N = 10 it prints: 1 2 3 4 5 5 4 3 2 1 2) Use two nested loops to print the following triangle: ********** ******** ****** **** ** * Ask the user to enter the width of the triangle, for example, for the above triangle, the user would have entered 10. No need to ask for the height since for each line you need to remove one * from the left and another from the right. This is my assignment, we usually solve it in the lab course but this week we have the midterms before the lab so we won't be able to solve them. I already wrote them codes: For the first one it is not working on odd integers. For the second one , it's not giving me 1 star in the end plus I can't make them centered. Any idea guys? bkoun mamnounkoun! |
|
|
|
|
|
#2 |
|
Super Moderator
Last Online: 02-16-2022
Join Date: May 2006
Posts: 5,580
Thanks: 1,888
Thanked 2,653 Times in 1,593 Posts
Groans: 55
Groaned at 35 Times in 32 Posts
|
For the first one it is not working on odd integers.
use ceil(N/2)
__________________
click on 'Groan' to switch to my left testicle. Last edited by Kingroudy; 11-01-2010 at 07:03 PM. |
|
|
|
|
|
#3 |
|
Registered Member
Last Online: 05-28-2013
Join Date: Jun 2006
Posts: 781
Thanks: 168
Thanked 303 Times in 187 Posts
Groans: 23
Groaned at 22 Times in 18 Posts
|
|
|
|
|
|
|
#4 |
|
Super Moderator
Last Online: 02-16-2022
Join Date: May 2006
Posts: 5,580
Thanks: 1,888
Thanked 2,653 Times in 1,593 Posts
Groans: 55
Groaned at 35 Times in 32 Posts
|
no no no, lol, i will correct it, you need to take the ceiling not the floor.
i think you will need cmath.h
__________________
click on 'Groan' to switch to my left testicle. |
|
|
|
|
|
#5 | ||
|
Registered Member
Last Online: 05-28-2013
Join Date: Jun 2006
Posts: 781
Thanks: 168
Thanked 303 Times in 187 Posts
Groans: 23
Groaned at 22 Times in 18 Posts
|
Quote:
Quote:
bas for N=11 saret ta3tine 1 2 3 4 5 6 6 5 4 3 2 ana bade yeha ta3tine 1 2 3 4 5 6 5 4 3 2 1
|
||
|
|
|
|
|
#6 | |
|
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
|
I coded it in C
Quote:
__________________
|
|
|
|
|
|
|
#7 | |
|
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
|
And that's for the second one
Quote:
__________________
|
|
|
|
|
|
|
#8 |
|
Registered Member
Last Online: 05-28-2013
Join Date: Jun 2006
Posts: 781
Thanks: 168
Thanked 303 Times in 187 Posts
Groans: 23
Groaned at 22 Times in 18 Posts
|
Thank you google,
I translated the first one to C++ and i modified something and it worked, merci. but about the second, he is asking us to use only two nested loops with no if statement and he want us to remove 1 star from the right and one from the left ( it did not printed as the right format in the thread) thanks again |
|
|
|
![]() |
|
| Tags |
| helpc |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|