![]() |
[help]c++
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! |
For the first one it is not working on odd integers.
use ceil(N/2) |
Quote:
if N=11 , N/2=5.5 it will take it 6?! does it need a special library in the header?! |
no no no, lol, i will correct it, you need to take the ceiling not the floor.
i think you will need cmath.h |
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 :S |
I coded it in C
Quote:
|
And that's for the second one
Quote:
|
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 |
| All times are GMT +1. The time now is 07:12 AM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger