473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

I cant figure out why my program is crashing. Please Help!!!

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> 
  2. #include <stdlib.h>
  3.  
  4. void separate(int *first, int *second, int *third);
  5.  
  6. int main() { 
  7.  
  8.     int number;
  9.     int A, B, C;    
  10.  
  11.     printf("Enter a positive integer value to be evaluated: ");
  12.     scanf(" %d", &number);
  13.  
  14.     A = number + 0;
  15.     B = number + 0;
  16.     C = number + 0;
  17.  
  18.     printf("\nThe integer value you've chosen is %d\n\n", number);
  19.  
  20.     separate(&A, &B, &C);
  21.  
  22.     printf("The value of A is %d\n\n", A);
  23.     printf("The value of B is %d\n\n", B);
  24.     printf("The value of C is %d\n\n", C);
  25.  
  26.         system("pause");
  27.  
  28.     return 0; 
  29.  
  30.  
  31. void separate(int *first, int *second, int *third) {
  32.  
  33.     int i, j;
  34.     int input, sum = 0, total_sum = 0;
  35.  
  36.     if (*first % 7 == 0 || *first % 11 == 0 || *first % 13 == 0) {
  37.         *first = 1;
  38.     }
  39.     else {
  40.         *first = 0;
  41.     }
  42.  
  43.  
  44.     for (i = *third; i > 1; i--) {
  45.         if (*third % i == 0) {
  46.             *third = 0;
  47.         }
  48.         else *third = 1;
  49.     } 
  50.  
  51. // The problem is somewhere for here on
  52. //Im trying to add the digits of my imputed variable and return them to my main
  53. //function.    
  54.     for (input = *second; input <= 1000; input++) {
  55.         sum = 0;
  56.  
  57.         for (j=0; j<4; j++) {
  58.         sum = sum + (input / (j*10))%(10) ;
  59.         }
  60.  
  61.         total_sum = total_sum + sum;
  62.     }
  63.  
  64.     *second = total_sum;
  65.  
  66. }
Mar 11 '10 #1
1 1310
The problem in your code is ,
Expand|Select|Wrap|Line Numbers
  1. for (input = *second; input <= 1000; input++) {
  2. sum = 0;
  3. for (j=0; j<=4; j++) {
  4. sum = sum + (input / (j*10))%(10) ;
  5. }
  6.  
In the inner for loop j value starts from zero.
And inside the loop you are performing the operation,
sum = sum + (input / (j*10))%(10) ;
If j value is zero j*10 will be (0*10=>0).
So it will give divide by zero error (i.e) floating point exception.

So you start the j value from one .
Mar 11 '10 #2

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

Similar topics

3
by: Daragoth | last post by:
Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that determines the best possible combination of a data set by checking every possible combination. I found there were about 250,000,000...
5
by: johny | last post by:
Program details as follows: Input to the program the exam number and computer arch and programming results for 10 people. Three arrays - ExamNo, Arch and prog are used to hold these items. The...
4
by: vashwath | last post by:
Hi all, I am not able to figure out why the following program fails. Hope this long program does not irritate you. #include <stdlib.h> #include <string.h> #include <stdio.h> #define...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
3
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and...
1
by: dav3 | last post by:
Any help here is appreciated folks. First in my Person class the comments = errors visual basics is giving me and I am not sure why. Also when i try and set up my array of pointers to Student...
1
by: durjoy | last post by:
dunno is the right forum to ask for help , but i cant see any category for html help . dont know any other site as well . this site is my last hope dear experts . i was hosting my site with...
2
by: Hari2349 | last post by:
Regarding to log4j in java program..Plz help me... -------------------------------------------------------------------------------- Hai, friends i used the log4j.properties file like as...
5
by: chevon1920 | last post by:
I am trying to do my assignment but I cant figure out how to get 8 data points per line to print to a file. Here is the assignment 1. Program asks the user to enter an odd number as a BASE,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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,...
0
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...

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.