Toshkent Axborot Texnologiyalari Universiteti 712-19 guruh talabasi No’monov Murodjon


Download 13.18 Kb.
Sana04.12.2020
Hajmi13.18 Kb.
#158726
Bog'liq
1-2-labaratoriya


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) )



{

//use line here

}

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;

// Utility function to print

// the contents of a stack

static void printStack(stack s)

{

while (!s.empty())



{

cout << s.top() << " ";

s.pop();

}

}



// Function to delete all even

// elements from the stack

static void deleteEven(stack s)

{

stack temp;



// While stack is not empty

while (!s.empty())

{

int val = s.top();



s.pop();

// If value is odd then push

// it to the temporary stack

if (val % 2 == 1)

temp.push(val);

}

// Tranfer the contents of the temporary stack



// to the original stack in order to get

// the original order of the elements

while (!temp.empty())

{

s.push(temp.top());



temp.pop();

}

// Print the modified stack content



printStack(s);

}

// Driver Code



int main()

{

stack s;



s.push(16);

s.push(15);

s.push(29);

s.push(24);

s.push(19);

deleteEven(s);



return 0;

}
Download 13.18 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling