7.3.. Napisati program za izračunavanje y na osnovu vrijednosti x:

Listing programa:

#include <iostream>

using namespace std;

int main()
{
    	int x,y;
    	cin>>x;
	switch(x)
   	{
    		case 1:
       		y = x + 2;
       		cout<<x<<endl;
        		cout<<y;
        		break;
    		case 2:
        		y = x - 2;
        		cout<<x<<endl;
        		cout<<y;
        		break;	
		case 3:               
       		y = x / 2;    
        		cout<<x<<endl; 
        		cout<<y;         
        		break;             
    		case 4:
        		y = x -5;
        		cout<<x<<endl;
        		cout<<y;
        		break;
    		case 5:
        		y = 2 - x;
        		cout<<x<<endl;
        		cout<<y;
        		break;
    default:
        cout << "Greska" << endl;
    }
    return 0;
}

Ispis na ekranu:

Index