Solved

the question is easy (but I don't know what is wrong);please hurry.

Posted on 1998-04-13
2
159 Views
Last Modified: 2010-04-15
I am doing now a spreadsheet using two dimentional arrays I finished it but I can't seem to be able to add totals
for every row and coloum (like this):

1    0    3    4      t : 8

2    7    9    0      t : 18

4    6     4    1     t : 15

and the same for every coloumn . < I have been trying to do it for days but it won't happen> this is the code for the spreadsheet :

#include <math.h>
#include <stdio.h>
#define maxrows 20
#define maxcols  30
#define null 0
FILE *file_pointer;
char filename[]="data.text";
main()
{
int n,m,col,row,r,c,l,x,o,j;
float a[maxrows][maxcols],y ;
printf("how many rows do you want ?");
scanf("%d",&m);
printf("how many cols do you want ?");
scanf("%d",&n);
for (row=0;row<m;++row)
for(col=0;col<n;++col)
a[row][col] = 0.0;
for (row=0;row<m;++row)
{
printf(" \n \n");
for(col=0;col<n;++col)
printf("  %f  ",a[row][col]);
}
x=1 ;
while (x!=2)
{
printf("\n\n select the operation:1-add,2-sub,3-multi,4-div,5-quit,6-save,7-load\n\n");
scanf("%d",&l);
if(l<6){
if(l==5)break ;
printf("\n select the row of the cell : \n");
scanf("%d",&r);
printf("\n select the col. of the cell : \n");
scanf("%d",&c);
printf("\n select the amount you want to use : \n");
scanf("%f",&y);
c=c-1;
r=r-1;
if(l==1)
{
a[r][c]=y+a[r][c] ;
}
if(l==2){
a[r][c]=a[r][c]-y; }
if(l==3)
{a[r][c]=a[r][c]*y;}
if(l==4)
{a[r][c]=a[r][c]/y;}
}
else{
if(l==6){
file_pointer = fopen("data.text","w");
for( row=0; row< m; row++)
for( col=0; col< n; col++)
fprintf(file_pointer,"%f ", a[row][col]);
fclose(file_pointer);
}
if(l==7)
{
file_pointer=fopen("data.text","r");
for( row=0; row<m ; row++)
 for( col=0; col< n; col++)
fscanf(file_pointer,"%f", &a[row][col]);
fclose( file_pointer);
}
}
for (row=0;row<m;++row)
{
printf(" \n \n");
for(col=0;col<n;++col)
printf("  %f ",a[row][col]);
}
}
return 0 ;
}
0
Comment
Question by:habibi
2 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 200 total points
Comment Utility
Just before you print out the array...

for(row=0;row<m;++row) {
  a[row][n] = 0.0;
  for(col=0;col<n;++col) {
    a[row][n] += a[row][col];
  }
}
for(col=0;col<n;++col) {
  a[m][col] = 0.0;
  for(row=0;row<m;++row) {
    a[m][col] += a[row][col];
  }
}

And change the print loop to be for (row=0;row<=m;++row) etc so that you print the total row/cols as well

You don't say if the total row/cols need to be read/written .. that's up to you.

0
 

Author Comment

by:habibi
Comment Utility
Thank you very very much .
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now