Like Tree1Likes
  • 1 Post By sunnypalsingh

please help me with this questions

This is a discussion on please help me with this questions within the C++ Programming forums, part of the General Programming Boards category; first one is: "Write a program that inputs one five-digit number, separates the number into its individual digit and prints ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    please help me with this questions

    first one is:
    "Write a program that inputs one five-digit number, separates the number into its individual digit and prints the digits separated from one another by three spaces each.[Hint: Use combinations of integer division and the remainder operation.]"

    my code is like this:

    Code:
    #include <stdio.h>
     
    int main()
    {
     int num;
     
     printf("Enter a five-digit number:");
     scanf("%d",&num);
     
     printf("%d num/100000\n");
     num=num%100000;
     printf("%d num/10000\n");
     num=num%10000;
     printf("%d num/1000\n");
     num=num%1000;
     printf("%d num/100\n");
     num=num%100;
     printf("%d num/10\n");
     num=num%10;
     
      return 0;
    }
    but it does no work. what is the mistake please help.

    and here is the secound one, this one i could not do. by the way its my first yeat of C++.



    "Given a set of coded information about a student, write a program that prints this information on a single line. For example,
    A male student, at age 17, from Black Sea region, has fair performance with a GPA of 2.58"

    Coded information is as follows:
    Sex: 1:male, 2:female
    Home region: 1:Marmara, 2: Agean, 3:Mediterrenian, 4:Central, :Black Sea, 6:Southeast, 7:East
    Year of birth: 1988
    GPA: 3-4: good, 2-2.99: fair, 1-1.99: poor, 0-0.99:failing

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162

    Post

    Well This should be in C forum not in c++...anyways here is the working code....though its printing in reverse order...make some changes yourself
    Code:
    #include <stdio.h>
     
    int main()
    {
     int num;
     
     printf("Enter a five-digit number:");
     scanf("%d",&num);
     
     while(num>0)
     {
    	 printf("%4d",num%10);
    	 num/=10;
     }
      return 0;
    }
    Last edited by sunnypalsingh; 11-17-2005 at 02:16 AM.
    hula2007 likes this.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Ok we have a C board and a C++ board please stick to the right ones please.
    Woop?

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    3
    Quote Originally Posted by sunnypalsingh
    Well This should be in C forum not in c++...anyways here is the working code....though its printing in reverse order...make some changes yourself
    Code:
    #include <stdio.h>
     
    int main()
    {
     int num;
     
     printf("Enter a five-digit number:");
     scanf("%d",&num);
     
     while(num>0)
     {
    	 printf("%4d",num%10);
    	 num/=10;
     }
      return 0;
    }

    i did like this:

    Code:
    #include <stdio.h>
    
    int main()
    {
    	int num;
    	
    	printf("Enter a five-digit number:");
    	scanf("%d", &num);
    
    	printf("%d", num/10000);
    	printf("   ");
    	num=num%10000;
    	printf("%d", num/1000);
    	printf("   ");
    	num=num%1000;
    	printf("%d", num/100);
    	printf("   ");
    	num=num%100;
    	printf("%d", num/10);
    	printf("   ");
    	num=num%10;
    	printf("%d", num/1);
    	printf("   \n");
    	num=num%1;
    
    
    		return 0;
    }
    and it works well, thanks for your help also.

    what about second one?

    i begun like this

    Code:
    #include <stdio.h>
    
    int main()
    {
    
    	int sex,male,female,homeregion,yearofbirth,gpa;
    
    	printf("Enter sex (1:male, 2:female:");
    	scanf("%d",sex);
    	if(sex==1)
    		printf("male\n");
    	if(sex==2)
    		printf("female\n");
    	
    	printf("Enter home region (1:Marmara,2:Agean,3:Mediterrenian,4:Central,5:Black Sea,6:Southeast,7:East");
    	scanf("%d",homeregion);
    	if(homeregion==1)
    		printf("Marmara\n");	
    	if(homeregion==2)
    		printf("Agean\n");	
    	if(homeregion==3)
    		printf("Mediterrenian\n");	
    	if(homeregion==4)
    		printf("Central\n");	
    	if(homeregion==5)
    		printf("Black Sea\n");	
    	if(homeregion==6)
    		printf("Southeast\n");	
    	if(homeregion==7)
    		printf("East\n");	
    	if(homeregion==1)
    bu i do not how to continue. could someone help guys.

    prog-bman i beg your pardon, i'm new here.


    *modedit nvoigt: fixed [ code ] blocks*

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    It compiles fine as C++ and he mentioned a C++ course so I see no reason why this should be in another board.

    The code is also valid C, but that doesn't make it C only.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Well if that is the case why not just have a C++ board since well almost all C compiles as C++. It's just a waste of a board.
    Woop?

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    3
    guys can you help me with this one?


    Code:
    /* Problem Statement:
    Write a program that reads a nonnegative integer and computes and prints its factorial.
    
    */
    
    #include <stdio.h>
    
    int main()
    {
    
    	int num=0,numb;
    	unsigned factorial=1;
    	
    	printf("Enter a nonnegative integer:");
    	scanf("%d",numb);
    	
    	while(numb<0);
    	numb=-1;
    
    	while(num++<numb){
    		factorial*=num==0?1:num;
    	}
    
    	printf("this numb !%d is factorial",numb);
    
    		return 0;
    }
    its not work. help please

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    > while(numb<0);
    Loops forever.
    Hint - always use braces, even for trivial one-liner statements like you just attempted.

    > factorial*=num==0?1:num;
    Simplify into something more readable
    Code:
    if ( num > 0 ) factorial = factorial * num;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

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