Witam, potrzebuję pilnie pomocy, mam bardzo ważne zadanie domowe na programowanie do szkoły, nauczyciel się trochę wkurzył i na czwartek muszę przynieść gotowy program, zadanie brzmi: Napisać algorytm w postaci schematu blokowego oraz kod programu w języku C++ który czyta z klawiatury liczby z zakresu od 1 do 100, sprawdzi czy są to liczby parzyste oraz wyświetli w odwrotnej kolejności tylko liczby nieparzyste większe od 30, liczby należy oddzielić myślnikiem. Wiem że dosyć nakombinowanie ale będę bardzo wdzięczny za pomoc:)
" Life is not a problem to be solved but a reality to be experienced! "
© Copyright 2013 - 2024 KUDO.TIPS - All rights reserved.
Rozumiem że ma tylko sprawdzić czy liczby są parzyste i nic z nimi nie zrobić.... :)
W odwrotnej kolejności czyli od największej do najmniejszej ? :)
Prościzna . Zajęło mi to nie całe 10min napisania programu, gorzej z algorytmem . Tam nie mogę użyć po prostu for-a.
Odnośnie kodu :
Z Twojego zadania wywnioskowałem że zakres ma byc podany przez usera i ma zaczynać się od 1 do 100, dlatego wymuszam podanie takiego zakresu.
Liczby parzyste oddzielam przecinkiem, nie parzyste < 30 w odwrotnej kolejności - .
Na początku wyświetlania masz znak , lub - . Nie wiem jak go usunąć próbowałem z ( if i < odd - 1) ale to nic nie daje. Ale to raczej nie jest takie ważne po prostu pokazuje ,2,4 a nie 2,4 :) Odwrotna kolejność czyli zacząłem wyświetlać od DOO ( naszego 100 ) do 1 i tylko liczby które są > 30 .
Objaśnienia: i++ - inkrementacja, i-- dekrementacja , || - lub , && - i (AND)
Kod :
#include <iostream>
using namespace std;
int main(){
int i = 0,od = 0, doo = 0, dobrze = 1;
do {
cout << "Podaj zakres od 1: "; cin >> od;
cout << "do 100: "; cin >> doo;
if ( od != 1 || doo != 100) {
dobrze = 0;
system("cls");
cout << "\nPodales zly zakres. Od ma byc rowny 1 a do 100 - sprobuj ponownie\n";
}
}while(dobrze !=1);
cout << "\nLiczby parzyste: ";
for ( i = od; i < doo; i++ ){
if ( i%2 == 0)
cout << " , " << i;
}
cout << "\nLiczby nie parzyste: ";
for ( i = doo; i > od; i-- ){
if ( i%2 == 1 && i > 30)
cout << " - " << i;
}
getchar();
getchar();
}
Algorytm załącznik.
Narysowąło mi się w Paincie brzydko ale w Twojej kwestii leży aby przerysować to w ładny sposób. Co do samego algorytmu - wygląda strasznie ale jest prosty. I nie da się tego inaczej rozwiazać - aby było prościej .