Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 7th, 2007, 05:53 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , .
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ouput Error

Hi All,
I have been pulling my hair out trying to figur out this problem. Please help!!! I just started C++

I need my output to look like this:
The original vector v[] is:
v[] = { 1.05 -2.55 1.75 1.10 -0.75 2.43 -3.55 4.19 1.45 -0.05 } //The issue when I run the code is the first number 0.05 rather than 1.05
The rearranged vector v[] is:
v[] = { -3.55 -2.55 -0.75 -0.05 1.05 1.10 1.45 1.75 2.43 4.19 } //The issue when I run is, it is not sorting in this order
The length of the vector v[] is 7.11397 //Not sure what this means or how to do this


void prob2(void)

{

 FILE *infile, *outfile;

 int rows, val, rval, j, k, n;

 infile = fopen("data.dat", "r");

 outfile = fopen("output2.dat", "w");



 printf("\nThe original vector v[] is:\n");

 fprintf(outfile,"\nThe original vector v[] is:\n");

 printf("v[] = {");

 fprintf(outfile,"v[] = {");



 fscanf(infile, "%d", &rows);

 for(k=0; k<10; k++)

   {

    fscanf(infile, "%lf", &val);

    printf(" %.2f", val);

    fprintf(outfile," %.2f", val);

   }

 printf(" }\n");

 fprintf(outfile," }\n");



 printf("\nThe rearranged vector v[] is:\n");

 printf("v[] = {");



 double v[]={ 1.05, -2.55, 1.75, 1.10, -0.75, 2.43, -3.55, 4.19, 1.45, -0.05 };

 rearr(v,n);

 int x;

 for(x=0; x<10; x++)

    printf(" %.2f", v[x]);

    printf(" }");

    printf("\n");

}



double rearr(double *v, int n)

{

  int i, j, flag=1;

  int temp;

  for(i=1; i<=10 &&flag; i++)

    {

     flag = 0;

     for(j=0; j<9; j++)

       {

        if(v[j+1]<v[j])

         {

          int temp=v[j];

          v[j]=v[j+1];

          v[j+1]=temp;

          flag = 1;

         }

       }

    }

return;

}







void matrix1(double **A, double **B, double *a, double *b, int size)

{

  int row, col;

  printf("\nMatrix A is:\n\n");



  for(row=0; row<size; row++)

    {

     for(col=0; col<size; col++)

       {

        printf("%.3f ", A[row][col]);

       }

    }



  for(row=0; row<size; row++)

    {

     for(col=0; col<size; col++)

       {

        B[row][col]=1.5*A[row][col]*A[row][col];

       }

    }



  printf("\nVector a is:\n\n");

  printf("a[] = ");



  for(col=0; col<4; col++)

    {

     printf("%.3f ", a[col]);

    }



  for(row=0; row<4; row++);

    {

     b[row]=((A[row][0]+A[row][1]+A[row][2]+A[row][3])*a[row])+.5*a[row];

    }

}






Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL: Ouput replaces dot as comma ?? elayaraja.s XSLT 2 August 19th, 2008 08:37 AM
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Wiered ouput exstream ASP.NET 2.0 Basics 2 May 12th, 2006 04:59 PM
helpme ! query ouput categorize by group on asp eyesonly Classic ASP Databases 0 January 23rd, 2004 04:15 AM



All times are GMT -4. The time now is 05:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.