Like Tree1Likes
  • 1 Post By Salem

2 programs for programming !

This is a discussion on 2 programs for programming ! within the C++ Programming forums, part of the General Programming Boards category; Hi friends , I have 2 programs ... and i want u to help me on solving them ! ready? ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    5,871
    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%.

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,490
    Quote Originally Posted by Seniorija View Post
    I solved one of them but not completely ...
    So.. show us the incomplete solution.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,266
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,641
    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 05:38 AM.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    > 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.
    Seniorija 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-11-2011, 03: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, 06:03 AM
  4. Replies: 13
    Last Post: 01-13-2008, 08:38 PM
  5. Programs opening programs
    By LinuxPLC in forum C Programming
    Replies: 1
    Last Post: 11-21-2002, 11:50 AM

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