You are on page 1of 31

JADAVPUR UNIVERSITY

1.

2.

3.

4.

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

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.
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.
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.

5. Programs on 07.02.2014 :a. Program to find whether a given number is prime or not
b. Program to print the number of prime numbers in a given
range.
c. Program to print the following pattern upto ‘n’ which is
is entered by the user :5
54321
1
54
5432
21
543
543
321
5432
54
4321
54321
5
54321
d. Program to print the following pattern upto ‘n’ which is
is enter by the user :1
1
1
1
121
212
12
21
12321
32123
123321

POWER ENGINEERING

SHALINEE SINHA

ROLL - 001311501008

1

6.

JADAVPUR UNIVERSITY

Programs on 14-02-2014 :a.
Program to calculate the Grade of a student using switch-case statement.
b.

c.

7.

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).
Program to find the sum and average of odd numbers and even numbers in an
array.

Programs on 08-03-2014 :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.
a.

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.
#include<stdio.h>
int 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’.
else
return 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)

POWER ENGINEERING

SHALINEE SINHA

ROLL - 001311501008

2

{

return (float)a/b;

JADAVPUR UNIVERSITY

// 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
The
The
The

sum of 2 and 3 is :- 5
difference between 2 and 3 is :- 1
product of 2 and 3 is :- 6
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<stdio.h>
#include<math.h> //Needed for using the sqrt() function
float 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);

POWER ENGINEERING

SHALINEE SINHA

ROLL - 001311501008

3

} OUTPUT :Enter the length of one of the parallel sides of the trapezoid :. return 0.float f.3 4 5 The The The The area area area area of of of of the the the the given given given given ellipse is :.142857 triangle is :. printf("\n The area of the given triangle is :.p1. scanf("%f".float r. p1=(a+b+c+d).").3. } float area(float a.&x. area(a. a2=((a+b)*h)/2.12.000000 and perimeter is :.float b.z). a1=(22*a*b)/7.%f ".c.&r).a2.%f and perimeter is :. printf("\n Enter the length of the major axis of the ellipse :.000000 Q. printf("\n The area of the given circle is :.142857 trapezoid is :. Write a program to find the solution of a quadratic equation? Date :.a2.a3.f.4 Enter the length of the major axis of the ellipse :. scanf("%f%f%f".x. scanf("%f". printf("\n Enter the radius of the circle :.%f and perimeter is :.d. p2=(2*22*r)/7. a3=(22*r*r)/7.4 Enter the other two sides of the trapezoid :. printf("\n The area of the given ellipse is :. printf("\n Enter the three sides of the triangle :.").float d.5 Enter the length of the second parallel side of the trapezoid :.p2).").float e.float y.3 Enter the radius of the circle :.float h.float c.3 Enter the three sides of the triangle :.&a). POWER ENGINEERING SHALINEE SINHA ROLL . printf("\n Enter the length of the minor axis of the ellipse :."). printf("\n The area of the given trapezoid is :.float x.p3.3 4 Enter the height of the trapezoid :.&z).y.000000 circle is :.b.50.17-01-2014.12.000000 and perimeter is :.%f and perimeter is :.6.e.p3).h. scanf("%f".285713 and perimeter is :.float z) { float a1.5 Enter the length of the minor axis of the ellipse :.&b).&y.%f \n".p2.p1). p3=x+y+z.17.25. double a4.").001311501008 4 .a3.&h). return 0. scanf("%f". . a4=sqrt((p3/2)*(p3/2-x)*(p3/2-y)*(p3/2-z)).%f ".a1).a4.r.47.JADAVPUR UNIVERSITY printf("\n Enter the height of the trapezoid :.%f ".

scanf("%d".&c). } OUTPUT :Enter the value of 'a' in the quadratic equation :. } double quadratic(int a.000000 Q."). printf("\n Enter the 2nd integer :."). // Second root of the equation. scanf("%d". else { x1=(-(double)b+sqrt(b*b-4*a*c))/(2*a).-1. printf("\n Enter the value of 'b' in the quadratic equation :.c. scanf("%d".a. return 0. // Program to calculate largest and smallest of three integers using ternary operator. return 0."). printf(" Enter the value of 'a' in the quadratic equation :.b. x2=(-(double)b-sqrt(b*b-4*a*c))/(2*a).int. scanf("%d".h> //Needed for using the sqrt() function double quadratic(int. printf("\n Enter the value of 'c' in the quadratic equation :.&a). printf("\n Enter the 3rd integer :.3 Enter the value of 'c' in the quadratic equation :.c).int).b. } return 0. if((b*b-4*a*c)<0) // Checking whether Discriminant less than zero.&b).int).000000 and -2. printf(" Enter the first integer :.int c) { double x1.c. int main() { int a.h> int smalllarge(int.c. int main() { int a. // First root of the equation."). #include<stdio.&b).17-01-2014.001311501008 5 ."). printf("\n The roots of the equation %dx^2+%dx+%d=0 are :.&a).b. Write a program to calculate largest and smallest of three integers using ternary operator? Date :.2 The roots of the equation 1x^2+3x+2=0 are :.x2. printf("\n Roots are imaginary \n ").%lf and %lf \n".c).int. } POWER ENGINEERING SHALINEE SINHA ROLL .4.int b.&c).").b.JADAVPUR UNIVERSITY // Program to find the solution of a quadratic equation.1 Enter the value of 'b' in the quadratic equation :. scanf("%d".b. quadratic(a. smalllarge(a. scanf("%d".x1. #include<stdio.x2).h> #include<math.

float c) { int l=(a==b && a==c)?printf("\n The triangle is equilateral \n"):((a==b ||a==c || b==c)? printf("\n The triangle is isosceles \n"):printf("\n The triangle is scalene \n")). printf("\n Enter the third side of the triangle :.3 and 5 is :.5 Smallest number out of 2.l).float). Write a program to find the category of a triangle using ternary operator? Date :.%d and %d is :.s). // Finding the largest variable out of three.int c) { int l=(a>b && a>c)?a:((b>c)?b:c).&a). scanf("%f".5 POWER ENGINEERING SHALINEE SINHA ROLL ."). #include<stdio.17-01-2014.h> int trianglecategory(float. trianglecategory(a.b.float b.a.%d \n". printf("\n Largest number out of %d.2 Q.6 Enter the second side of the triangle :. } OUTPUT :Enter the first side of the triangle :.&b).a.").b.c. return 0.float. return 0. scanf("%f".%d ".").int b.3 and 5 is :.JADAVPUR UNIVERSITY int smalllarge(int a. } OUTPUT :Enter the first integer :.5. printf("\n Enter the second side of the triangle :.&c). int main() { float a. return 0. printf(" Enter the first side of the triangle :.b.001311501008 6 .5 Enter the third side of the triangle :.c. int s=(a<b && a<c)?a:((b<c)?b:c).b. printf("\n Smallest number out of %d.%d and %d is :. // Finding the smallest variable out of three.2 Enter the 2nd integer :. scanf("%f".c). } int trianglecategory(float a.3 Enter the 3rd integer :. // Finding the category of the given triangle. // Program to find the category of a triangle whose sides are given using ternary operator.c.5 Largest number out of 2.

17-01-2014. } float celfahr(float c) { float f=(1. printf(" Press '1' if you want celsius to fahrenheit conversion and \n '2' if you want fahenheit to celsius conversion :. printf("\n Temperature in celsius is :.98."). } else printf("\n Wrong choice \n").37 Temperature in fahrenheit is :.c). float fahrcel(float).").8*c+32.0).f). // Taking input the choice of the user. if(i==1) { printf("\n Enter the temperature in celsius :. return 0. } else if(i==2) { printf("\n Enter the temperature in fahrenheit :.JADAVPUR UNIVERSITY The triangle is isosceles Q.&i).%f\n". Write a program to convert temperature from Celsius to Fahrenheit and vice versa? Date :. int i. // Program to convert temperature from celsius to Fahrenheit and vice versa #include<stdio. } OUTPUT :Press '1' if you want celsius to fahrenheit conversion and '2' if you want fahenheit to celsius conversion :.&f).").1 Enter the temperature in celsius :.%f\n".&c). // Converting Celsius into Fahrenheit return f. printf("\n Temperature in fahrenheit is :. scanf("%f".f.599998 POWER ENGINEERING SHALINEE SINHA ROLL . // Converting Fahrenheit into Celsius return c.8.001311501008 7 . c=fahrcel(f). int main() { float c. // Function to convert temperature from Fahrenheit to Celsius. // Function to convert temperature from Celsius to Fahrenheit.h> float celfahr(float).6. } float fahrcel(float f) { float c=(f-32)/1. scanf("%f". scanf("%d". f=celfahr(c).

24-01-2014. } int trianglecategory(float a.&b). scanf("%f".").7. trianglecategory(a. // Program to find out the category of a triangle using if-else. } POWER ENGINEERING SHALINEE SINHA ROLL .&c).b. return 0.h> int trianglecategory(float. Write a program to find out the category of a triangle using if-else? Date :."). scanf("%f".").float b.c).001311501008 8 .b.JADAVPUR UNIVERSITY Q. return 0. printf(" Enter the length of the first side :. printf(" Enter the length of the second side :.float.&a).float c) // Checking category of the triangle. else printf(" The triangle is scalene \n"). printf(" Enter the length of the third side :.c. int main() { float a.float). else if(a==b || b==c || a==c) printf(" The triangle is isosceles \n"). #include<stdio. scanf("%f". { if(a==b && b==c) printf(" The triangle is equilateral \n").

7 Enter the length of the second side :.62 Grade : C Q. Write a program to find the grade of a student using if-else and logical operators? Date-24-01-2014.4 Enter the length of the third side :. grade(n).JADAVPUR UNIVERSITY OUTPUT :Enter the length of the first side :. int main() { int n. else if(n>=80 && n<90) printf(" Grade : A \n"). return 0.9. else if(n>=70 && n<80) printf(" Grade : B \n"). else if(n>=90 && n<=100) printf(" Grade : S \n"). POWER ENGINEERING SHALINEE SINHA ROLL .&n).001311501008 9 . printf(" Enter your marks :. } OUTPUT :Enter your marks :. } int grade(float n) // Function to calculate grade of the student. else if(n<50 && n>=0) printf(" Grade : F \n"). #include<stdio. \n ").8. Write a program to find the grade of a student using if-else and without using logical operators? Date-24-01-2014. // Variable to input the marks of the student. scanf("%d". return 0.6 The triangle is scalene Q. // Program to find the grade of a student using if-else and logical operators. { if(n>100 && n<0) printf(" Sorry!!! Maximum marks is 100 and minimum marks is 0."). else if(n>=60 && n<70) printf(" Grade : C \n"). else if(n>=50 && n<60) printf(" Grade : E \n").h> int grade(float).

h> int grade(float). printf("\n The sum of digits of the number in one digit is :.%d \n". return 0.s.JADAVPUR UNIVERSITY // Program to find the grade of a student using if-else without using logical operator. \n ").s). // Function to calculate sum of digits and to check whether it is greater than 10 or not. return 0.10. /* Program to calculate the sum of digits and if the sum exceeds one digit then the sum of digits of the digits of the sum and to check whether the given number is a palindrome or not */ #include<stdio. else if(n<50) printf(" Grade : F \n"). Write a program to calculate the sum of digits and if the sum exceeds one digit then the sum of digits of the digits of the sum and to check whether the given number is a palindrome or not? Date – 01-02-2014. int main() { int n.89 Grade : A Q. int main() { int n. printf(" Enter your marks :.&n). printf(" Enter an integer :. scanf("%d". #include<stdio. } int grade(float n) // Function to calculate grade of the student. POWER ENGINEERING SHALINEE SINHA ROLL . { if(n>100) // To check whether marks entered is between 0 and 100.001311501008 10 . else if(n>=90) printf(" Grade : S \n"). } OUTPUT :Enter your marks :. scanf("%d". grade(n). printf(" Sorry!!! Maximum marks is 100. else if(n>=60) printf(" Grade : C \n"). else if(n>=70) printf(" Grade : B \n"). s=sumofdigits(n). else if(n>=80) printf(" Grade : A \n"). else if(n>=50) printf(" Grade : D \n").h> int sumofdigits(int).").").&n).

d=0.r.52625 The number is a palindrome The sum of digits of the number in one digit is :.001311501008 11 . s=0. } OUTPUT :Enter an integer :.JADAVPUR UNIVERSITY return 0. else printf("\n The number is not a palindrome \n"). while(s>=10) { a=s.b=0. } return s. while(a>0) { r=a%10. s=s+r.s=0. a=a/10. s=n. } if(b==0) { if(d==n) printf("\n The number is a palindrome \n"). d=d*10+r. } int sumofdigits(int n) { int a.2 POWER ENGINEERING SHALINEE SINHA ROLL . } b++.

n. printf(" Enter the value whose factorial has to be found out :."). printf(" Factorial not possible \n"). // Function to calculate factorial by recursion method.h> int fact(int).fact(n)).7 The factorial of 7 without recursion is :.f=1. if(n<0) return 0. return f. else if(n<0) return 0. } OUTPUT :Enter the value whose factorial has to be found out :. { int i. // Function to calculate factorial by normal method. } int fact(int n) // Calculating factorial of the given number by normal method.i<=n. int factr(int). return 0. else return(n*fact(n-1)). // Program to calculate factorial of a number with and without using recursion #include<stdio. else { for(i=1. printf("\n Factorial not possible \n").5040 POWER ENGINEERING SHALINEE SINHA ROLL .%d \n".5040 The factorial of 7 using recursion is :. { int f. else if(n==0 || n==1) return 1. else printf("\n The factorial of %d without recursion is :.&n).JADAVPUR UNIVERSITY Q. Write a program to calculate factorial of a number with and without recursion? Date – 01-02-2014.factr(n)).n. scanf("%d". if(factr(n)==0) // Condition when the number entered is less than 0.%d \n".001311501008 12 . if(fact(n)==0) // Condition when the number entered is less than 0. } } int factr(int n) // Calculating factorial of the given number by recursion method. else printf(" The factorial of %d using recursion is :.i++) f=f*i. int main() { int n. if(n==0 || n==1) return 1.11.

POWER ENGINEERING SHALINEE SINHA ROLL . } int sumofoddeven(int u.o=0.l).e=0.001311501008 13 .JADAVPUR UNIVERSITY Q.n2=0.i++) { if(i%2==0) // Checking whether the number is even or not. sumofoddeven(u.&l). scanf("%d". float a1. scanf("%d".n1=0. #include<stdio. // Program to calculate the sum and average of odd and even numbers in a given range. { e=e+i.int). n1++.a2. int main() { int u.").").int l) { int i. n2++.i<=u. } else { o=o+i.&u). return 0. Write a program to calculate the sum and average of odd and even numbers in a given range? Date – 01-02-2014. for(i=l. printf(" Enter the upper limit of the range :. // Function to calculate sum of odd and even nos in a given range.l.h> int sumofoddeven(int. printf("\n Enter the lower limit of the range :.12.

30 and the average of even nos in the range is :.%d and the average of odd nos in the range is :.JADAVPUR UNIVERSITY } } a1=(float)o/n1.10 Enter the lower limit of the range :. // Program to calculate the Greatest common divisor using recursion and without recursion POWER ENGINEERING SHALINEE SINHA ROLL . a2=(float)e/n2.000000 The sum of even nos in the range is :.a1).e. Write a program to calculate the Greatest common divisor using recursion and without recursion? Date – 01-02-2014.13.24 and the average of odd nos in the range is :. printf("\n The sum of odd nos in the range is :. return 0.6. printf("\n The sum of even nos in the range is :.000000 Q.%f \n ". } OUTPUT :Enter the upper limit of the range :.o.6.%d and the average of even nos in the range is :.a2).2 The sum of odd nos in the range is :.001311501008 14 .%f \n".

b.int). return 0.b).%d \n". printf("\n The Greatest common divisor of %d and %d without using recursion is :. a=b. else return(gcd(a. b=a. d= gcd(a. } else { temp=b%a. if(temp==0) return b.JADAVPUR UNIVERSITY #include<stdio. } return b.temp)). if(temp==0) return a. printf(" Enter the first number :.").b). scanf("%d".h> int gcd(int.b. } int gcd(int a. scanf("%d".d). } return a.a.b.001311501008 15 . b=temp.d).&a). if(a>b) { while(b>0) { temp=a%b.int). } } POWER ENGINEERING SHALINEE SINHA ROLL . d=gcdr(a.int b) { int temp. else return(gcd(b.temp)). printf(" The Greatest common divisor of %d and %d using recursion is :.d. printf(" Enter the second number :.a.int b) { int temp. } else { while(a>0) { temp=b%a. a=temp. int gcdr(int. int main() { int a.%d \n".&b). } } int gcdr(int a. if(a>b) { temp=a%b.").

5.30 0. printf(". //Program to check whether a number is prime or not.a. Write a program to print the fibonacci series upto a certain number entered by the user? Date – 01-02-2014.3. b=s.1 Q. a=b. Write a program to check whether a number is prime or not? Date – 07-02-2014.1. } OUTPUT :Enter the last limit of the series :.35 Enter the second number :.JADAVPUR UNIVERSITY OUTPUT :Enter the first number :. #include<stdio."). int main() { int n.1 The Greatest common divisor of 35 and 6 using recursion is :. printf(" Enter the last limit of the series :. while((a+b)<=n) { s=a+b. fibonacci(n).15.s). } printf(". #include<stdio.6 The Greatest common divisor of 35 and 6 without using recursion is :.21.b).%d".14. return 0. } int fibonacci(int n) { int a=0.\n").1.s.13.h> int prime(int). Q.b=1.%d".&n).8.2. printf("\n %d.001311501008 16 . POWER ENGINEERING SHALINEE SINHA ROLL . // Program to print the fibonacci series upto a certain number entered by the user. scanf("%d". return 0.h> int fibonacci(int).

} } if(flag==1) printf(" The no %d is a non prime no\n ". else { for(i=2.JADAVPUR UNIVERSITY int main() { int n.&n1).&n).&n2). } return 0.\n ").16.i<n.flag=0.n2). if(n1<n2) { POWER ENGINEERING SHALINEE SINHA ROLL .s1=0."). printf(" Enter the last limit :. prime(n). printf(" Enter an integer :. // Becomes ‘1’ when the number ‘n’ becomes divisible by something less than the number ‘n’ break. else printf(" The no %d is a prime no \n". scanf("%d".").int).31 The no 31 is a prime no Q. #include<stdio.n2.s2=0.h> int prime(int. printf(" The number %d is a special number. if(n==1) // ‘1’ is a special number so whether it is prime or not cant be said. } OUTPUT :Enter an integer :.i++) { if(n%i==0) { flag=1. } int prime(int n1. // Program to find the no of prime numbers in a range. scanf("%d".int n2) { int i. } int prime(int n) { int i.n). return 0. prime(n1.j. scanf("%d". Write a program to find the no of prime numbers in a range? Date – 07-02-2014. printf(" Enter the first limit :.n).001311501008 17 . int main() { int n1."). return 0.

%d \n".001311501008 18 .7 POWER ENGINEERING SHALINEE SINHA ROLL .j<=n1. } } } } for(j=n1.j<=n2. OUTPUT :Enter the first limit :. } } s1++. // Number of prime numbers in the range.j++) if(j!=1) { for(i=2.15 The number of prime nos :.i++) { if(j%i==0) { s2++. // Number of non prime nos in the range.i<j. } } s1++.j++) { if(j!=1) { for(i=2. // Number of non prime nos in the range. break.5 Enter the last limit :. } } printf(" The number of non prime nos :.(s1-s2)). printf(" The number of prime nos :.i++) { if(j%i==0) { s2++. break. // Number of prime numbers in the range.s2).i<j.26 The number of non prime nos :.%d \n".JADAVPUR UNIVERSITY } else { { for(j=n2. return 0.

JADAVPUR UNIVERSITY Q. int structure2(int). int main() { int n. int structure3(int).j>=i.j). 54 5432 21 543 543 321 5432 54 4321 54321 5 54321 Date – 07-02-2014.i++) { for(j=n.001311501008 19 .i>=1. /* Program to print the following pattern upto 'n' which is entered by the user :5 54321 1 54 5432 21 543 543 321 5432 54 4321 54321 5 54321 */ #include<stdio.j--) printf("%d ".&n). } int structure3(int n) { POWER ENGINEERING SHALINEE SINHA ROLL . printf("\n\n")."). structure1(n).j>=i. scanf("%d". } int structure2(int n) { int i.j--) printf("%d ". } int structure1(int n) { int i.17.j). for(i=n.i<=n.j. Write a program to print the following pattern upto 'n' which is entered by the user :5 54321 1 where n=5. } return 0.i--) { for(j=n. printf(" Enter the limit of the structure :. printf("\n"). structure3(n). printf("\n").h> int structure1(int). for(i=1.j. return 0. structure2(n). printf("\n\n"). } return 0.

j++) printf("%d ".i<=n.18.j--) printf(" ").j>=1. JADAVPUR UNIVERSITY } OUTPUT :Enter the limit of the structure :.int i.j.i++) { for(j=n-i. Write a program to print the following patterns upto 'n' which is entered by the user :1 1 1 1 where n=3. for(i=1. printf("\n").001311501008 20 . 121 212 12 21 12321 32123 123321 Date – 07-02-2014.j<=i. } return 0. for(j=1.j).4 4 43 432 4321 4321 432 43 4 1 12 123 1234 Q. /* Program to print the following patterns upto 'n' which is entered by the user :- POWER ENGINEERING SHALINEE SINHA ROLL .

} int structure1(int n) { int i.j. int main() { int n.i++) { for(j=n-i. for(j=i-1. } return 0.j++) printf("%d ". } int structure2(int n) { int i. printf("\n\n").h> int structure1(int).j--) printf(" ").j>=1.j>=1. } return 0. for(j=1. for(j=i.i<=n.j<=i. int structure3(int).i<=n.001311501008 21 .j>=1. for(i=1.j--) printf(" ").j). return 0.i++) { for(j=1.j>=1. structure2(n). int structure2(int). } POWER ENGINEERING SHALINEE SINHA ROLL . printf("\n\n"). for(i=1.j.j<=i. scanf("%d".j).j--) printf(" ").j). printf("\n"). for(j=2. } return 0.j>=1. printf(" Enter the last limit of the structure :.j).j<=i. printf("\n").j--) printf("%d ".j).j).j++) printf("%d ". for(i=1. for(j=i.j--) printf("%d ". for(j=2*(n-i).j>=1.i++) { for(j=n-i.i<=n.j--) printf("%d ".&n). structure1(n).1 121 12321 1 212 1 12 1 21 123321 JADAVPUR UNIVERSITY 32123 */ #include<stdio.j++) printf("%d "."). } int structure3(int n) { int i. structure3(n).j. printf("\n").

//Program to perform addition.").int). scanf("%d".n.JADAVPUR UNIVERSITY OUTPUT :Enter the last limit of the structure :. // Entering the choice of the user.19. division.&n). int sub(int."). printf(" Press '1' for addition.&a). int power(int. int mod(int. ."). power and modulus using switch-case and do while(to repeatedly take input unless user wants to exit)? Date – 14-02-2014.h> int add(int.b.division using switch-case.subtraction. '3' for multiplication '4' for division and '5' to power and '6' to find remainder :. switch(n) { POWER ENGINEERING SHALINEE SINHA ROLL .multiplication. multiplication.int). int main() { int a. Write a program to perform addition. subtraction.int). float div(int. #include<math. scanf("%d".4 1 121 12321 1234321 1 212 32123 4321234 1 12 2 123 32 1234432 1 1 1 1 Q. do { printf(" Enter the first integer :. '2' for subtraction .h> #include<stdio.i=1.int).int). int multi(int. printf(" Enter the second integer :.001311501008 22 .&b). scanf("%d".int).

b)). case 2: printf(" The difference between %d and %d is :. break.a.6 Press '1' for addition. break.b.%f \n".b)).b. // Finding the remainder when the variable ‘a’ is divided by ‘b’. } int power(int a.0.%d \n".b).%d \n". scanf("%d".b)).add(a. case 3: printf(" The product of %d and %d is :. else return b-a.b.a. } OUTPUT :Enter the first integer :. '3' for multiplication '4' for division and '5' to power and '6' to find remainder :.multi(a. '3' for multiplication '4' for division and '5' to power and '6' to find remainder :. break.b)). case 5: printf(" %d^%d= %d\n".int b) { if(a>b) return a-b.4 Enter the second integer :.20. JADAVPUR UNIVERSITY } printf(" Press '1' to coninue and '0' to exit!!! ").001311501008 .11 Press '1' to coninue and '0' to exit!!! 1 Enter the first integer :.int b) { return a+b. case 6: printf(" Modulus of %d and %d :.int b) { return (float)a/b. '2' for subtraction . break.666667 Press '1' to coninue and '0' to exit!!! 0 Q.4 Enter the second integer :. return 0. // Loop to continue the program unless user wants to exit. break.mod(a. case 4: printf(" The quotient of %d and %d is :. // Finding the value of a^b.%d \n". } int sub(int a.a.sub(a.int b) { return a%b. } int multi(int a. break.int b) { return pow(a. '2' for subtraction .power(a. } int add(int a.b.a. Write a program to find the grade of a student using switch case? POWER ENGINEERING SHALINEE SINHA ROLL .&i).b)).1 The sum of 4 and 7 is :.a.%d\n". } float div(int a.b. }while(i==1).a.int b) { return (a*b).div(a.b. } int mod(int a.23 case 1: printf(" The sum of %d and %d is :.b)).7 Press '1' for addition.4 The quotient of 4 and 6 is :. default: printf(" Wrong input !!! Please enter the correct input \n").

grade(n). // Program to calculate the sum and average of even and odd numbers in an array. break. scanf("%f"."). // To bring the values of n1 in between 0 and 10 to reduce the number of cases. } return 0.21. case 8: printf(" Grade A \n"). case 4: case 3: case 2: case 1: case 0: printf(" Grade F \n"). switch(n1) { case 10: case 9: printf(" Grade S \n"). else printf(" Wrong input !!! Maximum marks is 100 and minimum marks is 0.h> int grade(float). break. int main() { float n. return 0. case 7: printf(" Grade B \n").84 Grade A Q.&n). printf(" Enter your marks :.h> POWER ENGINEERING SHALINEE SINHA ROLL . \n "). JADAVPUR UNIVERSITY // Program to find the grade of a student using switch case. #include<stdio. case 5: printf(" Grade D \n").Date – 14-02-2014. } OUTPUT :Enter your marks :. Date – 14-02-2014. break. Write a program to calculate the sum and average of even and odd numbers in an array?. #include<stdio.001311501008 24 . default: printf(" Wrong input !!! Maximum marks is 100 and minimum marks is 0. break. } int grade(float n) { int n1=n/10. break. case 6: printf(" Grade C \n"). \n "). if(n<=100 && n>=0)// Checking whether the marks entered is in between 0 and 100. break.

even(c.s=0.k). k++.j=0.%d and average is %f \n".181 and average is 60.s.66 Enter the element no:4 :.i++) .i<k. main() { int i.int k) { int i.&a[i]).i++) s=s+c[i].s. } for(i=0.i++) { if(a[i]%2==0) { b[j]=a[i].i<n.&n). } OUTPUT :Enter the number of elements you want to enter(max 50) :-5 Enter the element no:1 :. j++. scanf("%d". avg=(float)s/j. float avg.000000 Sum of odd numbers :. printf(" Sum of odd numbers :. s=s+b[i].78 Enter the element no:5 :.45 Enter the element no:2 :. // b[] variable stores all the even integers in the array a[].".i++) { printf(" Enter the element no:%d :.(i+1)). float avg.43 Enter the element no:3 :.144 and average is 72. } void even(int c[]. scanf("%d". // c[] variable stores all the odd integers in the array a[].k=0.int).i<n.i<j.b[50]. } else printf(" No of elements must be positive and less than equal to 50 \n").a[50]. printf(" Sum of odd numbers :.avg). } } odd(b. avg=(float)s/k. } void odd(int b[].c[50]. for(i=0.JADAVPUR UNIVERSITY void odd(int [].n.333332 POWER ENGINEERING SHALINEE SINHA ROLL .001311501008 25 .int j) { int i.int).j).s=0.93 Sum of odd numbers :. for(i=0.%d and average is %f \n".avg). printf(" Enter the number of elements you want to enter(max 50) :-" ). void even(int []. } else { c[k]=a[i]. if(n<=50 && n>0) { for(i=0.

void duplicatedel(int []. return 0.int).&n1). void insert(int [].i--) a[i]=a[i-1].deletion and dupicate deletion operation on a 1D array?. scanf("%d".int).22. void delete(int [].i<n. insert(a.n1. scanf("%d".n.i++) { printf(" Enter the element no :%d :. a[p]=n1. Write a program to perform insertion. } void show(int a[]. int main() { int i. printf("\n").n).h> void show(int [].").001311501008 26 .").int).JADAVPUR UNIVERSITY Q.a[20].&n). } printf(" The array is :. #include<stdio.i++) printf("%d ".i>p. Date – 08-03-2014. printf(" Enter the element you want to enter :. .").. // Program to perform insertion."). for(i=0. printf(" Enter the number of elements you want to enter in the array :. for(i=n. POWER ENGINEERING SHALINEE SINHA ROLL .int).int n) { int i.p.n).\n").a[i]).i<n. printf("\n\n"). scanf("%d".&p).&a[i]). printf(" Enter the position where you want to insert the value :. } void insert(int a[]. show(a. . scanf("%d".". printf(" Enter the elements of the array :.(i+1)).deletion and dupicate deletion operation on a 1D array. for(i=0.int n) { int i.

int n) { int i.1 Enter the element no :2 :. Program to perform the addition.1 The array after deletion is :.i++) a[i]=a[i+1].n). POWER ENGINEERING SHALINEE SINHA ROLL . JADAVPUR UNIVERSITY } void delete(int a[]. Date – 08-03-2014.i++) for(j=i+1."). printf("\n\n").1 7 3 2 Q.n). } OUTPUT :Enter the number of elements you want to enter in the array :. } void duplicatedel(int a[].n++. show(a. scanf("%d".1 7 2 3 2 The array after duplicate deletion is :.i<=(n-2).").3 Enter the element no :5 :. printf("\n\n").7 Enter the element no :4 :.int n) { int p. duplicatedel(a. n--.&p). for(i=p.1 5 7 2 3 2 Enter the position of element you want to delete :.i<=(n-2).k++) a[k]=a[k+1].j.j<n.n).1 5 7 3 2 Enter the element you want to enter :.5 Enter the element no :3 :."). n--.5 Enter the elements of the array :Enter the element no :1 :. printf(" The array after insertion is :.product and transpose operation of two matrices?.n).j++) if(a[i]==a[j]) { for(k=j.n).k<=(n-2).001311501008 27 .2 The array is :. } printf(" The array after duplicate deletion is :. show(a.k. for(i=0. delete(a.i.3 The array after insertion is :.23.").2 Enter the position where you want to insert the value :. printf(" Enter the position of element you want to delete :. printf(" The array after deletion is :. show(a.

i<r1.product and transpose operation of two matrices.c1).r1.\n"). printf("\n\n Transpose of second matrix is :.b[10][10].r1.").j++) { printf(" Enter element of row no-%d and column no-%d :. printf("\n\n").c2).j++) { printf(" Enter element of row no-%d and column no-%d :.j<c2.c2).b. printf(" Enter the rows and column of the first matrix :.\n").&c1).j. POWER ENGINEERING SHALINEE SINHA ROLL .&a[i][j]). } } void addition(int a[][10].\n"). transpose(a. printf("\n\n Transpose of first matrix is :.int b[][10].j<c1.i++) for(j=0. scanf("%d %d".a[i][j]). show(c.j. product(a.c1). #include<stdio.\n").". printf(“ After addition \n”). } show(b.int).(i+1).j.int c1.c2).r2.int. void transpose(int [][10].").int r1.int.int c2) { int c[10][10].int [][10].(j+1)). addition(a.\n").r1. printf(" Enter the elements of the second matrix :.i++) for(j=0.&c2). printf(" Enter the elements of the first matrix :.r1. scanf("%d %d".i++) { for(j=0. scanf("%d".c1.int. return 0.b.c1. void product(int [][10].r2.r2.&r1.i. void show(int [][10].c2). printf(" The matrix is :.int.JADAVPUR UNIVERSITY // Program to perform the addition. } else printf(" Addition not possible \n").int.h> void addition(int [][10].int c) { int i.001311501008 28 .r1. for(i=0. if(r1==r2 && c1==c2) { for(i=0.i<r1.int. scanf("%d".int).i++) for(j=0.r2. } void show(int a[][10].int.r2. } show(a.j++) c[i][j]=a[i][j]+b[i][j].j++) printf("%d\t".i.i<r.&b[i][j]).(i+1).int [][10].i<r2.j<c.r1. int main() { int a[10][10]. for(i=0. printf("\n").int r.int). // Printing the elements of the matrix.c2.c1). for(i=0.(j+1)). transpose(b.int).". printf(" Enter the rows and column of the second matrix :.int r2.&r2.int.j<c1.c1.

k<r2.int r2.5 Enter element of row no-1 and column no-3 :. for(i=0.i<r.4 Enter element of row no-2 and column no-1 :.k++) c[i][j]+=a[i][k]*b[k][j]. } printf(“ After multiplication\n”).001311501008 29 .c2).int r1.i. show(d.j.3 Enter element of row no-1 and column no-2 :.7 Enter element of row no-2 and column no-3 :.6 Enter element of row no-1 and column no-2 :.i++) for(j=0.int b[][10].2 2 Enter the rows and column of the second matrix :.int c1. } else printf(" Product not possible \n"). show(c.j++) d[j][i]=a[i][j]. for(k=0.k.2 The matrix is :3 4 5 2 Enter the elements of the second matrix :Enter element of row no-1 and column no-1 :.3 Enter element of row no-2 and column no-2 :.j.JADAVPUR UNIVERSITY } void product(int a[][10].c.r).int c2) { int c[10][10].int r. } OUTPUT :Enter the rows and column of the first matrix :.i<r1.r1.d[10][10].2 3 Enter the elements of the first matrix :Enter element of row no-1 and column no-1 :.i++) for(j=0. if(c1==r2) { for(i=0.4 Enter element of row no-2 and column no-1 :. } void transpose(int a[][10].2 The matrix is :6 5 4 3 7 2 Addition not possible After multiplication The matrix is :30 43 20 36 39 24 Transpose of first matrix is :- POWER ENGINEERING SHALINEE SINHA ROLL .int c) { int i.j<c.5 Enter element of row no-2 and column no-2 :.j++) { c[i][j]=0.j<c2.

j++) if(a[j]>a[j+1]) { t=a[j]. for(i=0.&a[i]). Write a program to sort elements of an 1D array in ascending order using bubble sort?. a[j]=a[j+1].i<n. } bubblesort(a.&n).a[20].int).i++) { printf(" Enter the element-%d :. } OUTPUT :- POWER ENGINEERING SHALINEE SINHA ROLL .i++) for(j=0.\n").int n) { int i.h> void bubblesort(int [].(i+1)).n).24. scanf("%d".j. printf(" Enter the elements of the array :. for(i=0.i<=(n-1). return 0. #include<stdio. } printf(" Array after sorting in ascending order :. // Swapping the values of a[j] and a[j+1].001311501008 30 .").j<=(n-i-2).The matrix is :3 5 4 2 JADAVPUR UNIVERSITY Transpose of second matrix is :The matrix is :6 3 5 7 4 2 Q.i<n.\n"). scanf("%d".t. // Program to sort elements of an 1D array in ascending order using bubble sort. for(i=0. a[j+1]=t. Date .i++) printf("%d ".". int main() { int i.n.a[i]). } void bubblesort(int a[].08-03-2014. // ‘i’ and ‘j’ are loop variables. printf("\n"). printf(" Enter the no of elements in the array :.

Enter the no of elements in the array :.5 Enter the elements of the array :Enter the element-1 :.5 Enter the element-4 :.1 Enter the element-2 :.001311501008 31 .9 Enter the element-5 :.2 Enter the element-3 :.4 Array after sorting in ascending order :12459 POWER ENGINEERING JADAVPUR UNIVERSITY SHALINEE SINHA ROLL .