the program should include "c" language not "c++'

Discussion in 'C++' started by i_s_a_a_c, Oct 23, 2011.

  1. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    I want to write a program in c that will get real values for the length of three sides of a triangle in ascending order and determine the nature of it.



    ANOTHE PROGRAM:
    I whant to WRITE A PROGRAM to print the ASCII table from 0x20 (spaces) to 0x7f (DEL) which is an unprintable character


    ANOTHER PROGRAM:
    i want to erite a program to test the knowlege of a child in single-digit multiplication. the program must initially promot the child the number of exercise he\she desires to do. each exercise displays the questions in form a*b=? where a and b are single-gigits numbers (0-9) chosen randomly using the functions srand() and rand(). for each answer the program displays "true" or "false" . upon termination the program displays the test score.



    PLZ HELPE ME AND THANK YOU:):):)
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Easy enough. How far have you got and where are you stuck?

    The second one is particularly easy - can be done in just 2 lines of code, however you need to decide how you want to represent an unprintable character. Any thoughts on that? Do you know about the isprint() function?

    Third one a bit more tricky but again not that hard. Where are you stuck?
     
  3. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    man i am new to this & i was not abel to know from were i could start so plz help me:):)
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Best bet is to go on a programming course, or get tuition off someone you know. It's not easy to teach C in a forum like this. Failing both of those, you could try reading a C book; there is lots of choice.
     
    i_s_a_a_c likes this.
  5. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    but can u plz tell me how to solve these three programs :):)
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    No. Programming is all about doing stuff yourself. Go and learn the language, and you'll be surprised how soon you can in fact do these three tasks (within a month, if you work hard).
     
    i_s_a_a_c likes this.
  7. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    i know what u mean but i have these as a homework for next week & i spent houres & i made many research and i was not abel to solve it:(:( so plz help me cz its graded
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, so how far did you get, and where did you get stuck? If you've spent hours on them you must have *something* to show for it. Even if you didn't get the code working properly, you must have something we can start with.
     
    i_s_a_a_c likes this.
  9. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    in the 1st one i know how tocontinue but i just don't know how to make the programe take the values in ascending order
    the second one i have solvet by using only printF
    and the 3rd i didn't know how to start cz i did not know how to make the program shoose 5 random questiond
     
  10. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    >> in the 1st one i know how tocontinue but i just don't know how to make the programe take the values in ascending order

    Given the problem description I don't think you need to: just input the numbers in increasing order, for example
    Enter length 1: 5
    Enter length 2: 7
    Enter length 3: 9

    But if you need to be able to handle non-increasing order, e.g.
    Enter length 1: 9
    Enter length 2: 5
    Enter length 3: 7

    you could swap them around with comparisons. A three-way swap is not difficult to figure out. If a>b then the largest is whichever is larger of a and c, and the smallest is whichever is the smaller of b and c. The middle value is the one that's left.

    >> the second one i have solvet by using only printF

    Great, well done! See, it's not that difficult when you start working on it, the trick is not to be overawed by the amount of work placed in front of you, just break it down and take it one step at a time.

    >> and the 3rd i didn't know how to start cz i did not know how to make the program shoose 5 random questiond

    Easiest way is to figure out how to make the program choose one random question, then to put that in a (for i=0; i<5; i++) loop. But the question itself tells you a lot:

    - the program must initially promot the child the number of exercise he\she desires to do

    I guess here "promot" means something like ask. So that means using cin or scanf as you've been shown. Store that value somewhere and use it in a loop's terminating expression.

    - each exercise displays the questions in form a*b=? where a and b are single-gigits numbers (0-9) chosen randomly using the functions srand() and rand()

    I don't know what a gigit is, digit perhaps? Anyway, do you know how to get a number from 0-9 using srand() and rand()? You're unlikely to be asked this without any background, so check through your course notes and you should find it with some examples, and you may even be lucky enough to have an example that shows how to get a single-digit random number. Do that twice and store the results into variables named a and b.

    - for each answer the program displays "true" or "false"

    OK so that means you need to get the answer from the user, and calculate the answer yourself, and compare the two results. You already know how to get input, and you should be able to figure out how to calculate the answer, so get both of those into separate variables and use the == operator, and display "true" or "false" accordingly.

    - upon termination the program displays the test score.

    This means you'll need some way of counting the number of correct answers. So you could think up a new variable name, initialise it to zero at the start of the program, then increment it each time you print "true".
     
    i_s_a_a_c likes this.
  11. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    code the function Factorial:
    unsigned long long Factorial (unsigned char N)
    that computes the expression :
    N!=1*2*3*4*5*6........*N
    test the function of values of N betw 0 and 20 (inclusive). indicate why the function would not properly compute anything beyond 20!. In this context justify, the return type of the function (unsigned long long)
    plz hep me :):)
     
  12. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    code the function SumNN:
    unsigned int SumNN(unsigned char N)
    that compute the expression:


    ∑(from i=0 to N) of i^2=1+2^2+3^2+.......+N^2


    justify why N is limited to unsigned char and the return valy is of type unsigned int. Note that the summation is also given by the formula :

    ∑(from i=o to N) of i^2= (N(N+1)(2N+1))/6

    you may use it to confirm your result.
     
  13. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    for the function SumNN i did this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    void main (void)
    
    { 
    	unsigned char N;
    	char ch;
        void SuNN(unsigned char N);
    	while (1)
    	{
    	     printf("Enter N:  ");
    	     scanf(" %c", &N);
    	     SuNN(N);
    	     printf("\n Would you like to try again Y/N? ");
    	     scanf(" %c", &ch);
    	     ch = toupper(ch);
    	     if(ch == 'N') break;
         }
    }
    void SuNN(unsigned char N)
    {   
    	int i;
    	int p=1;
    	for (p<N;i=p*p;p++);
    	{
    		printf ("I*I=%d",i);
    
    	}
    }
    
    but it did not work so plz help me :):):):):)
     
    Last edited by a moderator: Nov 30, 2011
  14. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    >> it did not work

    How exactly?
     
  15. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    it did not give me anythig it only display " would you like to continue Y/N"
    :(:(
     
  16. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Didn't it even display "Enter N:"? If it did, what input did you give it?
     
  17. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    WELL it didn't display "Enter N:" it just displayed "would you like to continue Y/N"
     
  18. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Once, or lots of times?
     
  19. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    lots of times...
     
  20. i_s_a_a_c

    i_s_a_a_c New Member

    Joined:
    Oct 23, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    sorry i re start the function it gave me enter N and when i enter any number it give me that I*I=0
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice