Tuesday, March 19, 2013

Find Median in a Series and Filing by Matee Gojra

By Unknown   Posted at  3:42 AM   C++ Programming 1 comment

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

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

1 comment:

  1. i did not run this program....yar ye swaping sy values i think ascending order mein nai ho gi...

    ReplyDelete

Back to top ↑
Connect with Us

    What's Trending in Videoism

    Total Pageviews

    Copy of any Post is Not Allowed. All Rights Reserved with Matee ur Rehman (Author). Powered by Blogger.

    Advertisements

    Follow us on FaceBook

What they says

© 2013 GC Study Timez. WP Daily Quranand Hadith Converted by Matee Gojra
Blogger templates. Proudly Powered by Blogger.