+ All Categories
Home > Documents > C Programs

C Programs

Date post: 25-Sep-2015
Category:
Upload: rahul-roy
View: 214 times
Download: 0 times
Share this document with a friend
Description:
C Programs
Popular Tags:
40
JADAVPUR UNIVERSITY PROGRAMS ON C 1. Programs on 10-01-2014 :- Program to perform all the arithmetic operations i.e. addition, subtraction, multiplication, division. 2. Programs on 17-01-2014 :- a. Program to calculate the area and perimeter of triangle, Trapezoid, circle and area of an ellipse. b. Program to find the solution of a quadratic equation. c. Program to calculate largest and smallest number out of three numbers using ternary operator. d. Program to find the category of a triangle using ternary Operator. e. Program to convert temperature from Celsius to Fahrenheit and vice versa. 3. Programs on 24.01.2014 :- a. Program to calculate category of a triangle using if-else. b. Program to calculate grade of a student using if-else and logical operator. c. Program to calculate grade of a student using if-else and without using logical operator. 4. Programs on 01.02.2014 :- a. Program to calculate the sum of digits of a number and if the sum exceeds one digit then the sum of digits of the digits if the sum and to check whether the given number is palindrome or not. b. Program to calculate the factorial of a number using recursion and without recursion. c. Program to calculate the sum and average of even and odd numbers in a given range. d. Program to find the greatest common divisor using recursion and without using recursion. e. Program to print the Fibonacci series of a given number entered by the user. POWER ENGINEERING SHALINEE SINHA ROLL - 001311501008
Transcript

PROGRAMS ON C

JADAVPUR UNIVERSITYPROGRAMS ON C

2

1. Programs on 10-01-2014 :- Program to perform all the arithmetic operations i.e. addition, subtraction, multiplication, division.

2. Programs on 17-01-2014 :-a. Program to calculate the area and perimeter of triangle, Trapezoid, circle and area of an ellipse.b. Program to find the solution of a quadratic equation.c. Program to calculate largest and smallest number out of three numbers using ternary operator.d. Program to find the category of a triangle using ternaryOperator.e. Program to convert temperature from Celsius to Fahrenheitand vice versa.

3. Programs on 24.01.2014 :-a. Program to calculate category of a triangle using if-else.b. Program to calculate grade of a student using if-else andlogical operator.c. Program to calculate grade of a student using if-else and without using logical operator.

4. Programs on 01.02.2014 :-a. Program to calculate the sum of digits of a number and if the sum exceeds one digit then the sum of digits of the digits if the sum and to check whether the given numberis palindrome or not.b. Program to calculate the factorial of a number using recursionand without recursion.c. Program to calculate the sum and average of even and oddnumbers in a given range.d. Program to find the greatest common divisor using recursionand without using recursion.e. Program to print the Fibonacci series of a given number enteredby the user.

5. Programs on 07.02.2014 :-a. Program to find whether a given number is prime or notb. Program to print the number of prime numbers in a givenrange.c. Program to print the following pattern upto n which isis entered by the user :- 5 5 4 3 2 1 1 5 4 5 4 3 2 2 1 5 4 3 5 4 3 3 2 1 5 4 3 2 5 4 4 3 2 1 5 4 3 2 1 5 5 4 3 2 1d. Program to print the following pattern upto n which isis enter by the user :- 1 11 1 1 2 1 2 1 21 2 2 1 1 2 3 2 1 3 2 1 2 31 2 3 3 2 1

6. Programs on 14-02-2014 :-a. Program to calculate the Grade of a student using switch-case statement.b. Program to perform all arithmetic operations i.e. addition, subtraction, product, division, power and modulus using switch case and do while(to repeatedly take input unless user wants to exit).

c. Program to find the sum and average of odd numbers and even numbers in an array.

7. Programs on 08-03-2014 :- a. Program to perform insertion,deletion and dupicate deletion operation on a 1D array.b. Program to perform addition,product and transpose operation on two matrices.c. Program to sort the elements of an 1D array in ascending order using bubble sort.

Q.1. Write a program to perform all the arithmetic operations i.e. addition,subtraction,multiplication,division? Date :- 10-01-2014.

// Program to perform arithmetic operations like addition,subtraction,multiplication and division.#includeint add(int,int);int sub(int,int);int product(int,int);float quotient(int,int);int main()// main function i.e. the main body of the program.{int a,b;printf(" Enter the first number :- ");scanf("%d",&a); printf("\n Enter the second number :- ");scanf("%d",&b); printf("\n The sum of %d and %d is :- %d",a,b,add(a,b)); printf("\n The difference between %d and %d is :- %d",a,b,sub(a,b));printf("\n The product of %d and %d is :- %d",a,b,product(a,b));printf("\n The quotient of %d and %d is :- %f\n",a,b,quotient(a,b));return 0;}int add(int a,int b){return a+b;// Adding the values of variables a and b.}int sub(int a,int b){if(a>b)// Checking if variable a is greater than b to get a positive result of the difference.return a-b;// Subtracting the value of variable a from b.elsereturn b-a;}int product(int a,int b){return a*b;// Multiplying the values of variables a and b and returning it.}float quotient(int a,int b){return (float)a/b;// Dividing the values of variables a and b and returning a float value.}

OUTPUT :-

Enter the first number :- 2

Enter the second number :- 3

The sum of 2 and 3 is :- 5 The difference between 2 and 3 is :- 1 The product of 2 and 3 is :- 6 The quotient of 2 and 3 is :- 0.666667

Q.2. Write a program to calculate the area and perimeter of trapezoid, triangle and circle and area of ellipse? Date :- 17-01-2014.

// Program to calculate Area and perimeter of trapezoid, triangle and circle and area of ellipse.#include#include //Needed for using the sqrt() functionfloat area(float,float,float,float,float,float,float,float,float,float,float);int main(){float a,b,h,c,d,e,f,r,x,y,z;printf(" Enter the length of one of the parallel sides of the trapezoid :- ");scanf("%f",&c);printf("\n Enter the length of the second parallel side of the trapezoid :- ");scanf("%f",&d);printf("\n Enter the other two sides of the trapezoid :- ");scanf("%f%f",&e,&f);printf("\n Enter the height of the trapezoid :- ");scanf("%f",&h);printf("\n Enter the radius of the circle :- ");scanf("%f",&r);printf("\n Enter the length of the major axis of the ellipse :- ");scanf("%f",&a);printf("\n Enter the length of the minor axis of the ellipse :- ");scanf("%f",&b);printf("\n Enter the three sides of the triangle :- ");scanf("%f%f%f",&x,&y,&z);area(a,b,c,d,e,f,h,r,x,y,z);return 0;}float area(float a,float b,float c,float d,float e,float f,float h,float r,float x,float y,float z){float a1,a2,a3,p1,p2,p3;double a4;a1=(22*a*b)/7;printf("\n The area of the given ellipse is :- %f ",a1);a2=((a+b)*h)/2;p1=(a+b+c+d);printf("\n The area of the given trapezoid is :- %f and perimeter is :- %f ",a2,p1);a3=(22*r*r)/7;p2=(2*22*r)/7;.printf("\n The area of the given circle is :- %f and perimeter is :- %f ",a3,p2);p3=x+y+z; a4=sqrt((p3/2)*(p3/2-x)*(p3/2-y)*(p3/2-z));printf("\n The area of the given triangle is :- %f and perimeter is :- %f \n",a4,p3);return 0;}OUTPUT :-

Enter the length of one of the parallel sides of the trapezoid :- 5

Enter the length of the second parallel side of the trapezoid :- 4

Enter the other two sides of the trapezoid :- 34

Enter the height of the trapezoid :- 3

Enter the radius of the circle :- 4

Enter the length of the major axis of the ellipse :- 5

Enter the length of the minor axis of the ellipse :- 3

Enter the three sides of the triangle :- 345

The area of the given ellipse is :- 47.142857 The area of the given trapezoid is :- 12.000000 and perimeter is :- 17.000000 The area of the given circle is :- 50.285713 and perimeter is :- 25.142857 The area of the given triangle is :- 6.000000 and perimeter is :- 12.000000

Q.3. Write a program to find the solution of a quadratic equation?

Date :- 17-01-2014.

// Program to find the solution of a quadratic equation.#include#include//Needed for using the sqrt() functiondouble quadratic(int,int,int);int main(){int a,b,c;printf(" Enter the value of 'a' in the quadratic equation :- ");scanf("%d",&a);printf("\n Enter the value of 'b' in the quadratic equation :- ");scanf("%d",&b);printf("\n Enter the value of 'c' in the quadratic equation :- ");scanf("%d",&c);quadratic(a,b,c);return 0;}double quadratic(int a,int b,int c){double x1,x2;if((b*b-4*a*c)b && a>c)?a:((b>c)?b:c);// Finding the largest variable out of three.int s=(a=80)printf(" Grade : A \n");else if(n>=70)printf(" Grade : B \n");else if(n>=60)printf(" Grade : C \n");else if(n>=50)printf(" Grade : D \n");else if(n=10){a=s;s=0;while(a>0){r=a%10;a=a/10;s=s+r;d=d*10+r;}if(b==0){if(d==n)printf("\n The number is a palindrome \n");elseprintf("\n The number is not a palindrome \n");}b++;}return s;}OUTPUT :- Enter an integer :- 52625 The number is a palindrome The sum of digits of the number in one digit is :- 2 Q.11. Write a program to calculate factorial of a number with and without recursion?Date 01-02-2014.// Program to calculate factorial of a number with and without using recursion#includeint fact(int);// Function to calculate factorial by normal method.int factr(int);// Function to calculate factorial by recursion method.int main(){int n;printf(" Enter the value whose factorial has to be found out :- ");scanf("%d",&n);if(fact(n)==0)// Condition when the number entered is less than 0.printf("\n Factorial not possible \n");elseprintf("\n The factorial of %d without recursion is :- %d \n",n,fact(n));if(factr(n)==0)// Condition when the number entered is less than 0.printf(" Factorial not possible \n");elseprintf(" The factorial of %d using recursion is :- %d \n",n,factr(n));return 0;}int fact(int n)// Calculating factorial of the given number by normal method.{int i,f=1;if(nb){temp=a%b;if(temp==0)return b;elsereturn(gcd(b,temp));}else{temp=b%a;if(temp==0)return a;elsereturn(gcd(a,temp));}}OUTPUT :- Enter the first number :- 35 Enter the second number :- 6 The Greatest common divisor of 35 and 6 without using recursion is :- 1 The Greatest common divisor of 35 and 6 using recursion is :- 1Q.14. Write a program to print the fibonacci series upto a certain number entered by the user?Date 01-02-2014.// Program to print the fibonacci series upto a certain number entered by the user.#includeint fibonacci(int); int main(){int n;printf(" Enter the last limit of the series :- ");scanf("%d",&n);fibonacci(n);return 0;}int fibonacci(int n){int a=0,b=1,s;printf("\n %d,%d",a,b);while((a+b)


Recommended