You must Sign In to post a response.
  • Category: Programming

    C program to reverse the given number using function.


    Preparing for MSBTE diploma in Computer engineering exams? Have a query about preparing for C programming subject? check out this page and get program solution for reversing a given number using function.

    Following is a question that was asked in the question paper of Diploma in Computer Engineering (Summer 2019)conducted by MSBTE Mumbai, for subject Programming in C(22226).

    This question is asked for 4 marks and hence requires some explanation along with the program code. Please let me know the solution.

    Q) Write a C program to reverse the number using function. (e.g. if the given number is 1234 then converted number is 4321) [4 Marks]
  • Answers

    1 Answers found.
  • The thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Following is the program to reverse the given number using function. Please include stdio.h and conio.h header files before declaration of main function.

    //PROGRAM TO REVERSE GIVEN NUMBER USING FUNCTION
    #include
    #include
    void main()
    {
    long int revnum(long int);
    long int num,res;
    clrscr();
    printf("Enter the number\n");
    scanf("%ld",&num);
    res=revnum(num);
    printf("\n%ld is original number an %ld is reverse of the given number",num,res);\
    getch();
    }
    long int revnum(long int n)
    {
    long int m=n,s=0,i,c=0;
    while(m>0)
    {
    c++;
    m=m/10;
    }
    m=n;
    while(m>0)
    {
    if(c==1)
    {
    s=s+(m%10);
    m=m/10;
    c=c-1;
    }
    else
    {
    s=(s+(m%10))*10;
    m=m/10;
    c=c-1;
    }
    }
    return(s);
    }


  • Sign In to post your comments