-
Notifications
You must be signed in to change notification settings - Fork 0
/
week 8 in c
75 lines (56 loc) · 1.72 KB
/
week 8 in c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<1> Divisibility
You are provided an array A of size N that contains non-negative integers. Your task is to determine whether the number that is formed by selecting the last digit of all the N numbers is divisible by 10.
Note: View the sample explanation section for more clarification.
Input Format
First line: A single integer N denoting the size of array A Second line: N space-separated integers.
Output Format
If the number is divisible by 10, then print Yes. Otherwise, print No.
Sample Input 0
5
85 25 65 21 84
Sample Output 0
No
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(){
int N = 0;
scanf("%d", &N);
long data[N];
for(int i=0; i<N; i++)
scanf("%ld", &data[i]);
if (data[N-1] % 10 == 0)
printf("Yes");
else
printf("No");
return 0;
}
<2> Find product
You have been given an array A of size N consisting of positive integers. You need to find and print the product of all the number in this array.
Input Format
The first line contains a single integer N denoting the size of the array. The next line contains N space separated integers denoting the elements of the array.
Output Format
Print a single integer denoting the product of all the elements of the array
Sample Input 0
5
1 2 3 4 5
Sample Output 0
120
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MOD 1000000007
int main() {
int n;
scanf("%d", &n);
int arr[n];
long long int product = 1; // to avoid integer overflow
for (int i=0; i<n; i++) {
scanf("%d", &arr[i]);
product = (product * arr[i]) % MOD; // taking the product and performing modulo operation at each step
}
printf("%lld", product);
return 0;
}