Professional Documents
Culture Documents
C
C
#include "stdafx.h"
#include "iostream"
#include "iomanip"
using namespace std;
int _tmain()
{
int n, k = 1;
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < k; j++)
cout << "*";
cout << endl;
k++;
}
}
ispis oblika
*
**
***
****
______________________________
Piramida v2 oblika:
*
***
******
********
int _tmain()
{
int n;
cin >> n;
int m = n, k = n - 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < k; j++)
cout << ' ';
for (int p = k; p < m; p++)
cout << '*';
k--; m++; cout << endl;
}
}
________________________________
IGRICA pogadanje broja
#include
#include
#include
#include
"stdafx.h"
"iostream"
"ctime"
"cstdlib"
}
}
_________________________________
pitat ahmeda za ovo!
int _tmain()
{
int a, b, c, min, max, mid, raz;
cin >> a >> b >> c;
if (a<1 || a>1000 || b<1 || b>1000 || c<1 || c>1000)
{
cout << "uneseni brojevi nisu iz intervala" << endl;
return 0;
}
raz = 0;
max = a;
if (b > max)
max = b;
if (c > max)
max = c;
if ((a > b && a<c) || (a>c && a < b))
mid = a;
if ((c > b && c<a) || (c>a && c < b))
mid = c;
if ((b > a && b<c) || (b>c && b < a))
mid = b;
min = a;
if (b < min)
min = b;
if (c < min)
min = c;
if (a != b && a != c)
raz = raz + 1;
if (b != a && b != c)
raz = raz + 1;
if (c != a&&c != b)
raz = raz + 1;
cout << min << " " << mid << " " << max << endl;
cout << "razlicito je " << raz << "brojeva" << endl;
return 0;
_____________________________________
pi e 36 kao 2*2*3*3
int _tmain()
{
int n;
bool prost;
cin >> n;
while (n > 1)
{
for (int i = 2; i <= n; i++)
//trazimo proste djelioce naseg broja n
{
if (n%i == 0)
{
prost = true;
for (int j = 2; j <= sqrt(i); j++)
if (i%j == 0)
{
prost = false;
break;
}
if (prost == true)
{
cout << i << " ";
n = n / i;
break;
}
}
}
}
}
_________________________________________
// niz, sortiranje brojeva unesenih u niz
//
#include "stdafx.h"
#include "iostream"
#include "algorithm"
using namespace std;
int _tmain()
{
int niz[20];
int n;
cin>>n;
for (int i = 0; i < n; i++)
cin >> niz[i];
sort(niz, niz + n);
for (int i = 0; i < n; i++)
cout << niz[i] << " ";
}
__________________________________________
#include "stdafx.h"
#include "iostream"
using namespace std;
int _tmain()
{
char ulazniString[100];
for (int i = 0; i <= 11; i++)
cin >> ulazniString[i];
(ulazniString[6] - 48) * 1000 + (ulazniString[7] - 48) * 100 + (ulazniSt
ring[8] - 48) * 10 + ulazniString[9] - 48
return 0;
}
_____________
pokusaj v2
pokusaj Dani// ConsoleApplication9.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include "iostream"
#include "sstream"
using namespace std;
int _tmain()
{
string datum;
cin >> datum;
int g = (datum[6] - 48) * 1000 + (datum[7] - 48) * 100 + (datum[8] - 48)
* 10 + datum[9] - 48;
cout << g;
return 0;
}
________________________________________
nesto nije tacno sa ovim, nadji na http://77.78.198.24/bhoimoodle/pluginfile.php
/101/mod_resource/content/1/Set%203.pdf
// ConsoleApplication9.cpp : Defines the entry point for the console application
.
//
#include "stdafx.h"
#include "iostream"
#include "iomanip"
using namespace std;
int _tmain()
{
int niz[100];
int n, s = 0;
cout << "Unesi broj clanova niza\n";
cin >> n;
cout << "Unesi clanove niza\n";
for (int i = 0; i < n; i++)
matrica[100][100];
n;
>> n;
(int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> matrica[i][j];
matrica[100][100];
n, m;
>> n >> m;
(int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> matrica[i][j];
int max = matrica[0][0], indexReda = 0, indexKolone = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (matrica[i][j] > max)
{
max = matrica[i][j];
indexReda = i;
indexKolone = j;
}
}
int s = 0;
for (int p = 0; p < n; p++)
s += matrica[p][indexKolone];
for (int p = 0; p < m; p++)
s += matrica[indexReda][p];
cout << s - max;
return 0;
}
_______________________________________
funkcije
.jel godina prestupna.
#include "stdafx.h"
#include "iostream"
#include "algorithm" //da sortiramo
using namespace std;
int _tmain()
{
if (IsLeapYear(2000) == true) cout << "Jeste\n";
else cout << "Nije\n";
return 0;
}
_________________________________
funkcija
jel broj prost
bool prost(int N){
bool prost = true;
for (int i = 2; i <= sqrt(N); i++){
if (N%i == 0) {
prost = false;
break;
}
}
return prost;
}
int _tmain()
{
if (prost(23) == true) cout << "Jeste\n";
else cout << "Nije\n";
return 0;
}
____________________________________
provjerava da li je niz sortiran
bool IsSorted(int niz[],int velicina)
{
if (velicina == 1)
return true;
bool sorted = true;
for (int i = 0; i < velicina - 1; i++)
{
if (niz[i]>niz[i+1])
return false;
}
return true;
}
int _tmain()
{
int nekiniz[] = { 1,2,4,44 };
cout << IsSorted(nekiniz, 3) << endl;
return 0;
}
____________________________________
broji proste brojeve u nizu
#include "stdafx.h"
#include "iostream"
#include "algorithm"
using namespace std;
int _tmain()
{
int niz[] = { 4, 17, 2, 3, 23, 27 };
cout << Countprimes(niz, 6);
return 0;
}
__________________________________________
najmanji parni broj nekog unosa
#include
#include
#include
#include
#include
#include
#include
"stdafx.h"
"iostream"
"algorithm"
"vector"
"ctime"
"cstdlib"
"algorithm"
int _tmain()
{
int unos;
vector<int>brojevi;
while (1)
{
cin >> unos;
if (unos == -1)
break;
brojevi.push_back(unos);
}
unos = INT_MAX;
for (int i = 0; i < brojevi.size(); i++)
{
if (brojevi[i] % 2 == 0 && brojevi[i] < unos)
unos = brojevi[i];
}
if (unos == INT_MAX)
cout << "nema parnih brojeva" << endl;
else cout <<"najmanji parni broj je" << unos << endl;
return 0;
}
___________________________________________