Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

This should be easy

I know this should be easy, but i cant get them to work...
1. A program that counts from 3 to 5 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.

/* Result of execution
3 .33333
4 .25000
5 .20000
*/

2. A program that counts from 459 to 450, prints three numbers on a separate line, and includes a message like below when the line has an even multiple of 5 and a different message when the count is 455. This program must employ a loop of your choice to print these lines.

/* Results of execution
The numbers are now 459 458 457.
The numbers are now 456 455 454 with an even multiple of 5.
The numbers are now 453 452 451.
The number is now 450 with an even multiple of 5.
*/


got any ideas?

Comments

  • zetffzetff Member Posts: 1
    1. There are two ways
    a) use a float

    float i ;

    for(i=3 ; i<6 ; i++)
    printf("%.0f %.5f
    ", i, 1/i) ;

    b) use a float and an int

    int i ;
    float f ;

    for(i=3 ; i<6 ; i++)
    {
    f = (float) 1/i ;
    printf("%d %.5f
    ", i, f) ;
    }

    About the floating numbers, is that not a typo ? I can't seem to get it to print floating numbers with a zero before the floating point.

    2. Don't really get the question.
  • Shawn CarterShawn Carter Member Posts: 0

    _____ < http://forcoder.org /> free ebooks and video tutorials about ( Perl, Swift, Python, Visual Basic .NET, Assembly, Ruby, PL/SQL, Objective-C, Scratch, C, R, PHP, C#, MATLAB, Go, Delphi, C++, Java, Visual Basic, JavaScript LabVIEW, Scheme, Fortran, Hack, Bash, ML, Scala, Julia, Rust, Alice, Lua, Kotlin, Awk, VBScript, Prolog, Dart, Transact-SQL, Apex, F#, D, FoxPro, Logo, COBOL, Clojure, Crystal, SAS, Lisp, Ada, ABAP, Erlang ) _____________

Sign In or Register to comment.