?
Solved

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

Posted on 1998-04-13
2
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 800 total points
ID: 1258123
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
ID: 1258124
Thank you very very much .
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

765 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