Using System. Io; namespace File 1 { class Program { public


Dasturning C# dagi ko’rinishi



Download 64,29 Kb.
bet2/6
Sana03.04.2022
Hajmi64,29 Kb.
#526700
1   2   3   4   5   6
Bog'liq
File 1

Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_5
{
class Program
{
public static void Main(string[] args)
{
string s; int n=0;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
s=Console.ReadLine();
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null
{
char[] m={' '};
string [] a=s.Split(m,StringSplitOptions.RemoveEmptyEntries);
n+=a.Length;
}
Console.WriteLine(n);
Console.ReadKey(true);
}
}
}
Natija:

File 6. Natural sonlar fayli nomi va natural son berilgan. Faylning -elementi chiqarilsin. Agar fayl bo’sh bo’lsa -1 chiqarilsin.
Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_6
{
class Program
{
public static void Main(string[] args)
{
string s; int k,n=0;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("Natural son kiriting: k=");
k=int.Parse(Console.ReadLine());
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null
{
char[] m={' '};
string [] a=s.Split(m,StringSplitOptions.RemoveEmptyEntries);
if (n+a.Length>k) {Console.Write(a[k-n]);break;}
n+=a.Length;
}
Console.ReadKey(true);
}
}
}
Natija:

File 7. Natural sonlar fayli nomi va natural son berilgan. Faylning -elementi chiqarilsin. Agar fayl bo’sh bo’lsa -1 chiqarilsin.
Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_7
{
class Program
{
public static void Main(string[] args)
{
string s; int i=0,n=0;bool f=true;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
s=Console.ReadLine();
StreamReader b=File.OpenText(@"d:\"+s);
s=b.ReadLine();
{
char[] m={' '};
string [] a=s.Split(m,StringSplitOptions.RemoveEmptyEntries);
Console.Write(a[0]+"\t"+a[1]+"\t"+a[a.Length-2]+"\t"+a[a.Length-1]);
}
Console.ReadKey(true);
}
}
}
Natija:

File 8. 2 ta haqiqiy sonlar fayli nomi berilgan. shu fayllarning birinchi bo’sh bo’lmagani ma’lum va ikkinchisi joriy katalogda mavjud emas. Mavjud bo’lmagan fayl yaratish va mavjud bo’lgan faylning birinbchi va oxirgi elementi shu faylga yozilsin.


Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_9
{
class Program
{
public static void Main(string[] args)
{
string s,S,c=null,p=null; bool f; char[] m={' '};
Console.Write("1-fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("2-fayl nomini kiriting: ");
S=Console.ReadLine();
FileInfo g=new FileInfo(@"d:\"+s);f=g.Exists;
if (!f) {c=s;s=S;S=c;f=true;}
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null)
{
string [] a=s.Split(m,StringSplitOptions.RemoveEmptyEntries);
if (f) c=a[0]+" ";f=false;p=s;
}
string [] t=p.Split(m,StringSplitOptions.RemoveEmptyEntries);
c+=t[t.Length-1];b.Close();
StreamWriter d=File.CreateText(@"d:\"+S);
d.WriteLine(c);
d.Close();
Console.ReadKey(true);
}
}
}
Natija:

File 9. 2 ta haqiqiy sonlar fayli berilgan. shu fayllardan biri (birinchisi bo’lshi shart emas) bo’sh bo’lmagani ma’lum va boshqasi esa joriy katalogda mavjud emas. Mavjud bo’lmagan fayl yaratish va mavjud bo’lmagan faylning birinchi va oxirgi elementi shushu faylga yozilsin.


Dasturning C# dagi ko’rinishi:

Natija:

File 10. Butun sonlar fayli berilgan. berilgan fayl elementlarini teskari tartibda o’zida aks ettiradigan yangi fayl hosil qilinsin.


Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_10
{
class Program
{
public static void Main(string[] args)
{
string s,p="";char [] m={'|'};
Console.Write("Mavjud fayl nomini kiriting: ");
s=Console.ReadLine();
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null)p=s+"|";
b.Close();
string [] a=p.Split(m,StringSplitOptions.RemoveEmptyEntries);
StreamWriter d=File.AppendText(@"d:\Farg'ona.txt");m[0]=' ';
for (int j=a.Length-1;j>=0;j--) 
{
string [] h=a[j].Split(m,StringSplitOptions.RemoveEmptyEntries);
for (int i=h.Length-1;i>=0;i--)d.Write(h[i]+" ");
d.WriteLine();
}
d.Close();
Console.ReadKey(true);
}
}
}
Natija:

File 11. Haqiqiy sonlar fayli berilgan. 2 ta yangi fayl hosil qilinsin, ular o’zida birinchisi berilgan faylning toq no’merli elementlarini, ikkinchisi juft no’merlilarini o’zida aks ettirsin.


Dasturning C# dagi ko’rinishi:
Natija:
using System;
using System.IO;

namespace File_10
{
class Program
{
public static void Main(string[] args)
{
string s,s1,s2,p="";char [] m={'|'};int i,j;
Console.Write("Mavjud fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("1-fayl nomini kiriting: ");
s1=Console.ReadLine();
Console.Write("2-fayl nomini kiriting: ");
s2=Console.ReadLine();
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null)p=s+"|";
b.Close();
string [] a=p.Split(m,StringSplitOptions.RemoveEmptyEntries);
StreamWriter d=File.AppendText(@"d:\"+s1);
StreamWriter n=File.AppendText(@"d:\"+s2);m[0]=' ';
for (j=0;j{
string [] h=a[j].Split(m,StringSplitOptions.RemoveEmptyEntries);
for (i=0;i{
if (Convert.ToInt32(h[i])%2==0)d.Write(h[i]+" ");
else n.Write(h[i]+" ");
}
d.WriteLine();n.WriteLine();
}
d.Close();n.Close();
Console.ReadKey(true);
}
}
}
File 12. Butun sonlar fayli berilgan. 2 ta yangi fayl hosil qilinsin, birinchisi dastlabki faylning juft elementlarini ikkinchisi esa toqlarinini (tartib bilan ) o’zida aks ettirsin. Agar berilgan faylning juft toq elementlari bo’lmasa, u holda natijaviy fayllar bosh bo’lsin.
Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_12
{
class Program
{
public static void Main(string[] args)
{
string s,s1,s2,p="";char [] m={'|'};int i,j;
Console.Write("Mavjud fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("1-fayl nomini kiriting: ");
s1=Console.ReadLine();
Console.Write("2-fayl nomini kiriting: ");
s2=Console.ReadLine();
StreamReader b=File.OpenText(@"d:\"+s);
while((s=b.ReadLine())!=null)p=s+"|";
b.Close();
string [] a=p.Split(m,StringSplitOptions.RemoveEmptyEntries);
StreamWriter d=File.AppendText(@"d:\"+s1);
StreamWriter n=File.AppendText(@"d:\"+s2);m[0]=' ';
for (j=0;j{
string [] h=a[j].Split(m,StringSplitOptions.RemoveEmptyEntries);
for (i=0;i{
if (Convert.ToInt32(h[i])%2==0)d.Write(h[i]+" ");
else n.Write(h[i]+" ");
}
d.WriteLine();n.WriteLine();
}
d.Close();n.Close();
Console.ReadKey(true);
}
}
}
Natija:

File 13. . Butun sonlar fayli berilgan. 2 ta yangi fayl hosil qilinsin, birinchisi dastlabki faylning musbat elementlarini (teskari tartibda ) ikkinchisi manfiy elementlarini (teskari tartib bilan o’zida aks ettirsin. Agar dastlabki faylda manfiy va musbat elementlari bo’lmasa, u holda natijaviy fayllar bosh bo’lsin.


Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_13
{
class Program
{
public static void Main(string[] args)
{
string s,s1,s2;char [] m={' ',','};double c;
Console.Write("Dastlabki mavjud fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("1-fayl nomini kiriting: ");
s1=Console.ReadLine();
Console.Write("2-fayl nomini kiriting: ");
s2=Console.ReadLine();
StreamWriter b=File.CreateText(@"d:\"+s1);
StreamWriter d=File.CreateText(@"d:\"+s2);
string [] h=File.ReadAllLines(@"d:\"+s);
for (int i=0;i{
string [] a=h[i].Split(m,StringSplitOptions.RemoveEmptyEntries);
for (int j=0;j{
c=Convert.ToInt32(a[j]);
if (c>0) b.Write(c+" ");
if (c<0) d.Write(c+" ");
}
b.WriteLine();d.WriteLine();
}
b.Close();d.Close();
Console.ReadKey(true);
}
}
}
Natija:
File 14. Haqiqiy sonlar fayli berilgan. Uning elementlari o’rta arifmetigini topish dasturi tuzilsin.
Dasturning C# dagi ko’rinishi:
using System;
using System.IO;

namespace File_14
{
class Program
{
public static void Main(string[] args)
{
string s;char [] m={' ',','};double c=0;int n=0;
Console.Write("Mavjud fayl nomini kiriting: ");
s=Console.ReadLine();
string [] h=File.ReadAllLines(@"d:\"+s);
for (int i=0;i{
string [] a=h[i].Split(m,StringSplitOptions.RemoveEmptyEntries);
for (int j=0;j{
c+=Convert.ToInt32(a[j]);
}
n+=a.Length;
}
c=c/n;Console.WriteLine("Natija: "+c);
Console.ReadKey(true);
}
}
}
Natija:
File 15. Haqiqiy sonlar fayli berilgan. Uning juft nomerli elementlari yig’indisini topish dasturi tuzilsin.

Download 64,29 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish