Like Tree1Likes
  • 1 Post By Salem

Basic problem using for loops w/ functions. help :(

This is a discussion on Basic problem using for loops w/ functions. help :( within the C Programming forums, part of the General Programming Boards category; Would someone help me with this word problem? Write a function that will accept three integers as parameters, call these ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    4

    Basic problem using for loops w/ functions. help :(

    Would someone help me with this word problem?

    Write a function that will accept three integers as parameters, call these three integers as start , end and step respectively.


    -assume that start is always less than end and step is a positive integer greater than zero.


    -thereafter, the function should print the numbers such that the first item is start, the second item is equivalent to the first item plus the value of step, the third item is equivalent to second item plus the value of step and so on. the last value to be printed should not be greater than end.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    GReaper likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    can you help me with this ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,975
    Probably. You should make an attempt first though, and that is what Salem is getting at.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    Code:
    #include<stdio.h> void notepad(int,int,int); void main() { int a,b,c; notepad(a,b,c); } void notepad(int a,int b, int c) { int start,end,step; printf("Enter the 1st Number :"); scanf("%d",&start); printf("Enter the 2st Number :"); scanf("%d",&end); printf("Enter the 3st Number :"); scanf("%d",&step); for(start=start;start<end;++start) printf("%d\n",start); }
    is this correct? im still newbie for C

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    Well the first step would be for you to show that you can either
    - call a function with parameters, but can't do the loop
    - can do the loop in main, but somehow cannot call a function
    - can do a loop, but only if step is 1

    Now, where exactly are you stuck?

    Edit:
    Try start += step
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2012
    Posts
    4
    where i would put "start+=step" ? sorry.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    Where in the code you have at the moment do you see start being modified?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Why do you pass a, b, and c to your function? They aren't used or modified.

    Don't use void main: SourceForge.net: Void main - cpwiki

    > where i would put "start+=step" ?
    You're making me think you didn't write the above code. Just think about it. In the loop, instead of incrementing by 1 every time, increment by step.

    Code:
    for(start=start;start<end;++start)
    You don't need "start=start;".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C functions using loops
    By Noobpoint in forum C Programming
    Replies: 19
    Last Post: 02-13-2012, 09:31 PM
  2. Problem with nested loops in functions
    By countchocula in forum C Programming
    Replies: 5
    Last Post: 04-21-2008, 03:10 PM
  3. Loops in functions?
    By AmbliKai in forum C Programming
    Replies: 16
    Last Post: 11-29-2007, 05:33 AM
  4. Functions and loops assignment problem
    By JFonseka in forum C Programming
    Replies: 2
    Last Post: 08-07-2007, 03:21 AM
  5. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 02:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21