0% found this document useful (0 votes)
45 views9 pages

Zadaca-For, If Else

The document contains 14 code snippets written in C++ that use for loops to output various patterns and numbers. Many of the snippets demonstrate basic for loop usage to iterate and print values, while others show more complex logic using conditionals and nested loops. Overall the snippets provide examples of common for loop applications in C++ programs.

Uploaded by

Irina Fazlija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views9 pages

Zadaca-For, If Else

The document contains 14 code snippets written in C++ that use for loops to output various patterns and numbers. Many of the snippets demonstrate basic for loop usage to iterate and print values, while others show more complex logic using conditionals and nested loops. Overall the snippets provide examples of common for loop applications in C++ programs.

Uploaded by

Irina Fazlija
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

#include <iostream>

using namespace std;

int main()

{ cout<<"ovaj program ispisuje prvih 10 brojeva";

for (int i = 1; i <= 10; i++) {

cout << i << "\n";

return 0;

2.

#include <iostream>

using namespace std;

int main()

{ int n;

cout<<"Unesi broj";

cin>>n;

for (int i = 1; i <= n; i+=2) {

cout << i << "\n";

return 0;

3.

#include <iostream>

using namespace std;


int main()

{ int n;

cout<<"Unesi broj";

cin>>n;

for (int i = 1; n >=i; n--) {

if(n%3==0){

cout << n << "\n";

return 0;

4.

#include <iostream>

using namespace std;

int

main ()

int n, proizvod;

cout << "Unesi broj: ";

cin >> n;

for (int i = 1; i<=10; i++)

proizvod=n*i;

cout <<n<<"*"<<i<<"="<<proizvod << "\n";

}
return 0;

5.

6.

#include <iostream>

using namespace std;

int main()

int x, y,z;

x=0;

y=1;

cout<<y<<" ";

for (int i=0;i<9; i++){

z=x+y;

cout<<z<<" ";

x=y;

y=z;

return 0;

7.

#include <iostream>

using namespace std;

int main ()

{
cout << "ovaj program ispisuje brojeve, koji su dijeljivi sa pet, ali nisu djeljivi sa dva., u intervalu od 1-100
"<<endl;

for (int i = 1; i <=100; i++) {

if (i%5==0 & i%2!=0) {

cout<<i<<endl;

return 0;

8.

#include <iostream>

using namespace std;

int main ()

cout << "ovaj program ispisuje brojeve koji nisu djeljivi sa tri u intervalu od 1-100 "<<endl;

for (int i = 1; i <=100; i++) {

if (i%3==0) {

continue;

cout << i << "\n";

return 0;

9.

#include <iostream>

using namespace std;


int main ()

{ int n;

cout << "ovaj program ispisuje ocjenu prema broju bodova"<<endl;

cout<<"unesi broj bododva: ";

cin>>n;

if (n>0 & n<=40) {

cout<<"ocjena 1"<<endl;

if(n>40 & n<=55){

cout<<"ocjena 2"<<endl;

if(n>55 & n<=70){

cout<<"ocjena 3"<<endl;

if(n>70 & n<=85){

cout<<"ocjena 4"<<endl;

if(n>85 & n<=100){

cout<<"ocjena 5"<<endl;

return 0;

10.

#include <iostream>

using namespace std;


int main()

{ int sum=0;

for (int i = 1; i <= 100; i++) {

sum+=i;

if (sum > 30) {

break;

cout << sum << endl;

return 0;

11.

#include <iostream>

using namespace std;

int main ()

int a,b,c;

cout << "unesi uglove trougla" << endl;

cin >>a>>b>>c;

if (a+b+c==180)

cout << "trougao je validan" << endl;

else{

cout<<"trougao nije validan";


}

return 0;

12.

#include <iostream>

using namespace std;

int main ()

{ for (int i = 1; i <= 50; i++) {

if (i % 5 == 0 & i % 3 == 0) {

cout << "FizzBuzz" << endl;

else if (i % 3 == 0) {

cout << "Fizz" << endl;

else if (i % 5 == 0) {

cout << "Buzz" << endl;

else {

cout << i << endl;

return 0;

13.

#include <iostream>
using namespace std;

int main(){

for(int i=1;i<=5;i++){

for(int j=6-i;j>=1;j--){

cout<<j;

cout<<endl;

return 0;

14.

#include <iostream>

using namespace std;

int main()

for (int i = 1; i <= 5; i++)

for (int j = 1; j < i; j++){

cout << "*";}

cout << "*" << endl;}

for (int i = 4; i >= 1; i--)

for (int j = i; j >1; j--){

cout <<"*";}

cout << "*" << endl;}


return 0;

You might also like