Thread: Help !!!

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    6

    Help !!!

    please could anyone help me with this assigment!!!

    which contains pointers and functions

    BTW----> iam a biginner


    here is the problem:

    Write a complete C program to compute the least common divisor (LCD). The program should reverse and sum the digits of the given integers. Use the following functions with pointers:

    Function Fun_1 to compute the least common divisor
    Function Fun_2 to reverse and sum the digits of the given integer

    Sample Run:

    Enter Your Choice:
    |1 – To Reverse and Sum the Digits
    |2 - To compute LCD
    |3- Exit
    ………………………………….
    1
    Input the given numbers
    Num1: 123
    Num2: 456

    Reverse of Num1: 321
    Sum of Num1 digits: 6

    Reverse of Num2: 654
    Sum of Num2 digits: 15
    --------------------------------------------------------------------------------
    i was able to find some codes, maybe it's usefull

    this one for the sum
    Code:
    #include <stdio.h>
    int main()
    {
    int x,y,
    sum = 0;
    printf("Enter the number \n");
    scanf("%d",&x);
    for (x!=0;y=x%10;x/=10)
    sum =sum+ y;
    {
    printf("The sum is %d\n", sum);
    }
    return 0;
    }
    and this one for the inverse
    Code:
    #include<stdio.h>
    main()
    {
    int num,
    rev=0;
    printf("\n Enter the number\n ");
    scanf("%d", &num);
    while(num>0)
    {
    rev = (rev * 10) + (num % 10);
    num = num / 10;
    }
    printf("\n Reverse of the number is %d", rev);
    return(0);
    }
    thanks...

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Stop finding za codez on za internet, and start writing them yourself. Anything else is just a total waste of time and if it is wasting your time it certainly is wasting ours. So come back when you have your own attempt at the problem, and we will help you move on from there.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    6
    well,,...
    i don't need the whole code,
    what i need is the beginning, so i can continue
    like the prototypes for instants

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by goby View Post
    well,,...
    i don't need the whole code,
    what i need is the beginning, so i can continue
    like the prototypes for instants
    This should get you started:

    Code:
    #include <stdio.h>
    
    int main(void){
       /* CODE GOES IN HERE*/
       return 0;
    }
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    6
    any more help!??..

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by goby View Post
    any more help!??..
    I think you're missing the point.... This isn't a "we do your homework for you" service. You need to show an effort. The volunteers here will help you out if you get stuck, but they're not going to write your code for you.

    Believe me you won't learn a darned thing if you try to scrape through on "borrowed" code. To learn programming you need to write programs of your own creation.

    So... sit down, puzzle it out as far as you can, write some original code...

Popular pages Recent additions subscribe to a feed