Toshkent Axborot Texnologiyalari Universiteti
712-19 guruh talabasi No’monov Murodjon
1-labaratoriya
15. Берилган матнли файлдан символларни ўқиб, экранг чиқаринг ва рақамларни ажратиб кўрсатинг.
#include
#include
#include
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
2-labaratoriya ishi
15. Stekni juft oʻrinda turgan elementlari oʻchirilsin.
include
#include
#include
using namespace std;
static void printStack(stack s)
{
while (!s.empty())
{
cout << s.top() << " ";
s.pop();
}
}
static void deleteEven(stack s)
{
stack temp;
while (!s.empty())
{
int val = s.top();
s.pop();
if (val % 2 == 1)
temp.push(val);
}
while (!temp.empty())
{
s.push(temp.top());
temp.pop();
}
printStack(s);
}
int main()
{
stack s;
s.push(16);
s.push(15);
s.push(29);
s.push(24);
s.push(19);
deleteEven(s);
return 0;
}
Do'stlaringiz bilan baham: |