Thread: hexadecimal numbers

  1. #31
    Registered User gaurav9991's Avatar
    Join Date
    Oct 2010
    Location
    Pune, Maharashtra, India
    Posts
    69
    if() is NOT a function, it's a statement.

    Code:
    if(expression)
    {
          statement1;
          statement1;
          '
          '
    }
    if(the the expression is true, then it goes into the braces, otherwise it jumps to the closing brace.

    You can have if statement, nested if...else, but NOT only else
    Code:
    if(expression 1)
    {
          statement1;
          statement2;
          '
          '
    }
    else if(expression 2)
    {
          statement1;
          statement2;
          '
          '
    } 
    '
    '
    '
    '
    else
    {
          statement1;
          statement2;
          '
          '
    }

  2. #32
    Registered User
    Join Date
    Oct 2010
    Posts
    21
    oh man!!!!!!!!!!!!!!!!!!!! finally... guys!!!!!! i completed the code.. thanks gaurav, that flag idea of urs saved my butt.... and ur if() STATEMENT is very clear now...


    here's the code

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    void low_up(char *);
    void main()
    {
    	char ch[4];
    	int temp[4],i,hex=0,dec=0;
    	clrscr();
    	printf("Enter a hexadecimal number");
    	for(i=0;i<4;i++)
    	{
    		scanf("%c", &ch[i]);
    	}
    	for(i=0;i<4;i++)
    	{
    		if((ch[i]>='a' && ch[i]<='f')||(ch[i]>='A' && ch[i]<='F'))
    		
    			hex++;
    		else
    		
    			dec++;
    	}
    	if(dec==4)
    
    		printf("This is not a hexadecimal number");
    
    	else
    	{
    		printf("This is a hexadecimal number");
    		low_up(ch);
    	}
    	for(i=0;i<4;i++)
    	printf("%c", ch[i]);
    
    	getch();
    }
    
    void low_up(char *j)
    {
    	int k;
    	for(k=0;k<4;k++)
    	{
    		if(*j>=97 && *j<=102)
    			*j=*j - 32;
    		else if(*j>=65 && *j<=70)
    			*j=*j + 32;
    		j++;
    	}
    
    
    }

  3. #33
    Registered User gaurav9991's Avatar
    Join Date
    Oct 2010
    Location
    Pune, Maharashtra, India
    Posts
    69
    hey STOP

    try for 45sa which is NOT hex no.

    and no need to use two flags hex and dec, you are using only dec then what is use of hex ?
    Code:
    for(i=0;i<4;i++)
    	{
    		if((ch[i]>='a' && ch[i]<='f')||(ch[i]>='A' && ch[i]<='F'))
    		
    			hex++;
    		else
    		
    			dec++;
    	}
    	if(dec==4)
    
    		printf("This is not a hexadecimal number");
    
    	else
    	{
    		printf("This is a hexadecimal number");
    		low_up(ch);
    	}
    these red lines says that if there are all four digits which are NOT part of hex no. system then only the whole no. will be considered as NON hex no. Are you getting ?

    and you haven't considered about decimal numbers (1234)
    Last edited by gaurav9991; 11-24-2010 at 05:07 AM.

  4. #34
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Sonia View Post
    hahahaha i'm sorry i didn know WACP wud coz such confusion...@salem yeah ur ryt it is Write a C Program... hey ppl thanks for the help... i finally did manage to come up with the code but its still generating errors please have a look.
    Mostly I think it's your pigeon english that confusing people. It's so mangled up that it's amost impossible to read... like the crap grade school kids send on text messages. I don't know if English is your first language or not but, in any case, you really should make a sincere attempt at writing legibly...

  5. #35
    Registered User
    Join Date
    Oct 2010
    Posts
    21
    yes i do tend to type like that when i'm in a hurry... but FYI english is my first language and i have no problems whatsoever writing or speaking english fluently... but i didn realise that there are slow(at mind) people here.. so i'm sorry next i will type out my questions properly so that slow people(like you, especially you) can understand well.

    P.S.(stands for Post Script) : FYI stands for "For your information"

  6. #36
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by Sonia View Post
    so i'm sorry next i will type out my questions properly so that slow people(like you, especially you) can understand well.
    Don't bother. You won't be getting anymore help from people with your crappy attitude. You came here for help. You should be making it as easy as possible for people to help you. Instead we spend our time trying to decipher your stupid acronyms that no one's ever used before and your 3rd-grade level spelling.

    I'm done with you.
    If you understand what you're doing, you're not learning anything.

  7. #37
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by itsme86 View Post
    Don't bother. You won't be getting anymore help from people with your crappy attitude. You came here for help. You should be making it as easy as possible for people to help you. Instead we spend our time trying to decipher your stupid acronyms that no one's ever used before and your 3rd-grade level spelling.

    I'm done with you.
    Amen, brother.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #38
    Registered User gaurav9991's Avatar
    Join Date
    Oct 2010
    Location
    Pune, Maharashtra, India
    Posts
    69
    i would like to say something here, no one have problem with your english , the thing is your attitude.
    Lots of people are here who wants to use their intelligence to help others. So I request you, don't disappoint them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  2. Program that prints numbers in columns
    By rayrayj52 in forum C++ Programming
    Replies: 12
    Last Post: 09-20-2004, 02:43 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM