473,508 Members | 2,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find the product of all elements of an array modulo 10^9+7 ?

56 New Member
I have written below code ,for the problem stated on below link under topic Array multiplication , I am unable to get the insight of why is the code not working for any test case ?

https://www.hackerearth.com/practice/math/number-theory/modulus-arithmetic/tutorial/


Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include<inttypes.h>
  3. #include<stdint.h>
  4. #include<math.h>
  5.  
  6. int main()
  7. {
  8. uintmax_t size;
  9. uintmax_t product=1;
  10. scanf(" %ju",&size);
  11. uintmax_t i;
  12. if(size<=10000 && size>=1)
  13. {
  14.  
  15. uintmax_t array[size];;
  16. for(i=0;i<size;i++)
  17. {
  18.  
  19. scanf(" %ju",&array[i]);
  20. product=product*array[i];
  21.  
  22. }
  23.  
  24. uintmax_t a=pow(10,9);
  25. uintmax_t b=a+7;
  26. uintmax_t c=product % b;
  27. printf("%ju",c);
  28. }
  29.  
  30.   return 0;
  31. }
  32.  
Sep 4 '16 #1
1 2899
weaknessforcats
9,208 Recognized Expert Moderator Expert
It might be right here:

Expand|Select|Wrap|Line Numbers
  1. uintmax_t array[size];;
At the time this line of code is executed, size has not been initialized so you get whatever value is in the variable.

Also, static arrays like this need t know the size before the array can be created.

I suggest:

unitnmax_t* array = 0;

scanf your size

array = malloc(size * sizeof(unitmax_t));

then initialize the array elements

then plug in your element values
Sep 4 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
10257
by: Jack Fu | last post by:
I am trying to install Visual Studio .net Enterprise Architect 2003. This is the full version, not academic. At an early point in the installation it asks me for the product ID. However, there is not...
2
1556
by: Shalini | last post by:
Hi , Is the code below efficient?? bool *isElement(char **a1,long lengtha1,char **a2,long lengtha2){ charQuickSort(a2, 0, (lengtha2-1)); bool *tag=(bool*)calloc(lengtha1,sizeof(bool)); int...
2
6582
by: thomasamillergoogle | last post by:
Hi, As you can see from the code below I have a simple js function called getFormElementsinTableRow(rowName). rowName is the ID of the tableRow. I just want to use js to find the child ID's of all...
1
6775
by: SB | last post by:
I have a struct with a fixed array of items (see below). How can I obtain the physical address of the array? I don't need to do anything with it other than display it to the end user (this is a...
3
5673
by: shyam | last post by:
Hello to all C geeks My query is as follows i declare a variable in main as UINT8 *c if i check for sizeof(c) it returns 20, i.e 20/4 = 5 elements. This is fine .
1
2329
by: Wondering2 | last post by:
Hi All, For Oracle 9i or Oracle 10g...if someone needed to deinstall and reinstall..where would they find the "license Key"..i.e. if they didn't have the physical media (cd) to install from, could...
4
2057
by: =?Utf-8?B?QXZvY2V0?= | last post by:
I recently bought a new computer and want to install my VB.net 2003, but I cannot seem to find my product key anymore. Yes I have legal version with all CDs and blue box with all the information...
2
4844
by: blaine | last post by:
Hi, I would like to find all elements within my DOM that begin with "test". Any idea on how I would go about this? Example Below I would like to return a list of element id's of test1, test2,...
1
1832
by: Zarwadi | last post by:
Hi i have 2 array's one is like this (123, 123, 123) the other (123, 435, 123, 564, 123, 780, 453, 123) I need to know how to use the first array to find the matching data and it;s postion in...
2
2682
by: luftikus143 | last post by:
Hi there, I have an array, which stores in the first dimension a counter for the number of sets, and in the second the value: $value I found somewhere how to find min and max values in such...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.