CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

1-dimensional array type double.....and....2-dimensional array topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 12-01-2007, 11:47 PM
Junior Member
 
Join Date: Dec 2007
Location: Illinois
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
styles8687 is on a distinguished road
Send a message via AIM to styles8687 Send a message via Yahoo to styles8687
| More
Unhappy 1-dimensional array type double.....and....2-dimensional array

ok i have to write two 1-dimensional arrays and one 2-dimensional array, but i was out of town so i have no idea of what im doin. any help i can get with explaining it would be greatly appreciated.

1-dimensional:
write an interactive C++program that asks the user to enter the total rainfall for each of 12 months into a one dimensional array of type double. The program then calculates and displays the total rainfall for the year and the months with the highest and lowest amount. do not accept negative numbers for monthly rainfall...use a loop. if any1 is able 2 explain this 2 me that would b awesome.


2-dimensional:
program should....declare and initialize an array called values, print resultant array, determine and print sum of each row, determine and print sum of each column, determine and print sum of each diagonal. must use loop to accomplish this.
Reply With Quote
  #2  
Old 07-25-2008, 05:07 AM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: 1-dimensional array type double.....and....2-dimensional array

How far have you got? Where are you stuck?
Reply With Quote
  #3  
Old 01-01-2009, 04:30 AM
Member
 
Join Date: Dec 2008
Posts: 48
Thanks: 0
Thanked 1 Time in 1 Post
hkp819 is on a distinguished road
| More
Re: 1-dimensional array type double.....and....2-dimensional array

This program takes in the number of rows (n) and columns (m) as well as the elements as a screen input in a matrix n x m.
It then calculates the sum of each row and each column and outputs it using the 'cout' command.
Also, if it is a square matrix, it calculates the sum of diagonal elements and prints it out.

I do not understand clearly your question if you tell for diagonal sum of matrix(2-dimensional array) than program is below....
In this program user enter the row and columns and value of matrix
Than output is sum of diagonal elements.
Code:
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
int A[10][10],m,n,x,y,sum=0;
//Create a Matrix A
cout << "Enter number of rows and columns in Matrix A : \n";
cin>>n>>m;
cout << "Enter elements of Matrix A : \n";
for(x=1;x<n+1;++x)
for(y=1;y<m+1;++y)
cin>>A[x][y];
//Find sum of each row
for(x=1;x<n+1;++x)
{
A[x][m+1]=0;
for(y=1;y<m+1;++y)
A[x][m+1]=A[x][m+1]+A[x][y];
}
//Find sum of each column
for(y=1;y<m+1;++y)
{
A[n+1][y]=0;
for(x=1;x<n+1;++x)
A[n+1][y]+=A[x][y];
}
cout << "\nMatrix A, Row Sum (Last Column)" << " and Column Sum (Last Row) : \n";
for(x=1;x<n+1;++x)
{
for(y=1;y<m+2;++y)
cout << A[x][y] << "     ";
cout << "\n";
}
//Print sum of each column
x=n+1;
for(y=1;y<m+1;++y)
cout << A[x][y] << "     ";
cout << "\n";
if(m==n)
{
for(x=1;x<m+1;x++)
for(y=1;y<n+1;y++)
if(x==y)
sum+=A[x][y];
else
if(y==m-(x+1))
sum+=A[x][y];
}
cout << "Sum of diagonal elements is : " << sum << endl;
getch();
return 0;
}

Input by the user:

3 3
9 8 7 6 5 4 3 2 1

output of that input

Matrix A, Row Sum(Last Column) and Column Sum(Last Row) :
9 8 7 24
6 5 4 15
3 2 1 6
18 15 12
Sum of diagonal elements is : 15

Last edited by shabbir; 01-01-2009 at 09:17 AM. Reason: Code Block
Reply With Quote
Reply

Thread Tools
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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
initializing a multi-dimensional array John C++ Programming 8 11-20-2011 02:52 AM
C char array help! Dylan C Programming 1 07-31-2008 04:45 PM
Reset array coderzone C# Programming 1 03-11-2008 11:25 PM
Help with parallel array psppb C++ Programming 3 12-31-2007 07:14 AM
Gosh ! 2D int array trapeze C++ Programming 2 11-16-2007 05:47 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:11 AM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board