// Prepared on Demand of Sir Yahya
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream myfile("Series.txt", ios::app); // Syntax of File Creating
if(!myfile) // Cheking weather it is Successful action of Opening File
{
cerr<<"\n\t\tFile Opening Error...!\n"; // To Display Error Msg in Case of File Opening Error
exit(0);
}
int i,j,k,sz,indx;
float med,t;
cout<<"\n How Many Numbers You Want to Enter : ";
cin>>sz; // size of Series
float srs[sz];
cout<<"\n Enter "<<sz<<" Numbers: ";
for(i=0;i<sz;i++)
cin>>srs[i];
myfile<<"\n Series is as: ";
for(i=0;i<sz;i++)
myfile<<srs[i]<<" ";
cout<<"\n Series in Ascending Order: ";
myfile<<"\n Series in Ascending Order: ";
for(i=0;i<sz;i++) // For Setting Series Elements in Ascending Order
{
for(j=0;j<sz;j++)
if(srs[i]<srs[j]) //Swapping Values for Ascending Order
{
t=srs[i];
srs[i]=srs[j];
srs[j]=t;
}
}
for(i=0;i<sz;i++)
{
cout<<srs[i]<<" ";
myfile<<srs[i]<<" ";}
cout<<endl;
if(sz%2!=0) // Find Median
{
indx=sz/2;
med=srs[indx];
}
else
{
med=(srs[sz/2] + srs[sz/2-1])/2;
}
cout<<"\n\tMedian = "<<med<<endl;
myfile<<"\n\tMedian = "<<med<<endl;
myfile<<"\n***********************\n\n";
system("pause");
} // End
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream myfile("Series.txt", ios::app); // Syntax of File Creating
if(!myfile) // Cheking weather it is Successful action of Opening File
{
cerr<<"\n\t\tFile Opening Error...!\n"; // To Display Error Msg in Case of File Opening Error
exit(0);
}
int i,j,k,sz,indx;
float med,t;
cout<<"\n How Many Numbers You Want to Enter : ";
cin>>sz; // size of Series
float srs[sz];
cout<<"\n Enter "<<sz<<" Numbers: ";
for(i=0;i<sz;i++)
cin>>srs[i];
myfile<<"\n Series is as: ";
for(i=0;i<sz;i++)
myfile<<srs[i]<<" ";
cout<<"\n Series in Ascending Order: ";
myfile<<"\n Series in Ascending Order: ";
for(i=0;i<sz;i++) // For Setting Series Elements in Ascending Order
{
for(j=0;j<sz;j++)
if(srs[i]<srs[j]) //Swapping Values for Ascending Order
{
t=srs[i];
srs[i]=srs[j];
srs[j]=t;
}
}
for(i=0;i<sz;i++)
{
cout<<srs[i]<<" ";
myfile<<srs[i]<<" ";}
cout<<endl;
if(sz%2!=0) // Find Median
{
indx=sz/2;
med=srs[indx];
}
else
{
med=(srs[sz/2] + srs[sz/2-1])/2;
}
cout<<"\n\tMedian = "<<med<<endl;
myfile<<"\n\tMedian = "<<med<<endl;
myfile<<"\n***********************\n\n";
system("pause");
} // End
i did not run this program....yar ye swaping sy values i think ascending order mein nai ho gi...
ReplyDelete