BCSL 58 em

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14
 
1
  T  h e   H  u  b   f o  r   O  n  l  i  n e   R e a d  i  n g  a  n d   E -  b o o  k s
 
2
  T  h e   H  u  b   f o  r   O  n  l  i  n e   R e a d  i  n g  a  n d   E -  b o o  k s
5
 
3
  T  h e   H  u  b   f o  r   O  n  l  i  n e   R e a d  i  n g  a  n d   E -  b o o  k s
B.C.S.L.-058
Computer-oriented NumericalTechniques Lab
 Disclaimer/Special Note:
 These are just the sample of the Answers/Solutions to some of the Questions given in theAssignments. These Sample Answers/Solutions are prepared by Private Teacher/Tutors/Authors for the help and guidanceof the student to get an idea of how he/she can answer the Questions given the Assignments. We do not claim 100%accuracy of these sample answers as these are based on the knowledge and capability of Private Teacher/Tutor. Sampleanswers may be seen as the Guide/Help for the reference to prepare the answers of the Questions given in the assignment.As these solutions and answers are prepared by the private Teacher/Tutor so the chances of error or mistake cannot bedenied. Any Omission or Error is highly regretted though every care has been taken while preparing these Sample Answers/Solutions. Please consult your own Teacher/Tutor before you prepare a Particular Answer and for up-to-date and exactinformation, data and solution. Student should must read and refer the official study material provided by the university.
Note: The programs are to be written in C/C++ and/or in MS-Excel/Any spread sheet.Q.1. Write a program in C/C++ to find the solution of system of linear equations (given below), by usingGauss-Elimination method:
 x 
 +
 y
 +
 z 
 = 2
 x 
 + 2
 y
 + 3
 z 
 = 14
 x 
 + 3
 z 
 = 14
 x 
 + 3
 y
 – 6
 z 
 = – 23Ans.
#include <stdio.h>#include <stdlib.h>#include<math.h>int main(){int n,i,j,k;float a[10][10]={0.0}, x[10]={0.0};float pivot = 0.0;float factor = 0.0;float sum = 0.0; printf(“Gauss Elimination \n\n”); printf(“Enter number of equations:”);scanf(“%d”,&n); printf(“%d\n”,n); printf(“\n\t Input Coefficients a[i, j+1], row-wise\n”);for(i=l;i<=n;i++)\{for(i=1;<=n+1;j++)
5
 
4
  T  h e   H  u  b   f o  r   O  n  l  i  n e   R e a d  i  n g  a  n d   E -  b o o  k s
{scanf(“%f’,&a[i][j]);}} printf(“\n\n”);for(i=l;i<=n;i++)} printf(“\t%10.0f”,a[i][j]);} printf(“\n\n”);}for(k=l;k<=n-l;k++){if(a[k][k]==0.0) printf(“error”);}else{ pivot = a[k][k];for(j=k;j<=n+l;j++)a[k]Q]=a[k][j]/pivot;for(i=k+l;i<=n;i++){factor =a[i][k];for(j = k;j<=n+l;j++)a[i][j]=a[i][j]- factor * a[k]Q];}}}if(a[n][n]==0) printf(“error”)else{x[n] = a(n)(n+1)/a(n)(n);for(i=n–1;i>=1;i--){sum = 0.0;for(j=i+1;j<=n;j++)sum = sum + a[i][j] * x[j];x(i)=(a[i][n+1]–sum)/a[i] [i];for(i=l;i<=n;i++)}}}
5
5
5
5
5
5
5
5
5
5
5

Reward Your Curiosity

Everything you want to read.
Anytime. Anywhere. Any device.
No Commitment. Cancel anytime.
576648e32a3d8b82ca71961b7a986505