Solved

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

Posted on 1998-04-13
2
163 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

726 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