CrazyEngineers
  • Rupam Das
    Rupam Das

    MemberOct 10, 2011

    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
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Rupam Das

    MemberOct 10, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • harishproject

    MemberOct 11, 2011

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

    #include<stdio.h>
    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<temp/2;i++)
    {
    n=n-2;
    }
    if(n==0)
    printf("%d is even",temp);
    else
    printf("%d is odd",temp);
    }

    is this correct
    Are you sure? This action cannot be undone.
    Cancel
  • harishproject

    MemberOct 11, 2011

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

    and also
    #include<stdio.h>
    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);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 13, 2011

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

    harishproject
    and also
    #include<stdio.h>
    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!
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 13, 2011

    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.
    😀
    Are you sure? This action cannot be undone.
    Cancel
  • harishproject

    MemberOct 13, 2011

    #include<stdio.h>
    #include<stdlib.h>
    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);
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 13, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • harishproject

    MemberOct 14, 2011

    Re: Great Going Harish. Now try this with a do-while loop

    #include<stdio.h>
    #include<stdlib.h>
    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?
    Are you sure? This action cannot be undone.
    Cancel
  • H.Ali

    MemberOct 14, 2011

    #include<stdio.h>
    #include<conio.h>
    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();
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 14, 2011

    Ali....that was what exactly i was looking for and that is exactly how it must be done.
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 14, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberOct 14, 2011

    My code for Odd-Even numbers.
    #include<iostream>
    //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;
    }
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 14, 2011

    @simplycoder, This is what I was Expecting. Professionally Done and you are "My Programmer of The day" . Real cool.
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberOct 14, 2011

    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<iostream>
    #include<math.h>
    //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 "<<x<<" fact : "<<term4<<endl;
       
    
    
       cout<<endl<<endl;
    system("PAUSE");
    return 0;
    }
    
    
    
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 14, 2011

    Again Spot On. But I would Prefer Some more approaches. Lemme know how many of Engineers here can Think Out of the Box!
    Are you sure? This action cannot be undone.
    Cancel
  • H.Ali

    MemberOct 15, 2011

    simplycoder
    My code for Odd-Even numbers.
    
        num&1?printf("ODD\n"):printf("EVEN\n");
    
    }
    @simply coder please explain how this woks...
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberOct 15, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 17, 2011

    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 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 17, 2011

    Next Assignment: Declare an Array in Turbo C which can store 100x100 double values. Store and retrieve the values. As Simple as that. 😀
    Are you sure? This action cannot be undone.
    Cancel
  • simplycoder

    MemberOct 18, 2011

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • H.Ali

    MemberOct 19, 2011

    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.. 😒
    Are you sure? This action cannot be undone.
    Cancel
  • Rupam Das

    MemberOct 19, 2011

    Thats why this thread is created. It needs to be solved.
    Are you sure? This action cannot be undone.
    Cancel
  • H.Ali

    MemberDec 18, 2011

    No One to answer this...
    Rupam please post the Answer and the Next assignment....
    Are you sure? This action cannot be undone.
    Cancel
  • Kashif Mehmood

    MemberApr 20, 2015

    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
    Are you sure? This action cannot be undone.
    Cancel
  • Faisal Ali

    MemberJan 19, 2016

    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....
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register