




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Btech 1 St year lab manual programming lab in c language
Typology: Papers
1 / 103
This page cannot be seen from the preview
Don't miss anything!





























































































Theme: General Programs Program No: 1 Objective: Write a program to calculate the area of triangle using formula at=√s (s- a) (s-b) (s-c) Logic Given a triangle with side lenths a, b and c. Then is area can be calculated as==√s (a+b+c)/2where s=(a+b+c)/ Example: If the input is: a = 3. b = 5. c = 7. Triangle area = 6. Algorithm:
area= sqrt(s(s-a)(s-b)*(s-c); print(“ Area of the triangle %f”, area); getch(); Output Window :
getch(); } Output Window:
Program No: Objective: Write a program to determine the roots of quadratic equation. Logic: The general form of a quadratic equation is (ax^2 + bx + c = 0). The formula to find the roots of a quadratic equation is given as follows x = [-b +/- sqrt (-b^2 - 4ac)]/2a The discriminant of the quadratic equation is d= (b^2 - 4ac). Depending upon the nature of the discriminant, the roots can be found in different ways.
real_part = - b/2a; imag_part = sqrt(-discriminant)/2a; printf(First root of the equation is %lf+%lf”, real_part, imag_part); printf(Second root of the equation is %lf-%lf”, real_part, imag_part); getch(); } } Output Window :
Program No: Objective: Write a program to find the largest of three numbers using nested if else Logic: Given three numbers A, B and C The task is to find the largest number among the three. Input: A = 2, B = 8, C = 1 Output: Largest number = 8 Input: A = 231, B = 4751, C = 75821 Output: Largest number = 75821 Algorithm:
Program No: 3 Objective: Write a program to receive marks of physics, chemistry & maths from user & check its eligibility for course if a) Marks of physics > 40 b) Marks of chemistry > 50 c) Marks of math’s > 60 d) Total of physics & math’s marks > 150 or Total of three subjects marks > 200 Logic: Take the marks of Physics , Chemistry and Math from user Case1: if Marks of Physics > Case2: if Marks of Chemistry > Case3: if Marks of Math > Case 4: if Addition of Physics and maths marks > Case5: if Addition of Physics , chemistry and Maths> If all five cases are satisfied then candidate is eligible. Algorithm:
int physics, chemistry, maths, total1,total2; clrscr(); printf(“ Enter the marks of Physics”); scanf(“%d”, & physics); printf(“ Enter the marks of Chemistry”); scanf(“%d”, & chemistry); printf(“ Enter the marks of Maths”); scanf(“%d”, & maths); toatl1=physics+maths; total2=physics+chemistry+maths; if(physics>40) if(chemistry>50) if(maths>60) if(total1>150|| total2>200) printf(“ Applicants is eligible for admission”); else printf(“ Applicants is not eligible for admission”); else printf(“ Applicants is not eligible for admission”); else printf(“ Applicants is not eligible for admission”); else printf(“ Applicants is not eligible for admission”); } getch() }
Program - 4 Objective: Write a program to find the value of y for a particular value of n. The a, x, b, n is input by user (switch) if n=1 y=ax%b if n=2 y=ax2+b if n=3 y=a-bx if n=4 y=a+x/b Logic: Use the switch feature to choose one condition from multiple condition. Case 1: n=1, calculate using formula y=ax%b Case2: n=2 calculate using y=ax2+b Case3: n=3 calculate using y=a-bx Case 3 n=4 calculate using y=a+x/b Example: Input: If a=5, b=1, x=1, n= Output=4.0 beacause as n=3 case 3 will be executed as y=a-bx=5-1*1= Algorithm:
scanf("%d",&b); printf(" Eneter the value of x\n"); scanf("%d",&x); printf(" Eneter the value ofn\n"); scanf("%d",&n); switch(n) { case 1: y=(ax%b); printf(" The value of y is=%f" ); break; case 2: y=(ax2+b2); printf( " The value of y is=%f" ,y); break; case 3: y=(a-b*x); printf( " The value of y is=%f" ,y); break; case 4: y=(a+x/b); printf( " The value of y is=%f" ,y); break; } getch(); } Output Window :
#include<conio.h> void main() { int a ,b ,c , i, terms; clrscr(); printf(“ Enter the number the terms”); scanf(“%d”, &terms); a = 0; b= 1; c=0; printf(“Fibonacci series is :\n”); for(i=0;i<+terms;i++) { printf(“\t%d”,c); a=b; b=c; c=a+b; getch(); } Output Window :
Program No: Objective: Write a program to find whether the number is Armstrong number. Logic: If Sum of cubes of every digit of number is equal to itself number is known as Armstrong Number like 0, 1, 153, 370, 371 and 407 153= 1^3 +5^3 +3^3 Determine Remainder of Given number as Remainder=Number%10.Then calculate the last digit of given number as Number=Number/10. Algorithm:
Program No: Objective: Write a program to generate sum of series 1!+2!+3!+ n!. Logic: Apply loop to Compute the summation of every Integer value.Initialize the value of sum=0 and loop counter by 1.At each iteration factorial of each term and then compute Sum. Example: Input: Terms= So, Sum=1! +2! +3! +4! +5!=1+2+6+24+120= Output: 153 Algorithm:
printf(“ The sum of the series is: %d”,Sum); getch(); } Output Window :