scanf

This is a discussion on scanf within the C Programming forums, part of the General Programming Boards category; how do i use scanf to read in one number and set it to two different variables?...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19

    scanf

    how do i use scanf to read in one number and set it to two different variables?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    You use it to read into one variable, then copy the value of that variable over to the other variable.
    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

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Is this what you mean?
    Code:
    scanf("%d",&i);
    j=k=i;
    If not, give an example.
    Last edited by BEN10; 11-22-2009 at 07:34 AM.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19
    thats exactly what i mean. thank you very much.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Location
    Ireland
    Posts
    19
    Code:
    #include <stdio.h>
    
    void main()
    {
    	int maxfactorial=0, minfactorial=0, line=0, factorial=0, i=0;
    	
    	printf("enter max factorial\n");
    	scanf("%d", &i);
    	printf("enter min factorial\n");
    	scanf("%d", &minfactorial);	
    	printf("--------------------------------------------------------------------");
    	while (line<=0){
    	printf("\nFactorial Value        Factorial expression            Result");
    	line=line+1;
    	}
    	maxfactorial=i;
    	factorial=i;
    	while ( factorial>0){
    	printf("\n%d" ,maxfactorial);
    	maxfactorial=maxfactorial-1;
    	factorial=factorial-1;
    	}
    
    
    }
    i have made this to create part of a factorial table but i cant get it to only print the max factorial till it reaches the value entered for the minimum factorial. how would i go about that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. scanf issue
    By fkheng in forum C Programming
    Replies: 6
    Last Post: 06-20-2003, 08:28 AM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 07:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 05:34 AM

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