Program that will create 2 one-dimensional arrays then performs multiplication of integers entered into the array .sum of all integers in Array 1, Array 2 and the sum of all products
sample:
#include<stdio.h>
#include<conio.h>
main()
{
int arra[5], arrb[5], i, y=3,sum[5];
clrscr();
gotoxy (5,2); printf("Array A");
for(i=0; i<=4; i++)
{
gotoxy(8, y);scanf("%d", &arra[i]);
y++;
}
y=y-5;
gotoxy (20,2); printf("Array B");
for(i=0; i<=4; i++)
{
gotoxy(30, y);scanf("%d", &arrb[i]);
y++;
}
for(i=0; i<=4; i++)
{
sum[i]=arra[i]+arrb[i];
}
gotoxy (60,2); printf("Sum");
y=y-5;
for(i=0; i<=4; i++)
{
gotoxy(60, y);printf("%d", sum[i]);
y++;
}
getch();
}
#include<stdio.h>
int sum(int arr[], int size){
int s = 0;
for(int i = 0; i < size; i++){
s += arr[i];
}
return s;
}
int product(int arr[], int arr2[], int size){
int p = 0;
for(int i = 0; i < size; i++){
p += (arr[i] * arr2[i]);
}
return p;
}
main()
{
int arra[5], arrb[5], i;
printf("Array A\n");
for(i=0; i<=4; i++)
{
scanf("%d", &arra[i]);
}
printf("Array B\n");
for(i=0; i<=4; i++)
{
scanf("%d", &arrb[i]);
}
printf("Sum of array A: %d\n", sum(arra, 5));
printf("Sum of array B: %d\n", sum(arrb, 5));
printf("Product of array A and array B: %d\n", product(arra, arrb, 5));
return 0;
}
Comments
Leave a comment