Answer to Question #275885 in C for tamahome

Question #275885

Create a program that will ask the user to input 9 integer numbers and display its vertical and horizontal sum. The numbers should be encoded in a 3 rows and 3 columns manner. After the user entered each set of numbers in a row, the horizontal sum of the set of numbers should automatically be shown.



1
Expert's answer
2021-12-05T11:22:22-0500
#include <stdio.h>


// Driver code
int main() {
	int i,sumRow=0;
	int sumColumn1=0;
	int sumColumn2=0;
	int sumColumn3=0;
	int numbers[9];


	for(i=0;i<9;i++){
		printf("Enter number %d: ",(i+1));
		scanf("%d",&numbers[i]);	
	}
	printf("\n");
	for(i=1;i<=9;i++){
		if(i%3==0){
			sumRow+=numbers[i-1];
			printf("%d, sum = %d\n",numbers[i-1],sumRow);
			sumRow=0;
		}else{
			sumRow+=numbers[i-1];
			printf("%d\t",numbers[i-1]);
		}
	}
	sumColumn1=numbers[0]+numbers[3]+numbers[6];
	sumColumn2=numbers[1]+numbers[4]+numbers[7];
	sumColumn3=numbers[2]+numbers[5]+numbers[8];
	printf("---------------------\n");
	printf("%d\t%d\t%d\n\n",sumColumn1,sumColumn2,sumColumn3);
	getchar();
	getchar();
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS