Solved

array

Posted on 1999-01-08
8
253 Views
Last Modified: 2010-04-15
given an array x[10][10] with initial values, compute the sum of all:-
a)the diadonal elements;
b)the square of the elements in the even rows(i.e., rows 2,4,6,8,10)
c)the square root of the elements in the odd columns(i.e.,columns 1,3,5,7,9).
0
Comment
Question by:samuelccs
[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
8 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255629
#include <math.h>

//assuming x[row][column]
//s is squares, sr is square root, return value is diagonal elements

int calculate(int *x[10][10], int *s, int *sr) {
int i,j,k, sum=0;
*s=0; *sr=0;
for(i=0,j=9;i<10;i++ ,j--){
  sum+=*x[i][i]+*x[i][j];
  for(k=0;k<9;k++) if(i%2)      *s+=*x[i][k]**x[i][k]; else *sr+=sqrt(*x[k][i]);
}
  return(sum-=*x[4][4]);
}
0
 
LVL 1

Expert Comment

by:dpuckett
ID: 1255630
Hey ScrapDog, keep doing this guys homework and you'll have to stay after school :)
0
 
LVL 1

Expert Comment

by:_Canidae_
ID: 1255631
Hehehe, someone obviously hasn't been paying attention during his programming classes.
0
Independent Software Vendors: 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!

 

Accepted Solution

by:
aj1070798 earned 30 total points
ID: 1255632
Class project folks - I set it - beware!
0
 

Expert Comment

by:rsongyl
ID: 1255633
Well you can do this .. it is shorter
Question (A)
printing from top-left to bottom right
for index = 1 to MAX do
    print(numbers[index][index])
end for
printing from bottom-left to top-right
for diag=1 to MAX do
    print(numbers[MAX-diag+1][diag])
enfor

Question (B)
index2=0
for index=1 to MAX
    sum=sum+(numbers[index][index2]*numbers[index][index2])
    index=index+2
    index2++
endfor
   
Question (C)
I think the answer above is quite ok to follow. Most importantly must understand the concept
0
 

Author Comment

by:samuelccs
ID: 1255634
i am sorry, sir. i just want to have more opinion and more alternatives to do one programming work. i'll promise that i will not copy the direct answer
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1255635
samuel, your teacher gotcha right at the place of crime :)

Aren't you gonna accept your teacher's answer now? :))
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1255636
a)the diadonal elements;

int sum = 0;

for (int i = 0; i < 10; i++)
  sum += array[i][i];

b)the square of the elements in the even rows(i.e., rows 2,4,6,8,10)

int sum = 0;

for (int j = 2; j < 10; j += 2) {
  for (int i = 0; i< 10; i++)
    sum += sqr(array[j][i]);
}

c)the square root of the elements in the odd columns(i.e.,columns 1,3,5,7,9).

int sum = 0;

for (int j = 1; j < 10; j += 2) {
  for (int i = 0; i< 10; i++)
    sum += sqrt(array[j][i]);
}

Hope this helps.

-Viktor
--Ivanov
0

Featured Post

Industry Leaders: 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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

689 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