Sei sulla pagina 1di 26

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG.

AND TECHNOLOGY, BHILAI

PROGRAM - 01 Date.................. OBJECT WAP To Calculate The Area & Perimeter Of The Rectangle And The Area And Circumference Of The Circle. ALGORITHM 1. 2. 3. 4. 5. 6. 7. Input width of the rectangle. Input length of the rectangle. Input radius of circle. Calculate area and perimeter of the rectangle Calculate area and perimeter of the circle Output area and perimeter of the rectangle and circle. Stop

SAMPLE PROGRAM #include<stdio.h> #include<conio.h> void 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-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

INPUT OUTPUT VIVA QUESTIONS 1. 2. 3. 4. 5. Name various types of variables in C. How many characters are allowed in a variable name of C? What are the keywords in C? Differentiate between Constants and Variables. Differentiate between Variables and Keywords. ************

-2-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 02 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( ) ,etc 3. Accordingly display the retult 4. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> #include<ctype.h> 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-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

INPUT OUTPUT VIVA QUESTIONS 1. 2. 3. 4. 5. Write the syntax of If ...else Statement. Name the LOGICAL operators used in C. Prepare the table for the Hierarchy of Operators used in C. Name the RELATIONAL operators used in C. Prepare True Table for all the Logical Operators. ************

-4-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 03 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 formula Sum = Sum + counter / Factorial 4. Increment in value of Counter by 1 5. Repeat 2 4 unless, the value of Counter reaches to 7 6. Display the value of Sum. 7. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> void main() { clrscr(); int i,j,k; float S= 0; for( i = 1; i<= 7; i++) { int factorial =1; for( j =1; j<= i; j++) { factorial=factorial*j; }//Determination of the Factorial S = S + float(i)/factorial; }//End of the outer for loop textcolor(128 +3); gotoxy(20,20); cprintf("The sum of the Series is = %f",S); gotoxy(5,45); printf("Press any key to continue"); getch(); return; }//End of the main
-5-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. Write the syntax of For loop. Write the syntax of While loop. Write the syntax of Do.... While loop. What is the use of Break statement within loop? What is the use of Continue statement within loop?

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

-6-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 04 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 operations a. Factorial of a Number b. Prime or Not c. Odd or Even 2. Depending upon the users choice i.e. 1. Calculate Factorial Using the formula X = X * Yk Where k ranges from 1 to X 2. 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 Even 3. Display the final result 4. Stop SAMPLE PROGRAM
#include<stdio.h> #include<conio.h> #include<process.h> 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-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

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<= no; i++) factorial = factorial *i; printf("Factorial of %d = %ld",no,factorial); break; case 2: for( i =2;i< no; i++) { if( !(no % i) ) { printf("The given Number %d is not a Prime Number",no); break; } } if(i== no) printf("The given Number %d is a Prime Number\n",no); break; case 3: if( no%2 ) printf("The given Number %d is a Odd Number\n",no); else printf("The given Number %d is an Even Number\n",no); break; default: printf("You have selected a wrong option\nPlease select between 1 ...3\n"); }//End of the swithc case getch(); return; }//End of the main

INPUT OUTPUT VIVA QUESTIONS 1. 2. 3. 4. 5. Write the Syntax of Switch.... Case statement. Differentiate between Switch Vs if - else ladder. What is the use of goto statement? What is the role of keyword break in switch statement? What is the use of function exit( ) ?

-8-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 05 Date.................. OBJECT WAP To Implement Bubble Sort On An Set Of 10 Numbers ALGORITHM 1. 2. 3. 4. 5. 6. 7. Initialize an one dimensional array of TEN elements Select each element one by one Compare it with all the other element and swap if it is greater than the next Repeat 2 to 3 and arrange all the elements of the array The concept of Bubble sort in implemented in the following Fig 5.1 Print all the element of the array Stop BUBBLE SORT

ITERATION 1 0 1 2 3 4 44 33 55 22 11 33 44 55 22 11 33 44 55 22 11 33 44 22 55 11

ITERATION 2 0 1 2 3 4 33 44 22 11 55 0 1 2 3 4 33 44 22 11 55 0 1 2 3 4 33 22 44 11 55

ITERATION 3 0 1 2 3 4 33 22 11 44 55 0 1 2 3 4 22 33 11 44 55

ITERATION 4 Result 0 22 0 11 1 11 1 22 2 33 2 33 3 44 3 44 4 55 4 55

-9-

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

Fig 5.1 BUBBLE SORT

SAMPLE PROGRAM #include<stdio.h> #include<conio.h> void main() { clrscr(); int a[10],i,j,temp; for(i=0;i<10;i++) { printf("Enter any integer no a[%d] =",i+1); scanf("%d",&a[i]); }//End of for loop //Bubble sorting for(i = 0 ;i<9 ;i++) { for(j= 9; j>i ;j--) { if( a[j] < a[j-1]) { temp = a[j]; a[j] = a[j-1]; a[j-1]= temp; }// end of if }//End of inner for loop }//End of outer for loop //Printing the Numbers in Ascendin Order printf("\n\n"); gotoxy(1,20); textcolor(128 +5); cprintf("Printing of the Numbers in Ascending order \n\n\n"); for(i =0 ;i<10; i++) { printf(" %4d ",a[i]); }//End of the for loop
- 10 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

getch(); return; }//End of the main INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. What is array? Write a short program to pass array elements to a Function. Depict the Memory Allocation for Two Dimensional Array variables. Enlist the advantages of array variables. Diagrammatically compare the Selection and Insertion Sort.

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

- 11 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 06 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. 2. 3. 4. 5. 6. 7. Initialize file pointer Open a file in WRITE mode. Get character from keyboard Scan for its ASCII code If it is not Esc character write it within the file Other wise terminate writing within the file Stop

SAMPLE PROGRAM #include<stdio.h> #include<conio.h> 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 loop fclose(fp); getch(); return; }//End of the main
- 12 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. What are Strings? What is Scan code of a character? What is ASCII code of a character? Enlist certain Standard Library functions related to String. What is the significance of NULL character in a String?

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

- 13 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 07 Date.................. OBJECT WAP To Find The Roots Of An Equation Using Newton Raphson Method ALGORITHM 1. 2. 3. 4. 5. 6. Select any function say y = f(x). Find out its first differential say dy/dx = d /dx( f(x)) Set the starting value of x. Give the Maximum value of Permissible error. Set maximum no. of iterations allowed. 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 <= Maximum Permissible error 9. if Yes Print the result and terminate the programme 10. if Not , continue till all the iterataions are not completed 11. If even then the value of x does not converges give proper message and terminate the program. 12. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> #include<math.h> float fn(float x); float dfn(float x); void main() { clrscr(); int itr,maxitrn; float h,xo,x1,aerr; printf("\nEnter Starting Value of Xo = "); scanf("%f",&xo);
- 14 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

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<= maxitrn; itr++) { h = fn(xo) / dfn(xo); x1= xo - h; printf("Iteration No %2d and Modified Value of X = %10.7f\n",itr,x1); if( fabs(h) < aerr) { printf( "\n\n After %3d Iterations,Root X is = %10.7f\n" ,itr,x1); break; } xo=x1; }//End of for loop if( itr == maxitrn) printf(" Iterations are not sufficient, Solution Does not Converge\n"); getch(); return; }//End of the main float fn(float x) { // return (pow(x,3) - 2*x -5); return x *log10 (x) -1.2; }//end of fn(float x) float dfn(float x) { //return( 3*pow(x,2)-2); return (log10(x) + 0.4329); }//end of the dfn(float x)

//Function 1 //Function 2

- 15 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. What is a Function? What is Recursion? What are the Merits and Demerits of Newton Raphson Method? What is Taylors Series? Write the generalized formula for Newton Raphson method.

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

- 16 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 08 Date.................. OBJECT WAP A Program To Practice One Of The Numerical Integration Method I.E. Trapezoidal Rule. ALGORITHM 1. 2. 3. 4. Select the function say y = f(x) Set the starting and ending value of x i.e. limit of x. Give the no of iterval desired in the above limit of x. Calculate increment in x using the following formula h = (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 formula 7. Sum = h/2* Sum 8. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> 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 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

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<= n-1;i++) sum = sum + 2*fn(xo +i*h); textcolor(128+7); gotoxy(20,30); cprintf("The value of Integral is %10.7f\n",(h/2)*sum); getch(); return; }//End of the main float fn(float x) { return (1 /(1 + x)); }//end of fn(float x)

INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. Enlist the various methods of Numerical Integration. Differentiate between Trapezoidal Rule and Simpsons 1/3 Rule. Differentiate between Simpsons 1/3 Rule and Simpsons 3/8 Rule. What are the uses of Cubic Spline ? What are the Merits and Demerits of Trapezoidal Rule?

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

- 18 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 09 Date.................. OBJECT WAP To Find The Solution Of Differential Equation By Eulers Equation ALGORITHM 1. 2. 3. 4. 5. Select any Differential equation Initialize x and y Decide the final value of x Decide the increment in value of x i.e. initialize h Calculate modified values of x and y using the following formula a. y1 = y1 + h * dy/dx (x1,y1) b. x 1 = x1 + h

6. Continue the above iteration until x1 < x 7. Print the final value of x1 and y1 8. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> 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 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

printf("When x = %f the value of y = %10.7f\n",x1,y1); }//End of while loop getch(); return; }//End of the main float dfn(float x,float y) { return x+y; } INPUT OUTPUT

VIVA QUESTIONS 1. 2. 3. 4. 5. What is Eulers Method? What is Modified Eulers Method? Explain the method of error estimation for the Euler Method. What are the Merits and Demerits of the Eulers Method? What are the limitations of Eulers Method?

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

- 20 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

PROGRAM - 10 Date.................. OBJECT WAP To Find The Solution Of Differential Equation By Runge Kutta Equation ALGORITHM 1. 2. 3. 4. Select any function Initialize the value of x and y Select the final value of x and increment in x i.e. h 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 y 7. Stop SAMPLE PROGRAM #include<stdio.h> #include<conio.h> #include<math.h> 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 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

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 loop getch(); 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 solution of 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 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

LAB RECORD
OF
NUMERICAL ANALYSIS & COMPUTER PROGRAMMING

DEPARTMENT OF MECHANICAL ENGINEERING


NAME OF STUDENT SEMESTER BATCH ROLL NO. ACADEMIC SESSION

M.P.CHRISTIAN COLLEGE OF ENGINEERING & TECHNOLOGY Kailash Nagar, Near Industrial Estate, Bhilai, Distt.-Durg, C.G. - 23 Ph.No. : 0788 2286662/3/4, Fax. No. 0788 2285266 Website www.mpccet.org & www.mpccet.ac.in

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

M.P. CHRISTIAN COLLEGE OF ENGINEERING & TECHNOLOGY, BHILAI


NUMERICAL ANALYSIS & COMPUTER PROGRAMMING 3rd SEM MECHANICAL

LIST OF PROGRAMS

Sl. NO. 01 02 03

NAME OF EXPERIMENTS
WAP to calculate the area and perimeter of the rectangle and the area and circumference of the circle WAP to determine whether the character entered through a keyboard is a capital letter, a small case letter, a digit or a special symbol WAP to add first seven terms of the following series using looping statements series is S = 1/1! + 2/2! +... WAP which has the following options a. Factorial of a number b. Prime No. or not c. Odd or Even no. WAP to implement Bubble sort on a set of 10 numbers 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. WAP to find the roots of an equation using Newton Raphson Method. WAP to practice one of the Numerical Integration Method WAP to find the solution fo Differential Equation by Modified Eulers Equation WAP to find the solution of Differential Equation by Runge Kutte Equation

PAGE NO.
01 03 05

PERFORMED ON

REMARKS

04 05 06 07 08 09 10

07 09 12 14 17 19 21

- 24 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

Signature of Teacher

M.P. CHRISTIAN COLLEGE OF ENGINEERING & TECHNOLOGY, BHILAI


NUMERICAL ANALYSIS & COMPUTER PROGRAMMING 3rd SEM MECHANICAL

LIST OF PROGRAMS
Sl. NO. 01 02 03 NAME OF EXPERIMENTS WAP to calculate the area and perimeter of the rectangle and the area and circumference of the circle WAP to determine whether the character entered through a keyboard is a capital letter, a small case letter, a digit or a special symbol WAP to add first seven terms of the following series using looping statements series is S = 1/1! + 2/2! +... WAP which has the following options d. Factorial of a number e. Prime No. or not f. Odd or Even no. WAP to implement Bubble sort on a set of 10 numbers 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. WAP to find the roots of an equation using Newton Raphson Method. WAP to practice one of the Numerical Integration Method WAP to find the solution fo Differential Equation by Modified Eulers Equation WAP to find the solution of Differential Equation by Runge Kutte Equation PAGE NO. 01 03 05

04 05 06 07 08 09 10

07 09 12 14 17 19 21

- 25 -

DEPARTMENT OF MECHANICAL ENGG. M.P.CHRISTIAN COLLEGE OF ENGG. AND TECHNOLOGY, BHILAI

- 26 -

Potrebbero piacerti anche