🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4761

Re: HELP!! Beginner's question...

#4761
From: Roger Wells
Date: Mon, 05 Feb 1996 23:14
67 lines
2395 bytes
In article <DM5LC6.M2n@uis.com>, scottm@uis.com (Scott Miller) writes:
>
>I compiled your program and ran it on our HP 700 series Unix machine,
>entered 5 as the non-negative integer and 7 as the power, and got 78,125.
>The program appears to be correct.
>
>This could be a system dependant problem -- different systems may use
>different sizes for int and long int.

>Your instructor's advice to use long int sounds wise --
>try it if you haven't already.
>
>				Scott Miller
>
>
>>------------------------------------------------------------------------
>
>>#include <stdio.h>
>>                  
>>int main(void)
>>{
>>   int i,         /* integer */
>>       n,         /* power to raise integer */
>>       i_total,   /* integer's total value*/
>>       count;     /* keeps track of number of loops run */
>
>>   /* asks for an integer and stores it in 'i' */
>>   printf("Enter a non-negative integer: ");
>>   scanf("%d", &i); 
>
>>   /* asks for a power and stores it in 'n' */
>>   printf("What power should we raise it to? ");
>>   scanf("%d", &n);
>
>>   /* if 'n' is negative, program will treat it as a '0' */	
>>   if (n < 0){
>>       n = 0;
>>   }            
>>                    
>>    i_total = 1;       /* gives i_total an initial total of '1' */
>
>>    for (count = 1;  count <= n;  count = count + 1){
>>        i_total = i_total * i;
>>    }
>
>>    /* prints out the inputs and result */
>>    printf("%d raised to the %dth power is %d\n\n", i, n, i_total); 
>
>>    return(0);	
>>}

If (as I understand) he's changed i_total to type long and it still has
this problem, you also have to change the format to %ld (for long int):

given:
   int i;
   int n;
   long i_total;


   printf("%d raised to the %dth power is %ld\n\n", i, n, i_total);

(I normally don't do homework problems; however, I suspect I'm saying
exactly what the instructor would say.)

--
Roger Wells  (speaking only for myself)
Technical Details
Message-ID: <4f6319$mev@news1.halcyon.com>
Path: arc1-ca.pugleaf.net!usin.com!rwells
References: <Pine.OSF.3.91l.960131005708.7552A-100000@saul3.u.washington.edu> <DM5LC6.M2n@uis.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!usin.com!rwells
From: rwells@usin.com (Roger Wells)
Newsgroups: comp.std.c
Subject: Re: HELP!! Beginner's question...
Date: 5 Feb 1996 23:14:49 GMT
Organization: U.S. Intelco Networks, Inc.
Distribution: world
Message-ID: <4f6319$mev@news1.halcyon.com>
References: <Pine.OSF.3.91l.960131005708.7552A-100000@saul3.u.washington.edu> <DM5LC6.M2n@uis.com>
NNTP-Posting-Host: 198.202.216.7