Thread: 2 programs for programming !

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    10

    2 programs for programming !

    Hi friends , I have 2 programs ... and i want u to help me on solving them !
    ready?

    1. Write a c++ (or c) program that input 3 numbers and print the type of a Triangle ! (of course if the triangle can be made ! Otherwise print it can not be a Triangle )

    and 2. write a program that input a number , if it's a Multiple of 4 print (1/4) that number ... otherwise print (2^n) (n is inputed number) (Without using of if,:?,*,%,/)!!

    am waiting for ur answers ... TNX !!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    And we're waiting for you to show some effort.

    You can't just dump your assignment and leave it at that.

    For the first, study some geometry -> Triangle - Wikipedia, the free encyclopedia
    For the second, lookup the bitwise operators << >> & |
    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.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You might also want to have a look at this site's homework policy, at this link. That will make the reasons for Salem's response abundantly clear.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    10
    Salem .... excuse me !!
    In fact i want u to help me ... !!! Not just solving them !! and i know what a triangle is !!!!!

    I solved one of them but not completely ... and i want u Guide me !!!

    at all , I apologoize u if i annoy anyone !!

    Regards;
    Seniorija

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Seniorija View Post
    I solved one of them but not completely ...
    So.. show us the incomplete solution.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Think of us as a pinball machine. We're those little bumper things that give the ball a shove when the ball touches them, to try and get the more points, make things more interesting, and keep the ball away from the hole at the bottom. The problem here is that you haven't pulled the plunger to fire the ball into play (i.e. haven't posted your attempt), so we have nothing to do yet.

    We're still waiting for you... not the other way around.
    Post your attempt and then ask a specific question about it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    iMalc, you may be dating yourself with a pinball machine reference

  8. #8
    Registered User
    Join Date
    Oct 2012
    Posts
    10
    Thank u for ur all warnings ! So ... for question 1 : i have used "if" ... actually i know that its better to use if , but i dont exactly know what i shoud do ... !!!! the following is my solution (incomplete solution!!):
    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main(){
        float a,b,c;
        cout << "Enter 3 Numbers:" << endl;
        cin >> a >> b >> c;
    
        if (a+b<=c)
        cout << "WoW! It can not be a Triangle" << endl;
        if (a+c<=b)
        cout << "WoW! It can not be a Triangle" << endl;
        if (b+c<=a)
        cout << "0WoW! It can not be a Triangle" << endl;
           
        if (a==b==c)
        cout << "Type of Triangle is equalateral triangle" << endl;
        
        if (a*a==b*b+c*c)
        cout << "Type of Triangle is right triangle" << endl;
        if (b*b==a*a+c*c)
        cout << "Type of Triangle is right triangle" << endl;
        if (c*c==a*a+b*b)
        cout << "Type of Triangle is right triangle" << endl;
    
        if (a==b)
        cout << "Type of Triangle is Isosceles Triangle" << endl;
        if (a==c)
        cout << "Type of Triangle is Isosceles Triangle" << endl;
        if (b==c)
        cout << "Type of Triangle is Isosceles Triangle" << endl;
        getch();
        return 0;
    }
    in this code i want check 3 conditions (if) and after print 1 message (to specify the type of triangle ) ... !! i think its better that i write my code compact !! , dont it ?... do u know what i mean ?!!!
    and next ,when i enter 3 equal numbers , it prints "The type of triangle is Isosceles Triangle" 3 times and also it doesnt print equlateral triangle !!!! why ?!!

    and for question 2 :
    would u plz give me an idea to start ?!!!!!!!
    Last edited by Seniorija; 11-04-2012 at 06:38 AM.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > and next ,when i enter 3 equal numbers , it prints "The type of triangle is Isosceles Triangle"
    Because equilateral is just a special case of isosceles.

    Your conditions should be
    Code:
    if ( ... ) {
    } else if ( ... ) {
    } else if ( .... ) {
    } else {
    }
    If you just have separate if statements, you hit all the ones which are true.
    If you have if / else if chain, then you only get the first one to match true.

    > if (a==b==c)
    Try
    if ( a == b && b == c )

    > and for question 2 :
    > would u plz give me an idea to start
    I already have.
    But since you need more help, I suggest you write a function to do something like
    printBinary(int a);
    where if you provide a parameter, say 42, it prints the string "101010"
    When you've done that, use it to print (in binary)
    - numbers which are multiples of 4
    - numbers which are powers of 2
    When you've seen the pattern, you might be able to figure out how to use the bitwise operators I mentioned.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  2. Digits pyramid printing programs needed in C Programming
    By technoexam in forum C Programming
    Replies: 8
    Last Post: 10-01-2011, 04:58 PM
  3. Replies: 1
    Last Post: 11-09-2009, 07:03 AM
  4. Replies: 13
    Last Post: 01-13-2008, 09:38 PM
  5. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 12:50 PM