0% found this document useful (0 votes)
41 views30 pages

Factorial of A Number

The document contains algorithms and programs for several common programming problems: 1) It outlines algorithms and provides code for calculating factorials, Fibonacci series, addition and multiplication of matrices, determining if a number is even or odd, and converting between decimal and binary. 2) Additional algorithms and programs determine the largest of three numbers, display the name of a day of the week, check if a number is prime, and print Pascal's triangle. 3) The last section illustrates the concept of classes and objects in C++ by providing code for a Student class with functions to get and display data.

Uploaded by

kunjvas
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views30 pages

Factorial of A Number

The document contains algorithms and programs for several common programming problems: 1) It outlines algorithms and provides code for calculating factorials, Fibonacci series, addition and multiplication of matrices, determining if a number is even or odd, and converting between decimal and binary. 2) Additional algorithms and programs determine the largest of three numbers, display the name of a day of the week, check if a number is prime, and print Pascal's triangle. 3) The last section illustrates the concept of classes and objects in C++ by providing code for a Student class with functions to get and display data.

Uploaded by

kunjvas
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Factorial of a Number

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Initializing of the values to the variables and accept the values of which factorial is to
be found.
5. Calculate the factorial.
6. Print the factorial.
7. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int a, fact=1,i;
printf(“Enter any Number”);
printf(“\n”);
scanf(“%d”,&a);
for(i=1;i<=a;i++)
{
fact=fact*i;
}
printf(“%d”,fact);
getch();
}

Output:
Enter any Number 5

120
Fibonacci Series

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Initializing of the values to the variables and accept the limiting value.
5. Take the loop and display the initial values.
6. Swap the Values.
7. Display the series.
8. Stop the Program.
Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int f1,f2,f3,i,n;
printf(“Enter the Number\n”);
scanf(“%d”,&n);
f1=1;
f2=0;
i=1;
while(i<=n)
{
f3=f1+f2;
printf(“%d ”,f30;
f1=f2;
f2=f3;
i++;
}
getch();
}

Output:
Enter the Number

1 1 2 3 5 8 13
Addition of Two Matrices

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables and arrays to be added.
4. Accept the values of the two arrays from the user.
5. Adding of the two matrices and storage of Sum into the third Matrix.
6. Close the iteration.
7. Display the result.
8. Stop the Program.
Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int a[3],b[3],c[3],i,j,k,l,m,g;
printf(“Enter the value of Array A”);
for(i=0;i<=2,i++)
{
for(j=0;j<=2,j++)
{
scanf(“%d”,&a[i][j] );
}
}
printf(“Enter the value of Array B”);
for(k=0;k<=2,k++)
{
for(j=0;j<=2,i++)
{
scanf(“%d”,&b[i][j] );
}
}
printf(“The Addition is”);
for(m=0;m<=2,m++)
{
for(g=0;g<=2,g++)
{
c[m][g]=a[m][g]+b[m][g];
printf(“%d”’\t”,c[m][g]);

}
}
getch();
}
Output:
Enter the value of Array A

3 3 3

4 4 4

5 5 5

Enter the value of Array B

5 5 5

4 4 4

3 3 3

The Addition is

8 8 8

8 8 8

8 8 8
To Find The Largest Number Among Three Numbers

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Accept the values of the variables.
5. Check the Greatest among the three input values.
6. Print the Greatest Value.
7. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int x,y,z;
printf(“Enter the Values of X,Y,Z”);
printf(“\n”);
scanf(“%d%d%d”,&x,&y,&z);
if(x>y)
{
printf(“x=%d is greater than Y,Z”);
}
printf(“y=%d is greater than X,Z”);
}
else
{
printf(“z=%d is greater than Y,X”);
}
getch();
}

Output:
Enter the Values of X,Y,Z

12 8 10

x=12 is greater than Y,Z


Decimal To Binary Conversion

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Accept the values of the variables and enter the desired decimal value.
5. Conversion Performed.
6. Printing of the result.
7. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main( )
{
clrscr();
int d,i=0,dec,bin=0;
printf(“Enter the Decimal Value \n”);
scanf(“%d”,&dec);
while(dec)
{
d=dec%2;
bin=bin+((pow(10,i)*d));
i++;
dec=dec/2;
}
printf(“The Equivalent Binary Value is %d “,bin);
getch();
}

Output:
Enter the Decimal Value

14

The Equivalent Binary Value is 1110


To Find Even or Odd Number

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Accept the values of the variables.
5. Check the Condition.
6. Print the Value.
7. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int a;
printf(“Enter the Number”);
printf(“\n”);
scanf(“%d”,&a);
if(a%2==0)
{
printf(“Number is Even%d”,a);
}
else
printf(“Number is Odd%d”,a);
}
getch();
}

Output:
Enter the Number

Number is Odd
Multiplication of Two Matrices

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables and arrays to be added.
4. Accept the values of the two arrays from the user.
5. Multiplication of the two matrices and storage into the third Matrix.
6. Close the iteration.
7. Display the result.
8. Stop the Program.
Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int a[3][3],b[3][3],c[3][3],i,j,k,l,m,x,y;
for(i=0;i<=2,i++)
{
for(j=0;j<=2,j++)
{
printf(“Enter the values”);
scanf(“%d%d”,&a[i][j]&b[i][j] );
}
}
for(k=0;k<=2,k++)
{
for(l=0;l<=2,l++)
{
C[k][l]=0;
for(l=0;l<=2,l++)
{
C[k][l]=c[k][l]+a[l][m]*b[m][l];
}
}
}
for(x=0;x<=2,x++)
{
for(y=0;y<=2,y++)
}
{
printf(“%d”,c[x][y]);
}
getch();
}
To Display Name Of Days Of Week

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Initializing of the values to the variables and accept the values.
5. Display name of the day.
6. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("enter the number of dayz----\n");
scanf("%d",&n);
switch(n)
{
case 1:
printf("monday");
break;
case 2:
printf("tuesday");
break;
case 3 :
printf("wednesday");
break;
case 4 :
printf("thursday");
break;
case 5:
printf("friday");
break;
case 6:
printf("saturday");
break;
case 7:
printf("sunday");
break;
default:
printf("please enter the correct no.");
}
getch();
}
Output:
enter the number of dayz----

friday
To Print Whether The No. Is Prime Or Not

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Initializing of the values to the variables and accept the values.
5. Display the Number.
6. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,flag=0;
printf("Enter any no. 2 check");
scanf("%d",&a);
for(int i=2;i<=a/2;i++)
{
if((a%i)==0)
flag++;
}

if(flag==0)
{
printf("No. is prime");
}else{
printf("Not prime");
}
getch();
}

Output:
Enter any no. 2 check

No. is prime
To Print Pascal’s Triangle

Algorithm:

1. Start the program.


2. Declare the header files.
3. Declare the variables.
4. Initializing of the values to the variables and accept the values.
5. Display the Number.
6. Stop the program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int q,w,s,p;
clrscr();
for(q=1;q<=5;q++)
{
for(w=1;w<=q;w++)
{
printf("*");
}
{
printf("\n");
}
for(s=5;s>=1;s--)
{
for(p=5;p>=5;p--)
{
printf("*");
}
printf("\n");
}
getch();

}
Illustration Of Class And Objects

Algorithm:

1. Start the program.


2. Declare the header files.
3. Create The Class.
4. Declare all the variables in protected and all the functions in public.
5. Close the class.
6. Define all the functions for specific operations.
7. Create the object in the main function.
8. Call all the functions.
9. Stop the program.
Program:
#include<iostream.h>
#include<conio.h>
class students
{
long int regno;
char name[50];
public:
void getdata()
{
cout<”enter the name- ”;
cin>>name;
cout<<”enter the regno-“;
cin>>regno;
}
public:
void display()
{
cout<<”\nThe name is \n”<<name;
cout<<”\nThe regno is\n”<<gegno;
}
};
void main()
{
clrscr();
students s;
s.getdata();
s.display();
getch();
}

Output:
enter the name- Kunj Vashishtha
enter the regno- 10408878
The name is-
Kunj Vashishtha
The Regno is-
10408878
Single inheritance

Algorithm:

1. Start the program.


2. Declare the header files.
3. Create The Base Class.
4. Declare all the variables in protected and all the functions in public.
5. Initialize the valued to the variable.
6. Create the derived class and link it to the base class.
7. Declare the functions in public.
8. Declare the main function.
9. Create an object for Derived Class.
10. Call the Function in main
11. Stop the program.
Program:
#include<iostream.h>
#include<conio.h>
class base
{
protected:
float r,A;
public:
void getdata()
{
float r;
cout<”enter the radius ”<<endl;
cin>>r;
}
void calculate()
{
float r,A;
A=r*r*3.14;
}
};
class derived: public base
{
public:
void display()
{
float A;
cout<<”A Value is-“<<endl;
cout<<A;
}
};
void main()
{
clrscr();
derived d;
d.getdata();
d.calculate();
d.display();
getch();
}
Output:
enter the radius

12

A value is-
452.16
Computer Prractice 
 
Namee  :  Kun
nj Vashish
htha. 

Registtration No
o.  :  104
408878.

Sectio
on   :  H.

Subjecct Code  :  CS ‐‐ 0112. 

Semesster  :  2nd  . 

 
Accadmic Year 20
008‐20
009 

 
 

 
D
DEPARTM
MENT O
OF ELECTTRONIC
CS & COMMUN
NICATION 
SRM INSTITTUTE OF M
MANGEM
MENT & TEECHNOLO
OGY 

(SRM
M UNIVER
RSITY) 

MOD
DINAGAR,, GHAZIAB
BAD – 201 204 

 
I N D E X 
NAME : Kunj Vashishtha                                                       REG. NO.10408878 

SECTION :H    BRANCH :EC 

S.No TITLE OF EXPERIMENT Teachers


Sign.
1. Factorial Of A Number.
2. Fibonacci Series.
3. Addition of Two Matrices.

4. To Find The Largest Number Among


Three Numbers
5. Decimal To Binary Conversion

6. Multiplication of Two Matrices


7. To Display Name Of Days Of Week

8. To Print Whether The No. Is Prime Or


Not

9. To Print Pascal’s Triangle

10. Illustration Of Class And Objects(C++)

11. Single inheritance (C++)

You might also like