0% found this document useful (0 votes)
32 views

927623BME040 C Programming L Lab Record 2023 12 17

Uploaded by

tamilbullsatoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views

927623BME040 C Programming L Lab Record 2023 12 17

Uploaded by

tamilbullsatoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 96
: Exp. Name: Write @ C program to find Area and . S.No: 1 cimimpcone era cicis Date: 2023-11-13, Aim: Write a program to find the area and circumference of a cirele, Note: Use the printf() function with a newline character ( \n ) at the end. area = PI * radius * radius circumference = 2 * PI * radius Define (Pr) value as 3.14) using (define) and consider float ) data type for radius Source Code: circle.¢ Hincludecstdio.h> Hincludecnath.h> int main() { float radius,area, circumference; printf ("radius : *); scant ("#",@radius) ; area=3.14*radiustradius; circumference=2*3.14*radius; printf("area = XF\n",area); print#("circumference = XF\n" circumference) ; return 0; Execution Results - all test cases have succeeded! Test Case - 1 User Output radius 2.67 ‘area = 22,384747 circumference = 16,767601 Test Case - 2 User Output radius 30.05 ‘area = 2835.427734 Circumference = 188.713989 ID: 927623BME040__ Page No: 1 MXKumarasamy College of Engineering |2023-2027-B3. Test Case - 3 User Output radius 14.69 ‘area = 677,599731 ‘circumference = 92,253197 ID: 927623BME040_ Page No: 2 M.Kumarasamy College of Engineering |2023-2027-B3. Exp. Name: Basic Calculator implementation Date: 2023-11-24 Ain Writing a C program to implement Basic Calculator Source Code: calculatior Mincludecstdio.h> int main() { double nunbert,number2; print#("enter nunbert: "); scanf("1¢", @numbert) 5 printf(“enter non zero nunber2 scanf("K1#" ,@number2) ; printé("%.21f + %.21f = print#("%.21f - %.21F print#(°%.21f * %.21F number, nunber2,nunbert+nunber2) ; number, nunber2, number -nunber2) ; %.21f\n", nunberd,nunber2, number. *number2) 5 prantf("%.21F / %.21F = X.21F\n" nunbert, nunber2,nunberd/nunber2); return 85 } Execution Results - All test cases have succeeded! Test Case - 1 User Output enter nunberd: 2 enter non Zeno nunberde 3 2.00 + 3.00 = 5.00 2.00 - 3.00 = -1.00 2.00 * 3.00 = 6.00 2.00 / 3.00 = 0.67 ID: 927623BME040_ Page No: 3 MKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Design an algorithm and implement S.No: 3 Date: 2023-11-24 using C language the following exchanges im: Design an algorithm and implement using C language the following exchanges a ~ b— result as shown in the example. = d= aand print the ‘Sample Input and Output: Enter values of a, b, ¢ and d: 98 74 21 36 After swapping a= 74 bea c= 36 d= 98 Source Code exchange. Hincludecstdio.h> int main() { int a,b,e.d5 print#("Enter values of a, b, ¢ and d: scanf("Xd" 8a); scanf("%d" 8b); scanF("%d" 8c); scanf("d" 8d); print#(“After swapping\n"); print#("a = Rd\nb = %d\nc = Xd\nd = %d\n",b,c,d,a)5 Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter values of a, 6, ¢ and di 1234 ‘After swapping a-2 b= Test Case - 2 User Output Enter values of a, b ¢ and d 98 74.2136 ID: 927623BME040_ Page No: 4 MXKumarasamy College of Engineering |2023-2027-B3. S:0N a6eg | Ovoaaezoze After swapping, 2-7 baa 36 a= 98 €8-1Z02°EZOZ!_ GuiaauiGuy Jo a6ayj0> Aweserewny wy Exp. Name: Conversion of one datatype to another datatype S.No: 4 Date: 2023-11-24 im: Write a simple program that converts one given datatype to another using auto conversion. Take a double value from the user and convert it into integer and floating point datatypes. Note: Print the floating point value up to 2 decimal places. Source Code: typeconversion.¢ #includecstdio.h> Ant main() { double print#("Enter a value: "); scanf("K1#" 8a); Ant a Float a2=a; printf ("Value as an integer: Xd\n",1); printf("Value as a float: %.2F\n",a2)5 } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter @ value! 12345.67890 Value as an integer: 12345, Value as a float: 12345.68 Test Case - 2 User Output Enter @ value! 12 Value a5 an integer: 12 Value a 2 float: 12,00 ID: 927623BME040__ Page No: 6 MKumarasamy College of Engineering |2023-2027-B3. S.No: 5 Exp. Name: Solving Expression im: Write aC code to solve the expression as 3*2/3+5 Source Code: evaluate. Hinclude int main() { double result; J/ Evaluate the expression 75 // write your code here // Display the result result printf("Result: %.21f\n" result ); // write your code here Date: 2023-11-24 return 03 3 Execution Results - All test cases have succeeded! Test Case - 1 User Output Result 7.08 3g 2 3 g & = a 3 s 5 MKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write the code to find addition of two numbers S.No: 6 Date: 2023-11-24 Jenny's homework for the first day is to find the addition of two numbers, help jenny to solve the problem. Source Cod [ s0a.< | Hincludecstdio.h> int main() { Ant a,bs scanF("%d" Ba); scant("%d" 8b); print#("The addition of two numbers 1s: %d\n",a4b); } Execution Results - all test cases have succeeded! Test Case - 1 User Output 62 The addition of two numbers 4 Test Case - 2 User Output 759 624 The addition of two numbers is: 1989 ID: 927623BME040_ Page No: 8 MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write a program to find the total S.No: 7 Date: 2023-11-24 number of squares im: Problem Description: Tina's brother gave her a friendly task of calculating the number of squares in a board that has n*n squares of dimensions Tem *1cm each. Help her to find the number of total squares including all small and big ones. Constraints: +2 int main() { int nas scant ("%d",8n)5 a=n* (ne) *((2#n)#1)/65, print #("%d",); } Execution Results - all test cases have succeeded! Test Case - 1 User Output g 35 Test Case - 2 User Output 17 1785 ID: 927623BME040_ Page No: 9 MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write a program to find the quotient S.No: 8 Date: 2023-11-24 and remainder im: Problem Description: Nancy bought apples from a fruit shop, where the shopkeeper specified the bill amount. Nancy provided some money to the shopkeeper to pay the bill. Now, she would like to know the quotient and remainder after dividing the amount she gave by the bill amount specified by the shopkeeper. Can you help Nancy in finding it? Constraint : 5 < amount_givens 2500 5 bill amount < 2500 Input Format: The first line of the input consists of an integer representing the amount given by Nancy The second line of the input consists of an integer representing the amount specified by the shopkeeper Output Format: The first line of the output represents the quotient in integer format The second line of the output represents the remainder in integer format Source Cod billAmount Hincludecstdio.h> Ant main() { int ays scanf("%d" Ba); scant("%d",8n); print#("%d\n",a/n); print #("%d\n", akin); Execution Results - All test cases have succeeded! Test Case - 1 User Output 1800 56. 32 2 Test Case -2 User Output 1250 150, 2 927623BME040_ Page No: 10 1D: MXKumarasamy College of Engineering |2023-2027-B3. 50 LL:ON aBeg | OPOaINGEZIZZE ‘ai €4°2202"€202) Suuaeuj6ug Jo a6ayjo> Aweseiewny wy, Exp. Name: Write a program to find the volume of S.No: 9 Date: 2023-11-24 the ball im: Problem Description: Laasya bought a new volleyball in the sports shop. It looks medium-sized, She somehow found the radius of the sphere, But she would like to know the volume of that ball. Can you help her in finding the volume of the ball? Functional Description: Volume = (4.0/3.0) x m x r43 m=314 Constraint: 1.00 < radius < 5.00 Input Format : The input consists of a single float number representing the radius of the ball Output Format: The output consists of the volume of the ball Source Code: volumeOfBall.c Hincludecstdio.h> int main() { Float a,rs scanF("%F" 8); 4,0/3.0)"3.14¥r*r#n3 print#("%#",a)5 Execution Results - All test cases have succeeded! Test Case - 1 User Output 46 407.513367 Test Case -2 User Output 37 212.067230 927623BME040_ Page No: 12 1D: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 10 Exp. Name: Multiplication of two float values Date: 2023-11-24 Aim: Problem Descriptio {Arif came from a very low-income family. However, his father lrfan sent him abroad for the purpose of studying {if also concentrated well on his learning keeping in mind his father’s poverty. Arif was excellent in mathematics. ‘One day Arif had a computer class and his computer teacher asked him to create a programming logic for the mathematics problem of multiplying two numbers of type float. Can you help Arif with the logic? Constraints: + 1.00 < var < 1000.00 + 1.00 var2 < 1000.00 Input Format: The only line of input has two floating point numbers separated by space Output Format: In the only line of output print the result of the multiplication with 4 values after the decimal point. Source Code: multiplyTwoNums.c Hincludecstdio.h> int main() { float ain; scant("%F*, 8a); scant("%F" ,8n); print#("%.41F\n",a%n) Execution Results - All test cases have succeeded! Test Case - 1 User Output 412.2365 154.2136 63571.7266 Test Case - 2 User Output 784.2536 956.2487 7499415000 927623BME040_ Page No: 13 ID: MKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write a program to calculate the area S.No: 11 Date: 2023-11-24 of the Pyramid im: Problem Description: Jannu and Preethi both went to Egypt to visit the Pyramids. On seeing the Pyramids they were in discussion.During the discussion Jannu asked Preethi, what will be the area of this Pyramid Preethi has no idea about it. Can you help Preethi in calculating the area of this Pyramid? Functional Description Area = (height * base )/2 Constraints: 1 <= height <= 500 1< Input Format: ‘The only line of input has two floating point values representing height and base respectively separated by a space. ‘Output Format: In the only line of output print the area of the pyramid with only three values after the decimal point. Source Code: areaofPyrar Hincludecstdio.h> int main() { float a,b,¢3 scant ("RF 3", 8a,8b); atb)/25 print#("%.3F",¢); } in Results - All test cases have succeeded! Test Case - 1 User Output 31.5 43.7 688.275 Test Case - 2 User Output 176.3 120.6 10630,890 927623BME040_ Page No: 14 ID: MXKumarasamy College of Engineering |2023-2027-B3 Exp. Name: Print months in a year using switch case statement S.No: 12 Date: 2023-11-24 im: Write a € program to display month name according to the month number using switch case statement. Note: If the given input number is not in the range ie, other than 1 to 12, the output should be as “invalid month number" Source Code: DisplayMonth.c ‘ID: 927623BME040_| Page No: 15 MXKumarasamy College of Engineering |2023-2027-B3. Hincludecstdio.h> int main() { Ant month nos print#("Enter month nunber scanf("%d" ,nonth_no) ; switch(month_no) { return 05 case 1: print f("January\n"); break; case 2: print #("February\n"); break; case 3: print #("March\n"); break; case 4: print#(“Apri\n"); break; case 5: print #("May\n"); break; case 6: print #("June\n"); break; case 7: print #("July\n"); break; case 8: print f(“August\n") ; break; case 9: print ("September\n"); break; case 10: print f(“October\n"); break; case 11: print #(“Novenber\n"); break; case 12: print #("December\n"); break; default print#("Invalid month number\n"); break; ‘ID: 927623BME040_| Page No: 16 Execution Results - all test cases have succeeded! Test Case - 1 MKumarasamy College of Engineering |2023-2027-B3 User Output Enter month number + 1 January Test Case - 2 User Output Enter month number u Novenber Test Case - 3 User Output Enter month number 13 Invalid month number Test Case - 4 User Output Enter month number 9 Septenber Test Case - 5 User Output Enter month number + 4 ‘april Test Case - 6 User Output Enter month number + 2 February Test Case -7 User Output Enter month number + 8 ‘August 927623BME040_ Page No: 17 ID: MXKumarasamy College of Engineering |2023-2027-B3. Test Case - 8 User Output Enter month number 6 Bune Test Case - 9 User Output Enter month number + 12 Decenber Test Case - 10 User Output Enter month number + 0 Invalid month number Test Case - 11 User Output Enter month number + 7 auly 927623BME040_ Page No: 18 ID: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 13 Exp. Name: sum of n non-negative numbers Date: 2023-11-24 ‘Write a C program to find the sum of n non-negative numbers entered by the user. Source Code: sur jonnegative.c Hincludecstdio.h> int main() { Ant n,b,=85 scanF("%d" ,8n); printf("Enter ¥d Numbers: ",n); for(int e1sicensie+) { scanf("%d" @b) 5 4 (038) t cobs } ) peint#("Sum = Xd\n",c)5 + in Results - All test cases have succeeded! Test Case - 1 User Output 5 Enter 5 Numbers: 1234-7 Sun = Test Case - 2 User Output 7 Enter 7 Numbers: “3-2-4-5101112 Sun = 33 927623BME040_ Page No: 19 ID: M.Kumarasamy College of Engineering |2023-2027-B3 Exp. Name: Write a € program to calculate whether S.No: 14 i Date: 2023-11-24 a given number is Palindrome or not Design and develop an algorithm to find the reverse of an integer number and check whether itis Palindrome or not Implement a € program for the developed algorithm that takes an integer number as input and output the reverse of the same with suitable messages. At the time of execution, the program should print the message on the console as: Enter an integer : For example, if the user gives the input as: Enter an integer : 2014 then the program should print the result as: The reverse of a given number : 4102 2014 is not a palindrome Ifthe input is given as 1221 | then the result should be: The reverse of a given number : 1221 1221 is a palindrome Source Code: 927623BME040_ Page No: 20 1D: MXKumarasamy College of Engineering |2023-2027-B3. include int main() t int n,145+8,t3 print#("Enter an integer : "); seanf("¥a"8n)3 tens print#("The reverse of a given number while(n>@) { pankL@s sestlosns nen /2105 ) print #("%d\n",s); iF(tess) print#(°%d is a palindrome\n",t); printt(“Kd {s not a palindrone\n",t); In Results - All test cases have succeeded! Test Case - 1 User Output Enter an integer + 2014 The reverse of a given number + 4102 2014 is not a palindrone Test Case - 2 User Output Enter an integer 1221 The reverse of a given number + 1221 1221 is a palindrone 927623BME040_ Page No: 21 ID: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 15 Exp. Name: Fibonacci series Date: 2023-11-24 im: Write a C program to print the Fibonacci series ie. 0112358 13 21... up to the limit given by the user Hint: By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. Source Code Programi4.c Hincludecstdio.h> int main() { int a,b,n3 int nefits; print#("Enter the maximum limit to generate the Fibonacci series scant("%d", 8b); print#( for(int i { he Fibonacci series is : %d Xd",f,s); sAc=bsie+) print#(" %4",n)s efess if(n>) ( printf("\n"); break; Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter the maximun Limit to generate the Fibonaccl series 10 The Fibonacci series is: 0112356 Test Case - 2 User Output Enter the maximun Limit to generate the Fibonacci series 6 The Fibonacci series is: 011235 ‘ID: 927623BME040 | Page No: 22 MKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write @ C program to find whether the S.No: 16 . Date: 2023-11-24 given number is Armstrong or not Write a sample code to check whether the given number is an | arastrong number) or not. [Hint: An arnstrong nunber’ is a number that is the sum of its own digits each raised to the power of the number of digits For example, 9=9'=9 371 = 32 +7 + 1? = 27 +343 +1 = 371 8208 = 84 + 24404 + Bf = 4096 + 16 + 0 + 4096 = 8028] At the time of execution, the program should print the message on the console as: Enter any number : For example, if the user gives the input as: Enter any number : 153 then the program should print the result as: The given number 153 is an armstrong nunber Similaty, if the input is given as 121 then the output should be "The given number 121 is not an armstrong number Note: Do use the printf() function with a newline character ( \n ) at the end. Source Code Programa10 927623BME040_ Page No: 23 ID: MKumarasamy College of Engineering |2023-2027-B3. Hincludecstdio.h> includecmath.h> int main() { int nun,al, rem, float result= print#("Enter any number : *); scanf("Xd" num) ; a=nun; for(at=nunjai!=@;n++) { at/=105 } for(alsnum;a1!=0;a1/=10) { ren=al%10; result+=pow(rem,n); } 4f((Ant)result==num) printf("The given number %d is an armstrong number\n" nun); else printf("The given nunber Xd is not an armstrong nunber\n" num); return @; + Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter any number = 370 The given number 370 is an arwstrong number Test Case - 2 User Output Enter any number 1824 The given nunber 1824 1s not an armstrong number Test Case - 3 User Output Enter_any number: 5 The given nunber 5 is an armstrong nunber Test Case - 4 927623BME040_ Page No: 24 1D: MXKumarasamy College of Engineering |2023-2027-B3. User Output Enter any number + 1634 The given number 1634 is an armstrong number 927623BME040_ Page No: 25 ID: M.XKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write the C program to find the S.No: 17 ° Date: 2023-11-24 Factorial of a number. im: Write a program to find the Factorial of a non-zero positive integer n, denoted by nl, where factorial is the product of all positive integers less than or equal to n, For example, 51=5*4*3*2*1= 120 Note: + For negative values factorial cannot be calculated, so print “Invalid” Constraints: -10 <= n <= 10 Instruction: To run your custom test cases strictly map your input and output layout with the visible test cases. Source Code: Hincludecstdio.h> int main() { int printé(*Num: *); scanf("%d",n) 5 if(nco) print ("Invalid"); for(int te1;icensi++) { Freis ) prant®(“Factorial: 2", #)5 Execution Results - all test cases have succeeded! Test Case - 1 User Output Nan: 9 Factorial: 262880 Test Case -2 User Output rt 927623BME040_ Page No: 26 ID: M.Kumarasamy College of Engineering |2023-2027-B3. L2:0N aed | OPORINGEZILZE “ai Factorial: 1 Test Case - 3 User Output 10 Invalid an €8-1Z02°EZOZ!_ GuiaauiGuy yo a6ayj0> Aweserewny wy S.No: 18 Exp. Name: Triple of numbers Date: 2023-11-24 Aim: Problem Description: Johny is very enthusiastic about programming languages. One day he tried to write a program to find a triple of numbers. A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers. Help Johny to write the code. You will be given three integers A, B, and C. Constraints: 1<= AB andC <= 50 Input Format: Only line of input has three integers A B C separated by a space. Output Format: Print the output in a single line, Ifthe given triple is poor, print Yes; otherwise, print No. Source Code: triple. Hincludecstdio.h> int main() { int a,b,¢3 scanf("kd d 8d",&a,8b, 8c); Af(ae=bBgal=c) i printf("Yes"); } else if(asscléa!=b) ‘ printf("ves")3 } else iF(b: ‘ printf("ves"); } else print#("No"); } } Execution Results - All test cases have succeeded! Test Case - 1 User Output 23 1834 No ‘ID: 927623BMEO40 | Page No: 28 MKumarasamy College of Engineering |2023-2027-B3. 62:0N a6eg | OPOaINGEZIZZE ‘ai Test Case -2 User Output 39 28 39 Yes €4°2202"€202) Suuaeui6ug Jo a6ayjo> Aweserewny wy, Exp. Name: Write a program to find the profit and sno: 19 be. Program tofind he profit and os agp3-1.24 im: Problem Description: In primary mathematics classes, you all have learned about profit and loss. If cost price is greater than selling price, then there is a loss otherwise profit Can you kindly automate the same? Constraints: 1000scp45000 1000ssp45000 Input Format: First Line : Integer representing the Cost price Second Line: Integer representing Selling Price ‘Output Format: If Cost Price > Selling Price Print a “Loss” along with the amount of loss If Cost Price < Selling Price Print as “Profit” along with the amount of profit If Cost Price = Selling Price Print “No Profit No Loss’ Source Cod profitLoss Hincludecstdio.h> int main() t int a,b5 scanf("Kd\nkd" ,8a,86) 5 iF(acb) ‘ printf("Profit: ¥d",b-a); } else if(a>b) ‘ print#(“Loss: %4",a-b); ) else printf("No Profit No Loss"); } + Execution Results - All test cases have succeeded! Test Case - 1 User Output 15945 13785 927623BME040_ Page No: 30 1D: MXKumarasamy College of Engineering |2023-2027-B3. Loss: 2160 Test Case - 2 User Output 268232 28513 Profit: 1681 Test Case - 3 User Output 100 300 No Profit No Loss 927623BME040_ Page No: 31 1D: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 20 Exp. Name: Write a program to find the N pages Date: 2023-11-24 Aim: Problem Description: Tharun wants to print a document with "N" pages double-sided, where two pages of data can be printed on one sheet of paper. Can you tell him how many sheets of paper he needs to print N pages? Constraints: +1 int main() t int 93 scanf("Kd",8n); Af(n/2e"0) ‘ print #(“éd ) else( print("%d",n/2+4)5 } + Execution Results - All test cases have succeeded! Test Case - 1 User Output 189 35 Test Case - 2 User Output 567 284 927623BME040_ Page No: 32 1D: MXKumarasamy College of Engineering |2023-2027-B3. Exp. N it Ae xp. Name: Write a program to find the difference. ay3 44 94 between speeds im: Problem Description: ‘Arav and Aaron are patticipating in the Bike racing, Arav crossed some milestones earlier and Aaron crossed some milestones earlier during their racing because they have changed their speeds at different times. Both of them like to know the difference in speeds between them at different stages of racing. Can you help find the speed difference between Arav and Aaron? Constraints 20s aravspeed <100 20s aaronspeed <100 Input Format: The first line of input represents the speed of Arav. The second line of input represents speed of Aaron. Output Format: Print difference between the driving speed of two participants in a single line Source Code: speed Hincludecstdio.h> int main() { int a,b; scanf("Xd", 8a); scant("%d" , 8b); if(a>b) printé("éd",a-b)5 else print*("éd",b-a)5 } Execution Results - All test cases have succeeded! Test Case - 1 User Output 74 51 23 Test Case - 2 User Output 76 927623BME040_ Page No: 33 ID: MKumarasamy College of Engineering |2023-2027-B3 89 3 ve -ON a6eg | OPOIWTEZIZZE ‘al €8-LZ02-EZOZ! Suvi2eus6uy yo aGajjop Awesesewny yy S.No: 22 Exp. Name: Represent the currency value. Date: 2023-11-24 Aim: Problem Description: Paytm announced a Cashback offer for the people of Tamil Nadu which is a one-time offer for the new year-But to avail of the Cashback users need to pass the simple tasks given by Paytm, One such task given by Paytm is to ccheck the nature of the currency value provided by Paytm. Constraint: 1 <= currency <= 20000 Functional Description: ‘One more condition imposed by Paytm is that participants need to do this checking using the concept of Operators. Input Format: Only the Line of input has a single value of type integer representing the currency value, Output Format: ‘The output format will be a string indicating whether the input currency is even or odd. Source Code: currency. Hincludecstdio.h> int main() t int a3 scanf("%d" 8a); Af (ak2==0) print#("Even Currency"); else print#(“Odd Currency"); + Execution Results - all test cases have succeeded! Test Case - 1 User Output 1985 1985 is 04d Currency Test Case - 2 User Output 1642 3642 15 Even Currency 927623BME040_ Page No: 35 ID: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 23 Exp. Name: Store and print numbers using array Date: 2023-11-24 Write a program to accept n numbers in an array and display it Source Code: printNumbers.c Hincludecstdio.h> int main() { int ny 45 print#("How many numbers do you want to enter: "); scant("%d" Bin); Ant arr(n]s print#("Enter Xd numbers: ",n); For(i=0;icnsi++)( seanf("Xd" ,Barr(4]); } printf("Entered nunbers are: For(i=05icn;i++)( printf" d",are[1])5 } printf(*\n"); } Execution Results - All test cases have succeeded! Test Case - 1 User Output How many numbers do you want to enter: 5 Enter 5 numbers 246810 Entered numbers are: 246 8 10 Test Case - 2 User Output How many numbers do ‘you want to enter: 10 Enter 1@ numbers 12345678910 Entered numbers are: 12345678910 927623BME040_ Page No: 36 1D: MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: € program to find the largest and the S.No: 24 smallest of some numbers given by the user using Date: 2023-11-24 arrays. Aim: Write the ¢ program to find the largest and the smallest of some numbers given by the user using arrays Source Code SmallLarge Hincludecstdio.h> Ant main() { int ny 45 printf(“Enter no.of elenents: "); scant("Xd" 8); int aren for(1=1; Leensit+){ print f(“Enter element Xd: "); seanf("%d",Rarr[i]) 5 } Ant largest = aren]; int smallest = arr[n]; for(i sens i+4)( if(arr[4] > largest){ largest = arr[i]; } if(arr[i] < smallest) smallest = arr[i]; } printf("Largest elenent: %d\n", largest); print#("Smallest element: %d\n", smallest); Execu in Results - All test cases have succeeded! Test Case - 1 User Output Enter no.of elenents: 6 Enter element 1) 48 Enter element 2: 59) Enter elenent 3: 68. Enter elenent 4: 85, Enter element 5: 927623BME040_ Page No: 37 1D: MXKumarasamy College of Engineering |2023-2027-B3. 69. Enter elenent 6: 75 Largest elenent: aS Smallest elenent: 48 Test Case - 2 User Output Enter no.of elenents: 5 Enter element 1) 15, Enter element 2: 26 Enter element 3) 35 Enter element 4: aT Enter elenent 5: 59) Largest elenent: 59 Smallest elenent: 15 927623BME040_ Page No: 38 1D: MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write a program to count the number of increasing subsequences Date: 2023-11-24 Given an array arr(} containing n integers. Write a C program to count the number of increasing subsequences in the array of size k Constraints: «size < 50 -1000 < element < 1000 Input Format: The first line reads an integer representing the size of the array. The next line reads space-separated integers representing the elements of the array. The next line reads an integer representing the value of k Output Format The output is an integer representing the count of increasing subsequences in the array. Note: Elements of the subsequences need not be consecutive. Source Code subsequences.c 927623BME040_ Page No: 39 ID: MXKumarasamy College of Engineering |2023-2027-B3. #includecstdio.h> Ant hoe(int are{],int n,int k) c Ant dp{n][k]s for(int i=0;icnsitt){ for(int ck 54) pli) {4}=05 i) y for(int i-@;icnsie+){ pli] (0]=13 } for(int i=1;icnsi++)( for(int ja1sjcksJo+){ for(int mOsmeisme+){ Af(arr[i}>are[m]) dpla}{d}+=4p(m) [5-115 } } int result=0; for(int in0;icnsie+){ result+=dp(i][k-1]; y return result; int main() { Ant resultsn,ks int arr[50]; print#(“Enter the size: seanF("%d" Bn); print#("Enter the elements for(int 1=0;icnsi++){ scanF("%d" ,Barr(i]); + printf(“value of k scanF("%d", 8k); result=hoe(arr,n,k print#("Result: Xd Execution Results - all test cases have succeeded! Test Case - 1 User Output Enter the size: 5 Enter the elements: 1230-1 value oF ki 3 927623BME040_ Page No: 40 1D: M.Kumarasamy College of Engineering |2023-2027-B3. Test Case - 2 User Output Enter the size: 5 Enter the elenents: 1011121315, value of Kk. 3 Result: 10 927623BME040_ Page No: 41 1D: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 26 Exp. Name: Split the string Date: 2023-12-12 Aim: Write a C program to split and print the string based on blank space. Source Code: splitstrin Hincludecstdio.h> Hincludecstring.h> int main() { char stra[108] ; char newstring[10][10]; int Ld,etes scanf("X[*\n]*c", str); stelen(str1)) 314+) if(strt[ i] ( newstringfete][J]="\8"s tress } else newstring[ctr][j]=strt[4]5 iets } } for(i-9;icctrsit+) print #("%s\n" newstring[i])5 return @; Execution Results - All test cases have succeeded! Test Case - 1 User Output Hello world! Hello workd!! Test Case - 2 User Output This is a C program This is 927623BME040_ Page No: 42 1D: MXKumarasamy College of Engineering |2023-2027-B3. program Ev ON a6ed | OPORINGEZILZE ‘ai €8-1Z02°EZOZ!_ GuiaauiGuy yo a6ayj0> Aweserewny wy S.No: 27 Exp. Name: Find the total number of words Date: 2023-12-12 Aim: Write a C Program to perform the following operations on a given paragraph using built-in functions + Find the total number of words Source Code: total_word: Hincludecstdio.h> #includecstring-h> Hineludecctype.h> int main() { char sentence [100]; int Wordcount = 5 printf(“Enter a paragraph: “); scanf("X[*\n}*c", sentence); for(int i = @; i < strlen(sentence)-1; i++) { if(sentence[{] == * * && isalpha(sentence[is1]) @& (438)) { wordcount++5 ) } wordcount++s print#("Total words: %d\n", wordcount); return @5 } Execution Results - all test cases have succeeded! Test Case - 1 User Output Enter @ paragraph Hi Hello good morning! Total words: 4 Test Case - 2 User Output Enter a paragraph Twinkle Twinkle little star, how i wonder what you are, up above the world so high, Total words: 16 927623BME040_ Page No: 44 ID: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 28 Exp. Name: Capitalize the first word Date: 2023-12-12 Aim: Write a C Program to perform the following operations on a given paragraph using built-in functions + Capitalize the first word of each sentence Source Cods capitalize Hincludecstdio.h> define MAX 100 int main () { char str[MAX}=(0}; int 43 printf(“enter a paragraph: “); seanf("X[*\a]s", str); 5 str[i]!="\o" sit+) { a¢((str[4] ak str[i]<='2"))ste[i]=str[i]-325 continues //if(ste[i]>='a" && str[i]<="2") mK U/ste(i}=ste(i]-325 uy ) else £ 4¢(str[1]>="A" 88 str[i]ce'Z" )ste[d]=str[1]+325, i y print#("Capitalizing first word:\n%s\n",str); J/printf(°%s\n", str); return 5 y Execution Results - all test cases have succeeded! Test Case - 1 User Output Enter_@ paragraph this is C programming Capitalizing First word: This is © progranming 927623BME040_ Page No: 45 1D: MXKumarasamy College of Engineering |2023-2027-B3. Test Case -2 User Output Enter_a paragraph: roses are red and violets are blue Capitalizing first word: Roses are red and violets are blue 927623BME040_ Page No: 46 1D: MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Replace a given word with another S.No: 29 me Date: 2023-12-12 Write aC Program to perform the following operations on a given paragraph using built-in functions + Replace a given word with another word Source Code replace.c include include void replaceWord(char *paragraph, const char toldlord, const char *neviiord) { char *pos, tenp[ 1000]; int index = @, oldlordLen = strien(oldWord); while ((pos = strstr(paragraph, oldWord)) != NULL) t strnepy(temp, paragraph, pos - paragraph); temp[pos - paragraph] = "\@"; strcat (temp, newdord); strat (temp, pos+ oldWordLen); strepy(paragraph, temp); index += pos - paragraph + strlen(newWord) ; paragraph += index; a) } int main() { char paragraph [1080]; char olddord[5e], newkiord [50]; print#("Enter a paragraph: "); fgets(paragraph, sizeof(paragraph), stdin); printf("word to replace: "); scanf("%s", oldword); print#("new word: "); scanf("%s", newiord) ; print (“Original Paragraph: %s", paragraph); replaceWord (paragraph, oldWord, newsord); print f("After replacing: Xs", paragraph); return 05 Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter a paragraph: Roses are pinkviolets are blue. word to replace: pink new word: red. (Original Paragraph: Roses are pink, violets are blue. 927623BME040_ Page No: 47 1D: MXKumarasamy College of Engineering |2023-2027-B3. ‘After replacing: Roses are red,violets are blue. Test Case - 2 User Output Enter a paragraph This is a C programming structure. word to replace structure new word: language Original Paragraph: This is aC progranming structure After replacing: This is a C programing language. 927623BME040_ Page No: 48 ID: MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Absolute difference between any two S.No: 30 Date: 2023-12-13, consecutive integer Elon Musk has given an array of integers of size N and he has to find out if the absolute difference of values of any two consecutive array integers is at most D. Constraints: H1 Hincludecstdlib.h> char*check_absolute_difference(int arr{],int n,int d){ for(int 1=0;i¢n-13i+4){ 4f(abs (are( i) -arr[i+1])<=4){ return "YES"; } } return "No"; } int main() { int nds scanf ("Kd %d",8n, 84); int arr(n]; for(int i=@;4ens1+4){ scanf("%d" Barr[i]) 5 } chartresult=check_absolute_difference(arr,n,d); printf(%s\n" result); } Execution Results - all test cases have succeeded! Test Case - 1 User Output 74 117 1821 32.45 52 927623BME040_ Page No: 49 ID: MXKumarasamy College of Engineering |2023-2027-B3. YES Test Case - 2 User Output su 19 23 45 65 95 YES Test Case - 3 User Output 561 221-412 326 951 548 NO 927623BME040_ Page No: 50 ID: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 31 Exp. Name: Array Right Rotation by K Steps Date: 2023-12-13, Fazil loves to preform different operations on arrays, and so being the Head of the higher education institution, he assigned a task to his new student Bazil Bazil will be provided with an integer array A of size Nand an integer K,, where she needs to rotate the array in the right direction by steps and then print the resultant array. ‘As she is new to the school, please help her to complete the given task. Constraints: t1 void rotatearray(int arr{],int n, int k){ kekginj int templk]; for(int isn-k, templs } for(int i: } for(int sn@5icks144)4 arr[i]=temp( i]; y } int main(){ int a,b,are[a]; scanF("%d %d",8a,8b); arrfal; for(int i@;icasive){ scanf("%d" ,Barr(i]); sdensite, 5H) reals -1y bok i--)4 arr[i]=arr[S-k]3 } rotatearray(arr,a,b); for(int s=0;i Ant main() { int arr[3]03]5 for(int 4-051<351+4){ for(int. 3=0;5<353++){ seanf("Nd" @arr(4](41)5 ) int er(@] {@}+are [8] [2]+arr(1]{1]+arr(2}[@}+arr(2] [2] int c-arr[0][1]+arr[1] [@]+arr(1][2]+arr(2](1]5 print ("%d\nkd\n" 5b, €)5 } Execution Results - all test cases have succeeded! Test Case - 1 User Output 11.12 15 36 95 84 74 115 172 367 247 Test Case - 2 User Output 958476231274 58 927623BME040_ Page No: 53 1D: M.Kumarasamy College of Engineering |2023-2027-B3. a1 SON a6ed | OPOaINGEZILZE “ai €4°2202"€202) Suuaouj6ug Jo a6ayjo> Aweseiewny wy, Exp. Name: Write the code to identify the element S.No: 33 , Date: 2023-12-14 of array which occurs most frequently. Question description: Simon is studying B:Tech-Mechanical Engineering, He's going to attend a computer science-based subject exam this semester. Due to the less preparation in the previous monthly tests)his intemal marks are decreased His ‘computer science Professor made an offer one more chance to boost up his internal marks: Professor assigns a program to Simon for the internal mark boost up.So Simon wants to identify the element of the array which occurs most time in the array. Can you help him? Function Description: ‘Sample Input: 9 121214512 ‘Sample Output: 1 Explanation: + Toccurs 4 times + Zoccurs 3 times +A occurs 1 time +S occurs 1 time So, the output is 1. Constraints: O int main() { int a3 scanf("%d",8a)5 int arr[a] for(int scanf("Xd",@arr[i]); y int maxcount=0; int mostfrequentelenent = arr[@]; for(int & int currentelenent=arr[i]; int currentcounte1; for(int j=itlsjcasie+){ Af(arrL3 } urrentelement){ currentcount+5 if (currentcount>maxcount){ maxcount=currentcount; most frequentelenent=currentelenent; ) ) paint #("%d\n" mostfrequentelenent); } Execution Results - All test cases have succeeded! Test Case - 1 User Output 2 436975412 a Test Case - 2 User Output 10 3369852143 3 927623BME040_ Page No: 56 ID: MKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write the code to solve the given S.No: 34 ‘ Date: 2023-12-14 question. Question description: Issac is a Language teacher at a high school in Madurai Sabari is a student, he is studying programming during Language class.\ssac tells Sabari to leave the other subject and learn Tamil Sabari asked permission for 10 minutes, Finally, Sabri got permission to solve the program, ‘The computer teacher has given homework on the topic of Arrays andwhere he needs to do Array Rotation as per the input of the question. But Sabari is not good at C Programming.Can you help him to solve the programming problem? Constraints: 0 void rotateleft(int arr[], int n,int rotations){ int temp; for(int 1x0; icrotations;i++){ tenp=arr[@]; for(int j = @:Jen-23j++){ are(]=are[J+4]3 i) arr[n-t]=tenp; y } void rotateright(int arr(],int n,int rotations){ Ant tem for(int ;Lcrotations;1++){ tenp=arr[n-1]5 for(int 4=1 arr(3 §>055- y arr[@]=temps } } Ant main() { int n rotations; char direction; scanF("%d" in); int arr(n}3 for(int i: scanf("%d" Barr[i])5 } scanf("Kd" rotations); scanf(" %c",Adirection) ; Ly rotateleft(arr,n,rotations); if(directior } else if(direction are rotateright(arr,n,rotations); } for(int i= Osicnsiet){ print®("%d "arr(i])5 y Execution Results - All test cases have succeeded! Test Case - 1 User Output 5 12345 4 L 51234 927623BME040_ Page No: 58 ID: MXKumarasamy College of Engineering |2023-2027-B3. 65:0N a6eg | OPOaINGEZIZZE ‘ai Test Case -2 User Output 10.11 12 13 1415 16 FERTECECECETET! €4°2202"€202) Suuaeuj6ug Jo a6ayjo> Aweseiewny wy, S.No: 35 Exp. Name: Problem Solving Date: 2023-12-14 Ai Write a € program to find the maximum of 3 numbers using functions. Input and Output Format: Input consists of 3 integers. Refer sample output for formatting details. Sample Input and Output: Enter three numbers : 9 99 49 99 is the largest among three numbers Source Code maximumOfNum. ¢ Hinclude #include "maximunoflumt..c™ int largest(int x, int y, int 2)5 void main() ¢ int xy, 2, maxz printf("Enter three nunbers : "); scant ("%d¥dxd", &x, By, &2)5 print#("Xd is the largest among three nunbers\n" largest(x, y, z))3 maximumOfNumd .¢ Hincludecstdio.h> Ant largest(int a,int b, int ¢){ iF(arb B& arc) return a; else if(b>c) return b; else return ¢3 } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter three numbers 1111099 Lid is the largest anong three numbers Test Case - 2 927623BME040_ Page No: 60 AD: MKumarasamy College of Engineering |2023-2027-B3. User Output Enter three numbers 25 37 48 48 is the largest among three nunbers 19:0N aBeg | OPOAINEZIZZE ‘ai €4°2202"€202) Suuaauj6ug Jo a6ayjo> Aweseiewny wy, S.No: 36 Exp. Name: sum of digits of the largest number Date: 2023-12-14 Aim: Write a C program to print the sum of digits of the largest number from the given set of 4-digit numbers Source Code: f_digits Hincludecstdio.h> int main() { Ant cos print#("count of 4-digit numbers: "); scanf("%d" co) ; Ant largen = -45 int sumofdigit = @; for(int 4 =9;iccosi++) { int nj print f("Enter number Xd: ",i+1)3 scanf("%d" in); AF(n>=1008 @& n<=9999) { Af(n > largen) { largen } } else( print#(“Enter a valid 4-digit nunber\n"); + ) int t= largen; vwhile(t!=0)¢ sunofdigit+=tt10; t /=10; } print#("largest number: %d\n",largen); printf(“sum of its digits: %d\n", sumofdigit); } Execution Results - All test cases have succeeded! Test Case - 1 User Output count of 4-digit nunbers: 3 Enter number 1: 1234) Enter number 2: 927623BME040_ Page No: 62 1D: MXKumarasamy College of Engineering |2023-2027-B3. 3456 Enter number 3: 4000 Largest number: 4000 sun of its digits: 4 Test Case - 2 User Output count of 4-digit nunbers: 4 Enter number 1: 1100 Enter number 2: 200 Enter a valid 4-digit nunber Enter number 2: 2000) Enter number 3: 3000 Enter number 4 99999 Enter @ valid 4-digit nunber Enter number 4: 19999 argest_number: 9999 sun of its digits: 36 927623BME040_ Page No: 63 1D: MKumarasamy College of Engineering |2023-2027-B3: S.No: 37 Exp. Name: Area of the circle Date: 2023-12-14 Aim: Write a C program to find the area of the circle using call-by value and call-by reference. Note: + Take the pi value as 3.14. + Print the result up to 2 decimal places. + The driver function is provided to you in the editor. Hincludecstdio.h> float areaCal l8yvalue(float r){ return 3.14%#n3 i) float areaCallByReference(float r, double*a){ sas3.1dtrtn; int main() { double radius, area; print#("radius: "); scanf("Z1f", Bradius); // Calculate the area using call by value double areaByValue = areaCal1ByValue(radius); print#("Area(Call by value): %.2f\n", areaByValue) ; J/ Calculate the area using call by reference areaCal1ByReference(radius, Barea); printf("Area(Call by reference): %.2f\n", area); return 0; Execution Results - All test cases have succeeded! Test Case - 1 User Output radius: 7 ‘Area(Call by value): 153.86 ‘Area(Call by reference): 153.86 Test Case - 2 User Output radius 927623BME040_ Page No: 64 1D: M.Kumarasamy College of Engineering |2023-2027-B3. 82 21.13 ‘Area(Call by value) 211.13 ‘Area(Call by reference): 99:0N a6ed | OPOaINGEZILZE “ai €4°2202"€202) Suuauj6ug Jo a6ayjo> Aweseiewny wy, Exp. Name: Write a C program to find the Factorial S.No: 38 . A ° Date: 2023-12-14 of a given number using Recursion im: Write a program to find the factorial of a given number using recursion process, Note: Write the recursive function factorial() in [email protected] Source Cods Programoo1 #include include "[email protected]” void main() ¢ Jong int ns printf(“Enter an integer : "); seanf("Kd", &n)3 printf ("Factorial of ld is : Xld\n", n ,factorial(n)); Program90i include int factorial (num){ 4F(num==@| |nun==1){ return 43 } else return nun+factorial(nun-1); } } Execution Results - All test cases have succeeded! Test Case - 1 User Output Enter an integer = 5 Factorial of 5 is: 120 Test Case - 2 User Output Enter an integer 4 Factorial of 4 is: 24 |ID: 927623BMEO40_| Page No: 66 MXKumarasamy College of Engineering |2023-2027-B3. Test Case - 3 User Output Enter an integer + 8 Factorial of 8 is : 40320 Test Case - 4 User Output Enter an integer: 0 Factorial of @ is 927623BME040_ Page No: 67 1D: MXKumarasamy College of Engineering |2023-2027-B3. Exp. Name: Write a C program to display the S.No: 39 Fibonacci series up to the given number of terms Date: 2023-12-14 using Recursion Aim: Write a program to display the Fibonacci series/ up to the given number of terms using recursion process. The fibonacci series is @ 11.2.3 5 8 13 21 34 Note: Write the recursive function fibQ in Fibonacci. Source Code include include "fibonaccit.c void main() { int n, 43 print#("Enter value of n scanf("d", &n); print#( for (i he Fibonacci series of ¥d terms are 5 i < m5 ive) { print #(" Xd", #ib(i)); ads fibonaceit Hincludecstdio.h> int fib(int n){ int a=,b=1,¢5 return a3 else if(n! return b; else{ for(int i=@sicensit+)( coatb; AF (4e=n-2) return ¢3 ) y Execution Results - All test cases have succeeded! Test Case - 1 ‘ID: 927623BME040 | Page No: 68 MKumarasamy College of Engineering |2023-2027-B3: User Output Enter value of ni 4 The Fibonacci series of 4 terms are e@ii2 Test Case - 2 User Output Enter value of n 8 The Fibonacci series of @ terns are @ii235 8 13 User Output Test Case - 3 Enter value of n 14 The Fibonacci series of 14 terms are (eles eon 3 Sls ests isto aos moo 148181295) Test Case - 4 User Output Enter value of ni 3 The Fibonacci series of 3 terms are: @ 1 7 927623BME040_ Page No: 69 1D: MXKumarasamy College of Engineering |2023-2027-B3. S.No: 40 Exp. Name: To access elements using a pointer Date: 2023-12-14 Write a program to access the array elements using a pointer. Source Code pyramid.c Hinclude int main() { int x printf ("Enter the size of elements seanf("Kd", 8x); int arrayi[x] print#(“enter elements: "); for(int £= 0; 1< x5 i4#){ scanf("Xd", 8arrayi[i])3 y printf("Accessing the elements using the pointer: \n"); for(int i= @5 i < x3 it+){ printf("Xd\n", *(arrayl + 1))5 y return 05 Execution Results - all test cases have succeeded! Test Case - 1 User Output Enter the size of elenents: 5 Enter elenents: 12345 ‘Accessing the elenents using the pointer: Test Case - 2 User Output Enter the size of elements 4 Enter elements 40 3010 20 ‘Accessing the elenents using the pointer 40 927623BME040_ Page No: 70 ID: MXKumarasamy College of Engineering |2023-2027-B3.

You might also like