Learn With Rupam

In my opinion, the main hurdle a computer science engineer faces in the problem of practical. All these mug ups of lab program kills the time and opportunity of Learning. Now I am starting this thread for young aspirant CS students.

The objective is as bellow, I will post a simple problem and you have to write simple C-program to offer the solution. You need to post your program and the screenshot of the output. The curricula will be such that you get interest from basic to the most complex of algorithms.

If you are willing to put effort, lets work together.

Replies

  • Rupam Das
    Rupam Das
    1. Write a Simple C-program to print if a given number is even or odd

    criteria:

    You can not use % operator
    time : upto thrursday 5:30 IST.
  • harishproject
    harishproject
    Re: 1. Write a Simple C-program to print if a given number is even or odd

    #include
    void check(int n);
    void main()
    {
    int n;
    printf("\n Enter the number \n");
    scanf("%d",&n);
    check(n);
    }
    void check(int n)
    {
    int temp=n;
    for(int i=0;i {
    n=n-2;
    }
    if(n==0)
    printf("%d is even",temp);
    else
    printf("%d is odd",temp);
    }

    is this correct
  • harishproject
    harishproject
    Re: 1. Write a Simple C-program to print if a given number is even or odd

    and also
    #include
    void check(int n);
    void main()
    {
    int n;
    printf("\n Enter the number \n");
    scanf("%d",&n);
    check(n);
    }
    void check(int n)
    {
    int temp=n,q;
    q=temp/2;
    n=n-(2*q);
    if(n==0)
    printf("%d is even",temp);
    else
    printf("%d is odd",temp);
    }
  • Rupam Das
    Rupam Das
    Re: 1. Write a Simple C-program to print if a given number is even or odd

    harishproject
    and also
    #include
    void check(int n);
    void main()
    {
    int n;
    printf("\n Enter the number \n");
    scanf("%d",&n);
    check(n);
    }
    void check(int n)
    {
    int temp=n,q;
    q=temp/2;
    n=n-(2*q);
    if(n==0)
    printf("%d is even",temp);
    else
    printf("%d is odd",temp);
    }
    Bravo Harish..................... Great work!
  • Rupam Das
    Rupam Das
    Here is the Second Question: Write a Simple C program that Scan an even number

    Criteria:

    Once user gives an input, the scanning part must check if the number is even or not and should keep prompting the user for a valid even number input. if user fails to input correct number in 5 attempts, program should terminate.
    ๐Ÿ˜€
  • harishproject
    harishproject
    #include
    #include
    void check(int n);
    void main()
    {
    int n;
    for(int i=0;i<5;i++)
    {
    printf("\n Enter a valid even number number \n");
    scanf("%d",&n);
    if(n%2!=0)
    continue;
    else
    {
    printf("%d is even\n",n);
    break;
    }
    }
    exit(0);
    }
  • Rupam Das
    Rupam Das
    Great Going Harish. Now try this with a do-while loop

    Do while is the best technique for validating. Just try out. That is the most efficient method. I know you will do this.
  • harishproject
    harishproject
    Re: Great Going Harish. Now try this with a do-while loop

    #include
    #include
    void check(int n);
    void main()
    {
    int n,i=1;
    do
    {
    printf("\n Enter a valid even number number \n");
    scanf("%d",&n);
    i++;
    if(n%2!=0)
    continue;
    else
    {
    printf("%d is even\n",n);
    break;
    }
    }while(i<=5);
    exit(0);
    }

    ok did intrepret your question properly?

    and as i know for and do while execute same no. times here.can i know y is do while efficient?
  • H.Ali
    H.Ali
    #include
    #include
    void main()
    {
    int n,i=0;

    do {
    clrscr();
    printf("enter an EVEN No.\n");
    scanf("%d",&n);
    i++;
    continue;
    }while(n%2!=0&&i<5);
    if(n%2==0)
    printf("the enterd even No. is %d",n);
    else
    printf("LOSER\n you entered ODD No. in all your 5 chances !");
    getch();
    }
  • Rupam Das
    Rupam Das
    Ali....that was what exactly i was looking for and that is exactly how it must be done.
  • Rupam Das
    Rupam Das
    Ok The Next One: 3. A Simple Program to Find the Factorial of a Number

    But the Criteria is You can not use any sort of Loops: while,for, do while. And Recursion is also not permitted.
  • simplycoder
    simplycoder
    My code for Odd-Even numbers.
    #include
    //simplycoder
    
    using namespace std;
    int main(int argc,char**argv)
    
    {
        int num;
        scanf("%d",&num);
        num&1?printf("ODD\n"):printf("EVEN\n");
    system("PAUSE");
    return 0;
    }
  • Rupam Das
    Rupam Das
    @simplycoder, This is what I was Expecting. Professionally Done and you are "My Programmer of The day" . Real cool.
  • simplycoder
    simplycoder
    Nothing much to think of rather than Gamma-Functions and so on.
    I coded many series,out of which this series gave me the best and most accurate solution out of all.
    This approximation is called as Nemes approximation.
    #include
    #include
    //simplycoder
    
    using namespace std;
    int main(int argc,char**argv)
    
    {
        int x;
        scanf("%d",&x);
      
              int z=x+1;
    
       double pi=3.1415926535897932;
       double e=2.71828182845904523;
     
       double term1=sqrt(2.0*pi/z);
       double term2=1.0/e;
       double term3=(12*z-1/(10*z));
       double term4=z+1.0/term3;
       term4=term4*term2;
       term4=pow(term4,z);
       term4=round(term4*term1);
        cout<<"n "<
                                        
  • Rupam Das
    Rupam Das
    Again Spot On. But I would Prefer Some more approaches. Lemme know how many of Engineers here can Think Out of the Box!
  • H.Ali
    H.Ali
    simplycoder
    My code for Odd-Even numbers.
    
        num&1?printf("ODD\n"):printf("EVEN\n");
    
    }
    @simply coder please explain how this woks...
  • simplycoder
    simplycoder
    Its binary maths.
    Refer to my previous tutorial which involves bit-operators for more explanation.
    In short,all odd numbers have their last bit set to be 1 and all even number have last bit set to 0.
    So the above code works,
    condition?cout<<...:cout<<..
    is similar to if-else.
  • Rupam Das
    Rupam Das
    Next Assignment: 3) Find the Factorial of 65 in turbo C

    This is simplest isn't it? Find the factorial of 65 in Turbo C. If you are using boroland C++ or .Net, find the factorial of 1024 ๐Ÿ˜€
  • Rupam Das
    Rupam Das
    Next Assignment: Declare an Array in Turbo C which can store 100x100 double values. Store and retrieve the values. As Simple as that. ๐Ÿ˜€
  • simplycoder
    simplycoder
    I would not want to spoil this for other members but here is the slightest hint.This is not to be considered as normal and easy problem for findinf factorial, largest data-type is not sufficient to fit in all the numbers.
    Hint: use arrays.
  • H.Ali
    H.Ali
    Rupam Das
    Next Assignment: Declare an Array in Turbo C which can store 100x100 double values. Store and retrieve the values. As Simple as that. ๐Ÿ˜€
    Array size is too large !!! ๐Ÿ˜ dont know what to do .... let others try.. ๐Ÿ˜’
  • Rupam Das
    Rupam Das
    Thats why this thread is created. It needs to be solved.
  • H.Ali
    H.Ali
    No One to answer this...
    Rupam please post the Answer and the Next assignment....
  • Kashif Mehmood
    Kashif Mehmood
    Hello Sir , i am new member here , i am in 3rd year of computer science i have to submit proposal for final year project but dont have any idea
    my areas of intrest are:
    Andriod
    Gaming
    Netwroking
  • Faisal Ali
    Faisal Ali
    Hi...
    Sir i have read all your cs project ideas...no doubt all that projects are outstanding
    I personally asking you to suggest me a project which is unique...and not limited...
    Am a computer science student and my grip in c#
    A project which will be most usable..
    Thank you soo much if you help me....

You are reading an archived discussion.

Related Posts

can anyone recommend me any simple and easy mechatronic projects.. ASAP.. really need it.. can't think of it.. tq.. ๐Ÿ˜€
BlueStacks App Player will bring your dreams come true and let you run your Android Apps on Windows PC or tablet device. The startup revealed its player in Alpha Mode....
AT&T promised that they will launch about 12 new Android phones every year on their network. It seems that AT&T was quite serious about their announcement. The company has just...
If you love twitter and want to name your company with 'tweet' in it - watch out! Twitter Inc. has just secured the trademark for the word 'tweet'. Twittad is...
Facebook has just released the much awaited app for iPad. I'm not a FB user and don't have a reason to download the app on my iPad; however it would...