n a c p final

Upload: rahuldahekaryahoocoin

Post on 05-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 N A C P final

    1/26

    Date..................

    OBJECT

    WAP To Calculate The Area & Perimeter Of The Rectangle And The Area And

    Circumference Of The Circle.

    ALGORITHM

    1. Input width of the rectangle.

    2. Input length of the rectangle.

    3. Input radius of circle.4. Calculate area and perimeter of the rectangle

    5. Calculate area and perimeter of the circle

    6. Output area and perimeter of the rectangle and circle.7. Stop

    SAMPLE PROGRAM

    #include

    #includevoid main()

    {

    clrscr();

    int l,w,r;float rect_area,rect_perimeter,circle_area,circle_perimeter;

    printf("Enter Width of the Rectangle \n");scanf("%d",&w);

    printf("Enter Length of the Rectangle \n");

    scanf("%d",&l);

    printf("Enter Radius of the circle \n");scanf("%d",&r);

    //Calculation for Rectangle and Circle

    rect_area = w *l;rect_perimeter = 2*(w+l);

    circle_area = (22.0/7.0)*r*r;circle_perimeter =2*22.0/7.0 * r;printf("\n\n Area of Rectangle = %f",rect_area);

    printf("\n\n Perimeter of Rectangle = %f",rect_perimeter);

    printf("\n\n Area of the Circle = %f",circle_area);printf("\n\n Perimeter of the Circle = %f",circle_perimeter);

    getch();

    return;

    }//End of the main

    - 1 -

  • 7/31/2019 N A C P final

    2/26

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. Name various types of variables in C.2. How many characters are allowed in a variable name of C?

    3. What are the keywords in C?

    4. Differentiate between Constants and Variables.

    5. Differentiate between Variables and Keywords.

    ************

    - 2 -

  • 7/31/2019 N A C P final

    3/26

    Date..................

    OBJECT

    WAP To Determine Whether The Character Entered Through A Keyboard Is A

    Capital Letter, A Small Case Letter, A Digit Or A Special Symbol.

    ALGORITHM

    1. Input any character

    2. Use Inbuilt functions like

    Iuppter(_), Islower(), Isdigit( ) ,etc3. Accordingly display the retult

    4. Stop

    SAMPLE PROGRAM

    #include#include

    #include

    void main(){

    clrscr();

    char ch;

    printf("Enter any Character from the Keyboard\n\n");

    ch=getchar();textcolor(128+10);

    gotoxy(20,25);

    if(isupper(ch))cprintf("The entered character is a CAPITAL LETTER \n");

    else if( islower(ch))cprintf("The entered character is a SMALL LETTER\n");

    else if (isdigit(ch))cprintf("The entered character is a NUMERIC CHARCTER\n");

    else

    cprintf("The entered character is a SPECIAL CHARACTER \n");

    gotoxy(5,45);

    printf("Press any key to continue\n");

    getch();

    return;}//End of the main

    - 3 -

  • 7/31/2019 N A C P final

    4/26

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. Write the syntax of If...else Statement.

    2. Name the LOGICAL operators used in C.

    3. Prepare the table for the Hierarchy of Operators used in C.4. Name the RELATIONAL operators used in C.

    5. Prepare True Table for all the Logical Operators.

    ************

    - 4 -

  • 7/31/2019 N A C P final

    5/26

    Date..................

    OBJECT

    WAP To Add First Seven Terms Of The Following Series Using Looping

    Statements Series Is S = 1/ 1! + 1 / 2! + 3 /3! + .......

    ALGORITHM

    1. Initialize Sum =0, and Counter =1

    2. Find factorial of value available in variable Counter

    3. Use the following formulaSum = Sum + counter / Factorial

    4. Increment in value of Counter by 1

    5. Repeat 2 4 unless, the value of Counter reaches to 76. Display the value of Sum.

    7. Stop

    SAMPLE PROGRAM

    #include

    #includevoid main()

    {

    clrscr();

    int i,j,k;float S= 0;

    for( i = 1; i

  • 7/31/2019 N A C P final

    6/26

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. Write the syntax of Forloop.

    2. Write the syntax ofWhileloop.

    3. Write the syntax ofDo.... Whileloop.4. What is the use ofBreakstatement within loop?5. What is the use ofContinue statement within loop?

    ************

    - 6 -

  • 7/31/2019 N A C P final

    7/26

    Date..................

    OBJECT

    WAP In Which Has The Followoing Options

    a. Factorial No.

    b. Prime No. Or Not

    c. Odd Or Even No.

    ALGORITHM

    1. Display Menu to perform the following operationsa. Factorial of a Number

    b. Prime or Not

    c. Odd or Even

    2. Depending upon the users choice i.e.

    1. Calculate FactorialUsing the formula

    X = X * Yk

    Where

    k ranges from 1 to X2. Find out Prime no

    By dividing it by every digit excluding 1 and itself

    3. Find out Odd / Even no.By dividing it by 2

    If the remainder is non zero then it is Odd no. otherwise Even3. Display the final result

    4. Stop

    SAMPLE PROGRAM

    #include

    #include

    #include

    void main(){

    clrscr();int i,choice;

    int no;

    long int factorial=1;

    printf("Select Your Option please...\n\n");

    printf(" 1. Factorial No.\n 2. Prime No.\n 3. Odd and Even No.\n");

    scanf("%d",&choice);

    clrscr();

    - 7 -

  • 7/31/2019 N A C P final

    8/26

    printf("\n\nENTER THE No. You Want to Manipulate\n");

    scanf("%d",&no);

    switch(choice)

    {

    case 1: //Determination of Factorial No.for(i =1 ;i

  • 7/31/2019 N A C P final

    9/26

    Date..................

    OBJECT

    WAP To Implement Bubble Sort On An Set Of 10 Numbers

    ALGORITHM

    1. Initialize an one dimensional array of TEN elements2. Select each element one by one

    3. Compare it with all the other element and swap if it is greater than the next

    4. Repeat 2 to 3 and arrange all the elements of the array5. The concept of Bubble sort in implemented in the following Fig 5.1

    6. Print all the element of the array

    7. Stop

    BUBBLE SORT

    ITERATION 4

    Result

    0 22 0 111 11 1 22

    2 33 2 33

    3 44 3 44

    4 55 4 55

    - 9 -

    ITERATION 1

    0 44 33 33 33

    1 33 44 44 44

    2 55 55 55 223 22 22 22 55

    4 11 11 11 11

    ITERATION 2

    0 33 0 33 0 33

    1 44 1 44 1 22

    2 22 2 22 2 44

    3 11 3 11 3 11

    4 55 4 55 4 55

    ITERATION 3

    0 33 0 221 22 1 33

    2 11 2 11

    3 44 3 44

    4 55 4 55

  • 7/31/2019 N A C P final

    10/26

    Fig 5.1 BUBBLE SORT

    SAMPLE PROGRAM

    #include

    #include

    void main(){

    clrscr();

    int a[10],i,j,temp;for(i=0;i

  • 7/31/2019 N A C P final

    11/26

    getch();

    return;}//End of the main

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. What is array?2. Write a short program to pass array elements to a Function.3. Depict the Memory Allocation for Two Dimensional Array variables.

    4. Enlist the advantages of array variables.

    5. Diagrammatically compare theSelection andInsertion Sort.

    ************

    - 11 -

  • 7/31/2019 N A C P final

    12/26

    Date..................

    OBJECT

    WAP To Sore Every Character Typed At The Keyboard Into A File. The Procedure

    Should Come To An End As Soon As The Esc Key Is Pressed

    ALGORITHM

    1. Initialize file pointer

    2. Open a file in WRITE mode.

    3. Get character from keyboard4. Scan for its ASCII code

    5. If it is not Esc character write it within the file

    6. Other wise terminate writing within the file

    7. Stop

    SAMPLE PROGRAM

    #include

    #include

    void main(){

    clrscr();

    FILE *fp;fp = fopen("data.txt","w");

    char ch;

    //Note 10 is the scan code for the ESC key pressed

    while( int(ch =getchar()) != 10){

    fputc(ch,fp);

    }//End of the while loopfclose(fp);

    getch();

    return;

    }//End of the main

    - 12 -

  • 7/31/2019 N A C P final

    13/26

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. What areStrings?

    2. What isScan code of a character?3. What isASCIIcode of a character?4. Enlist certainStandardLibrary functions related to String.

    5. What is the significance ofNULL character in a String?

    ************

    - 13 -

  • 7/31/2019 N A C P final

    14/26

    Date..................

    OBJECT

    WAP To Find The Roots Of An Equation Using Newton Raphson Method

    ALGORITHM

    1. Select any function say y = f(x).

    2. Find out its first differential say dy/dx = d /dx( f(x))3. Set the starting value of x.

    4. Give the Maximum value of Permissible error.

    5. Set maximum no. of iterations allowed.6. Calculate h using the following formula

    h = f(x) / d/dx(f(x))

    7. Calculate new value of x say x1 using the following formula

    x1 = x h

    8. Check whether the value of h is

  • 7/31/2019 N A C P final

    15/26

    printf("\nEnter Value of Maximum Permissible Error=");

    scanf("%f",&aerr);

    printf("\n Enter Maximum no. of Iteration allowed =");scanf("%d",&maxitrn);

    //Iteration Starts

    for(itr =1 ; itr

  • 7/31/2019 N A C P final

    16/26

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. What is a Function?

    2. What is Recursion?

    3. What are the Merits and Demerits of Newton Raphson Method?4. What is Taylors Series?5. Write the generalized formula for Newton Raphson method.

    ************

    - 16 -

  • 7/31/2019 N A C P final

    17/26

    Date..................

    OBJECT

    WAP A Program To Practice One Of The Numerical Integration Method I.E.

    Trapezoidal Rule.

    ALGORITHM

    1. Select the function say y = f(x)2. Set the starting and ending value of x i.e. limit of x.

    3. Give the no of iterval desired in the above limit of x.

    4. Calculate increment in x using the following formulah = (xn xo )/ n

    5. Applying the following formula find out the summation

    a. Sum = fn(x0) + fn (xn)

    b. Sum = Sum + 2* fn(x0 + inh)c. Where

    n ranges from 1 to n-1

    6. Finally print the sum using the formula7. Sum = h/2* Sum

    8. Stop

    SAMPLE PROGRAM

    #include#include

    float fn(float x);

    void main(){clrscr();

    float xo,xn,h;

    int i,n;float sum;

    printf("Enter Starging value of X i.e.Xo =");

    scanf("%f",&xo);printf("Enter Ending value of X i.e. Xn =");

    - 17 -

  • 7/31/2019 N A C P final

    18/26

    scanf("%f",&xn);

    printf("Enter the Value of Interval i.e. n = ");

    scanf("%d",&n);

    h= (xn - xo)/n;sum = fn(xo) + fn(xn);

    for(i =1;i

  • 7/31/2019 N A C P final

    19/26

    Date..................

    OBJECT

    WAP To Find The Solution Of Differential Equation By Eulers Equation

    ALGORITHM

    1. Select any Differential equation

    2. Initialize x and y3. Decide the final value of x

    4. Decide the increment in value of x i.e. initialize h

    5. Calculate modified values of x and y using the following formulaa. y1 = y1 + h * dy/dx (x1,y1)

    b. x 1 = x1 + h

    6. Continue the above iteration until x1 < x7. Print the final value of x1 and y18. Stop

    SAMPLE PROGRAM

    #include

    #include

    float dfn(float x, float y);

    void main()

    {clrscr();

    float xo,yo, h,x,x1,y1;printf("Enter the vlaue of xo,yo,h,x\n");

    scanf("%f%f%f%f",&xo,&yo,&h,&x);

    x1 = xo; y1 = yo;while (1)

    {

    if (x1 >x) break;

    y1 += h * dfn(x1,y1);x1+= h;

    - 19 -

  • 7/31/2019 N A C P final

    20/26

    printf("When x = %f the value of y = %10.7f\n",x1,y1);

    }//End of while loopgetch();

    return;}//End of the main

    float dfn(float x,float y)

    {

    return x+y;

    }

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. What is Eulers Method?

    2. What is Modified Eulers Method?

    3. Explain the method of error estimation for the Euler Method.

    4. What are the Merits and Demerits of the Eulers Method?5. What are the limitations of Eulers Method?

    ************

    - 20 -

  • 7/31/2019 N A C P final

    21/26

    Date..................

    OBJECT

    WAP To Find The Solution Of Differential Equation By Runge Kutta Equation

    ALGORITHM

    1. Select any function

    2. Initialize the value of x and y3. Select the final value of x and increment in x i.e. h

    4. Use the following formula for calculation

    k1 = h * fn(x,y);k2 = h*fn(x + h/2, y + k1/2);

    k3 = h*fn(x + h/2, y + k2/2);

    k4= h*fn(x +h, y + k3);

    k = (k1 +2*(k2 +k3) +k4 )/6;x= x + h;

    y = y + k;

    5. Continue the above calculation until xo reaches to xn

    6. Print the value of x and y7. Stop

    SAMPLE PROGRAM

    #include

    #include#include

    float fn(float x, float y);

    void main(){clrscr();

    float xo,yo,h,xn,x,y,k1,k2,k3,k4,k;

    printf("Enter the values of xo,yo, h,xn \n");scanf("%f %f %f %f",&xo,&yo,&h,&xn);

    x=xo;

    y=yo;

    while(1){

    - 21 -

  • 7/31/2019 N A C P final

    22/26

    if(x == xn) break;

    k1 = h * fn(x,y);

    k2 = h*fn(x + h/2, y + k1/2);k3 = h*fn(x + h/2, y + k2/2);

    k4= h*fn(x +h, y + k3);k = (k1 +2*(k2 +k3) +k4 )/6;

    x= x+h;y = y +k;

    printf("When x = %10.7f y = %10.7f \n",x,y);

    }//End of the while loopgetch();

    return;

    }//End of the main

    float fn(float x, float y)

    {return (x+ y*y);

    }

    INPUT

    OUTPUT

    VIVA QUESTIONS

    1. What is the difference between the Eulers and Runge Kutte Method for the solutionof ordinary differential equation?

    2. What are the limitations of Runge Kutte Method?

    3. What are the merits and demerits of Runge Kutte Method?4. Write the Second order Runge Kutte Formula.

    5. Write the Fourth order Runge Kutte Formula.

    ************

    - 22 -

  • 7/31/2019 N A C P final

    23/26

    LAB RECORDOF

    NUMERICAL ANALYSIS & COMPUTER PROGRAMMING

    DEPARTMENT OF MECHANICAL ENGINEERING

    NAME OF STUDENT

    SEMESTER

    BATCH

    ROLL NO.

    ACADEMIC SESSION

    - 23 -

    M.P.CHRISTIAN COLLEGE OF ENGINEERING & TECHNOLOGY

    Kailash Nagar, Near Industrial Estate, Bhilai, Distt.-Durg, C.G.

    Ph.No. : 0788 2286662/3/4, Fax. No. 0788 2285266

    Website www.mpccet.org & www.mpccet.ac.in

  • 7/31/2019 N A C P final

    24/26

    M.P. CHRISTIAN COLLEGE OF ENGINEERING &

    TECHNOLOGY, BHILAI

    NUMERICAL ANALYSIS & COMPUTER PROGRAMMING

    3rd SEM MECHANICAL

    LIST OF PROGRAMS

    Sl.NO.

    NAME OF EXPERIMENTS PAGENO.

    PERFORMEDON

    REMARKS

    01WAP to calculate the area and perimeter of the

    rectangle and the area and circumference of thecircle

    01

    02WAP to determine whether the character enteredthrough a keyboard is a capital letter, a small case

    letter, a digit or a special symbol

    03

    03WAP to add first seven terms of the following

    series using looping statements series is S = 1/1! +

    2/2! +...

    05

    04

    WAP which has the following optionsa. Factorial of a number

    b. Prime No. or notc. Odd or Even no.

    07

    05WAP to implement Bubble sort on a set of 10numbers

    09

    06WAP to store every character typed at thekeyboard into a file. The procedure should come to

    an end as soon as the Esc key is pressed.

    12

    07WAP to find the roots of an equation usingNewton Raphson Method.

    14

    08 WAP to practice one of the Numerical IntegrationMethod

    17

    09WAP to find the solution fo Differential Equationby Modified Eulers Equation

    19

    10WAP to find the solution of Differential Equationby Runge Kutte Equation

    21

    - 24 -

  • 7/31/2019 N A C P final

    25/26

    Signature of Teacher

    M.P. CHRISTIAN COLLEGE OF ENGINEERING &

    TECHNOLOGY, BHILAINUMERICAL ANALYSIS & COMPUTER PROGRAMMING

    3rd SEM MECHANICAL

    LIST OF PROGRAMS

    Sl.

    NO. NAME OF EXPERIMENTSPAGE

    NO.

    01WAP to calculate the area and perimeter of the rectangle and

    the area and circumference of the circle01

    02

    WAP to determine whether the character entered through a

    keyboard is a capital letter, a small case letter, a digit or a

    special symbol

    03

    03WAP to add first seven terms of the following series using

    looping statements series is S = 1/1! + 2/2! +...05

    04

    WAP which has the following optionsd. Factorial of a number

    e. Prime No. or not

    f. Odd or Even no.

    07

    05 WAP to implement Bubble sort on a set of 10 numbers 09

    06

    WAP to store every character typed at the keyboard into a file.

    The procedure should come to an end as soon as the Esc key

    is pressed.

    12

    07WAP to find the roots of an equation using Newton Raphson

    Method.

    14

    08 WAP to practice one of the Numerical Integration Method 17

    09WAP to find the solution fo Differential Equation by Modified

    Eulers Equation19

    10WAP to find the solution of Differential Equation by Runge

    Kutte Equation21

    - 25 -

  • 7/31/2019 N A C P final

    26/26