정수 요소의 배열이 주어지고 작업은 배열의 요소를 곱하여 표시하는 것입니다.
예시
Input-: arr[]={1,2,3,4,5,6,7}
Output-: 1 x 2 x 3 x 4 x 5 x 6 x 7 = 5040
Input-: arr[]={3, 4,6, 2, 7, 8, 4}
Output-: 3 x 4 x 6 x 2 x 7 x 8 x 4 = 32256 아래 프로그램에서 사용된 접근 방식은 다음과 같습니다. -
- 최종 결과를 1로 저장하기 위해 임시 변수 초기화
- 0에서 n까지 루프를 시작합니다. 여기서 n은 배열의 크기입니다.
- 최종 결과를 위해 temp 값에 arr[i]를 계속 곱하세요.
- 결과 값이 될 temp 값 표시
아래는 입력을 곱하고 필요한 출력을 생성하는 예입니다.

알고리즘
Start
Step 1-> Declare function for multiplication of array elements
int multiply(int arr[], int len)
set int i,temp=1
Loop For i=0 and i<len and i++
Set temp=temp*arr[i]
End
return temp
step 2-> In main()
Declare int arr[]={1,2,3,4,5,6,7}
Set int len=sizeof(arr)/sizeof(arr[0])
Set int value = multiply(arr,len)
Print value
Stop 예시
#include<stdio.h>
//function for multiplication
int multiply(int arr[], int len) {
int i,temp=1;
for(i=0;i<len;i++) {
temp=temp*arr[i];
}
return temp;
}
int main() {
int arr[]={1,2,3,4,5,6,7};
int len=sizeof(arr)/sizeof(arr[0]);
int value = multiply(arr,len);
printf("value of array elements after multiplication : %d",value);
return 0;
} 출력
위의 코드를 실행하면 다음 출력이 생성됩니다.
value of array elements after multiplication : 5040