Uploaded by Anant Badal

Lab-Assessments

advertisement
Assessment – 1
Write C programs to answer the following questions:
1. Find the largest among three arbitrary numbers.
2. Find the factors of an integer.
3. Find all the prime numbers between two arbitrary integers.
***
Assessment - 2
1. Write a function to find the largest and smallest among three numbers. Call this function from
main().
2. Write a function that counts the number of digits of an integer and then reverse it. Call this
function from main() and print the results in main().
3. Write a function that checks if an integer can be expressed as the sum of two prime numbers.
If yes, then prints all such possible combinations. Call this function from main() and print
the results in main().
***
Assessment – 3
Write C programs to answer the following questions:
1. Write a C code to check if a square matrix is lower triangular. A matrix is called lower triangular
if all the elements above the main diagonal are zero. Matrix elements should be entered from
the keyboard.
2. Write a C code to check if an array a[n] is a subset of another array b[m]; m>n. Matrix
elements should be entered from the keyboard.
3. Open a file using vi/vim and write your hostel address there. Now write a C code to read the
texts of the file and print it in a new file. You can use fgetc() and fputc() functions.
***
Assessment – 4
1. Write C programs to calculate the value of the function at an arbitrary point taken by the user,
using the (i) Lagrange, (ii) Aitken and (iii) Newton’s forward difference method
xi
fi
0.0
1.000000
0.5
0.938470
1.0
0.765198
1.5
0.511828
2.0
0.223891
Newton’s forward difference formula for (n+1) data points:
𝛥𝑓0 1
𝛥2 𝑓0 1
𝛥3 𝑓0
𝑓 (𝑛) (𝑥) = 𝑓0 + (𝑥 − 𝑥0 )
+ (𝑥 − 𝑥0 )(𝑥 − 𝑥1 ) 2 + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) 3
ℎ
2!
ℎ
3!
ℎ
1
𝛥𝑛 𝑓0
+ ⋯ + (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )(𝑥 − 𝑥2 ) … (𝑥 − 𝑥𝑛−1 ) 𝑛 ,
𝑛!
ℎ
where 𝛥𝑘 𝑓0 is kth order forward difference.
Lagrange interpolation scheme:
𝑛
𝑛
𝑓(𝑥) = ∑ 𝑓𝑗 𝑝𝑛𝑗 (𝑥) ;
𝑝𝑛𝑗 (𝑥) = ∏
𝑗=0
𝑘≠𝑗
(𝑥 − 𝑥𝑘 )
.
(𝑥𝑗 − 𝑥𝑘 )
***
MidSem
Time: 60 minutes]
[Full Marks: 10
1. Write a C code to calculate the result of the following series for 𝑁 number of terms. 𝑁 is taken by
the user:
1/1! + 2/2! + 3/3! + 4/4! + ⋯.
Hints: You may write a function to calculate the factorial of a number.
2. Write a C code to find the fourth largest element of a 3 × 3 matrix. Matrix elements are taken from
the user.
Hints: You may first take the 2D matrix elements in a 1D matrix.
Download