41
PRACTICAL FILE PRACTICAL FILE Submitted for the partial fulfillment of requirement for the degree of Bachelor’s Of Technology (Session 2012-16) (Computer Science) Supervised by: Submitted By: Pinky Sethi Name:- Department of CSE Roll No Department of Computer Science & Engineering Dronacharya College of Engineering,

Focp File - Cc++ programsopy

Embed Size (px)

DESCRIPTION

it is re quired for project

Citation preview

Page 1: Focp File - Cc++ programsopy

PRACTICAL FILEPRACTICAL FILESubmitted for the partial fulfillment of requirement for the

degree of

Bachelor’s Of Technology (Session 2012-16)

(Computer Science)

Supervised by: Submitted By:

Pinky Sethi Name:-

Department of CSE Roll No

Department of Computer Science & Engineering

Dronacharya College of Engineering,

Farrukh Nagar, Gurgaon

Page 2: Focp File - Cc++ programsopy

CERTIFICATE

This is to certify that, Roll No. student of first

Semester (CSE) has completed his practical

file under the guidance and supervision of

undersigned.

Pinky Sethi Head of the DepartmentDepartment of CSE Department of Applied Sciences

Page 3: Focp File - Cc++ programsopy

S.NO

PROGRAM DATE SIGN

1. Program to find largest of three numbers.

2. Program to find largest number out of 10.

3. Program to find largest and second largest out of ten numbers.

4. Program to add two matrices.

5. Program to concatenate two strings.

6. Program to check whether the input string is palindrome or not.

7. Program to find factorial of a number entered through Keyboard.

8. Program to swap two numbers.

9. Program to reverse a number entered through keyboard

10. Program to sum digits of a number entered through keyboard.

11. Program to reverse a string.

12 Program to check whether a number is prime or not.

13. Program to implement linear search.

Page 4: Focp File - Cc++ programsopy

14. Program to Draw Pyramid of stars

15. Program to multiply two matrices.

PROGRAM TO FIND LARGEST OF THREE NUMBERS

#include<stdio.h>#include<conio.h>void main( ){Clrscr();float a,b,c;printf(“Enter any three numbers:”);scanf(“%f%f%f”,&a,&b,&c);if((a>b)&&(a>c)){printf(“Largest of three numbers: %f”,a);}elseif((b>a)&&(b>c)){printf(“Largest of three numbers: %f”,b);}else{printf(“Largest of three numbers: %f”,c);}getch( );

Page 5: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 6: Focp File - Cc++ programsopy

PROGRAM TO FIND LARGEST NUMBER OUT OF TEN NUMBERS

#include<stdio.h>#include<conio.h>void main(){int a[10],i,s=0,j,t;clrscr();printf(“Enter ten numbers:”);for(i=0;i<10;i++){scanf("%d",&a[i]);}for(i=0;i<10;i++){for(j=i+1;j<10;j++){if(a[i]>a[j]){t=1;}else{t=0;

Page 7: Focp File - Cc++ programsopy

break;}}if(t==1){printf("\nLargest no.:%d",a[i]);break;}}getch();}

OUTPUT SCREEN

Page 8: Focp File - Cc++ programsopy

WRITE A PROGRAM TO FIND LARGEST AND SECOND LARGEST NUMBER OUT OF GIVEN NUMBER

#include<stdio.h>#include<conio.h>void main(){int i,j=0,a[55],n,l=0,sl=0;clrscr();printf("\n\n\n\n\n\n\n\t\t How many numbers do you want to enter:");scanf("%d",&n);printf("\n\n\t\t Enter the numbers:");for(i=0;i<n;i++){scanf("%d",&a[i]);}for(i=0;i<n;i++){if(a[i]>l){l=a[i];j=i;

Page 9: Focp File - Cc++ programsopy

}}printf("\n\n\t\t Largest element is:%d",l);sl=a[n-j-1];for(i=0;i<n;i++){if((a[i]>sl)&&(j!=i)){sl=a[i];}}printf("\n\n\t\t Second Largest element is:%d",sl);getch();}

OUTPUT SCREEN

Page 10: Focp File - Cc++ programsopy

WRITE A PROGRAM TO FIND SUM OF TWO MATRICES

#include<stdio.h>#include<conio.h>void main(){int a[10][10],b[10][10],c[10][10];int i,j,k,r1,r2,c1,c2;clrscr();printf("\n\n\n\n\n\n\n\t\t Enter the order of matrix A:");scanf("%d%d",&r1,&c1);printf("\n\n\t\t Enter the order of matrix B:");scanf("%d%d",&r2,&c2);printf("\n\n\t\t Enter the element of matrix A:");for(i=0;i<r1;i++){for(j=0;j<c1;j++){scanf("%d",&a[i][j]);}}printf("\n\n\t\t Enter the element of matrix B:");for(i=0;i<r2;i++){for(j=0;j<c2;j++){scanf("%d",&b[i][j]);}}printf("Matrix A :");for(i=0;i<r1;i++){

Page 11: Focp File - Cc++ programsopy

for(j=0;j<c1;j++){printf("%d",a[i][j]);printf(" ");}}printf("\n\n\t\tMatrix B:");for(i=0;i<r2;i++){for(j=0;j<c2;j++){printf("%d",b[i][j]);printf(" ");}Printf(“\n\n\t\t\t\t “);}for(i=0;i<r1;i++){for(j=0;j<c2;j++){c[i][j]=a[i][j]+b[i][j];}}printf("\n\n\t\tSum of the matrices :");for(i=0;i<r1;i++){for(j=0;j<c2;j++){printf("%d",c[i][j]);printf(" ");}Printf(“\n\n\t\t\t\t\t “):}getch();}

Page 12: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 13: Focp File - Cc++ programsopy

WRITE A PROGRAM TO CONCATINATE TWO STRINGS

#include<stdio.h>#include<conio.h>void main(){char a[25],b[25],c[25];int i,j;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter first string:");scanf("%s",a);printf("\n\n\t\t\tEnter second string:");scanf("%s",b);for(i=0;a[i]!='\0';i++)c[i]=a[i];for(j=0; b[j]!='\0'; j++)c[i+j]=b[j];c[i+j]='\0';printf("\n\n\t\t\tThe concatenated string is:%s",c);getch();}

Page 14: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 15: Focp File - Cc++ programsopy

PROGRAM TO CHECK THAT THE INPUT STRING IS A PALINDROME OR NOT

#include<stdio.h>#include<conio.h>#include<process.h>void main(){char a[20],i,b[20],g=0,j,m;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter any string:");scanf("%s",a);for(i=0;a[i]!='\0';i++){g++;}j=g-1;for(i=0;i<g;i++){b[j]=a[i];j--;}for(i=0;i<g;i++){if(b[i]==a[i])m=0;else{m=1;break;}}if(m==0){printf("\n\n\t\t\tString is a Palindrome!!");}elseif(m==1){printf("\n\n\t\t\tString is not a Palindrome!!");}

Page 16: Focp File - Cc++ programsopy

getch();}

OUTPUT SCREEN

Page 17: Focp File - Cc++ programsopy

WRITE A PROGRAM TO FIND FACTORIAL OF A NUMBER

#include<stdio.h>#include<conio.h>void main(){int a,i,fact=1;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter the number:");scanf("%d",&a);for(i=1;i<=a;i++){fact=fact*i;}printf("\n\n\t\t\tThe factorial is:%d",fact);getch();}

Page 18: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 19: Focp File - Cc++ programsopy

WRITE A PROGRAM TO SWAP TWO NUMBERS

#include<stdio.h>#include<conio.h>void main(){int a,b,temp;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter the numbers a & b:");scanf("%d%d",&a,&b);temp=a;a=b;b=temp;printf("\n\n\t\t\tThe swapped values are:");printf("%d %d",a,b);getch();}

Page 20: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 21: Focp File - Cc++ programsopy

WRITE A PROGRAM TO FIND REVERSE OF A NUMBER

#include<stdio.h>#include<conio.h>void main(){int n,b,s=0;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter the number:");scanf("%d",&n);while(n!=0){b=n%10;s=(s*10)+b;n=n/10;}printf("\n\n\t\t\tThe reverse number is:%d",s);getch();}

Page 22: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 23: Focp File - Cc++ programsopy

PROGRAM TO READ A STRING AND WRITE IT IN REVERSE ORDER

#include<stdio.h>#include<conio.h>void main(){char a[20],i,b[20],g=0,j;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter any string:");scanf("%s",a);for(i=0;a[i]!='\0';i++){g++;}j=g-1;for(i=0;i<g;i++){b[j]=a[i];j--;}printf("\n\n\t\t\tReverse order of string:%s",b);getch();}

Page 24: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 25: Focp File - Cc++ programsopy

PROGRAM TO SUM DIGITS OF A NUMBER ENTERED THROUGH KEYBOARD

Ask for this program from teacher in lab.

Page 26: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 27: Focp File - Cc++ programsopy

WRITE A PROGRAM TO CHECK THAT INPUT NUMBER IS PRIME OR NOT

#include<stdio.h>#include<conio.h>void main( ){int num, i;clrscr( ) ;printf("\n\n\n\n\n\n\n\t\t\tEnter a no.:") ;scanf("%d", & num) ;i=2 ;while(i<=(num-1)){if(num%i==0){printf("\n\n\t\t\t%d is not a Prime Number.",num);break;}i++ ;}if(i==num)printf("\n\n\t\t\t%d is Prime Number.",num);getch();}

Page 28: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 29: Focp File - Cc++ programsopy

PROGRAM TO IMPLEMENT LINEAR SEARCH

#include<stdio.h> #include<conio.h> #include<stdlib.h>void main(){ int arr[100],i,element,no; clrscr(); printf("\nEnter the no of Elements: "); scanf("%d", &no); for(i=0;i<no;i++){ printf("\n Enter Element %d: ", i+1); scanf("%d",&arr[i]); } printf("\nEnter the element to be searched: "); scanf("%d", &element); for(i=0;i<no;i++){ if(arr[i] == element){ printf("\nElement found at position %d",i+1); getch(); exit(1); } } printf("\nElement not found"); getch(); }

Page 30: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 31: Focp File - Cc++ programsopy

WRITE A PROGRAM TO PRINT PYRAMID STAR

#include<stdio.h>#include<conio.h>void main(){int i,a,j,k;clrscr();printf("\n\n\n\n\n\n\n\t\t\tEnter the number of lines:");scanf("%d",&a);for(i=0;i<a;i++){printf("\n\t\t\t\t");for(j=0;j<10-i;j++){printf(" ");}for(k=0;k<=2*i;k++){ printf("*");}}getch();}

Page 32: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 33: Focp File - Cc++ programsopy

WRITE A PROGRAM TO MULTIPLY TWO MATRICES

#include<stdio.h>#include<conio.h>#include<process.h>void main(){int a[10][10],b[10][10],c[10][10];int i,j,m,n,p,q,s;clrscr();printf("\n\n\n\n\n\n\n\t\t\tInput row and column of matrix-A:");scanf("%d%d",&m,&n);printf("\n\n\t\t\tInput row and column of matrix-B:");scanf("%d%d",&p,&q);if(n!=p){printf("\n\n\n\t\t\tMatrix cannot be multiplied");getch();exit(0);}printf("\n\n\t\t\tInput Matrix-A:");for(i=0;i<m;i++){for(j=0;j<n;j++)

Page 34: Focp File - Cc++ programsopy

{scanf("%d",&a[i][j]);}}printf("\n\n\t\t\tInput Matrix-B:");for(i=0;i<p;i++){for(j=0;j<q;j++){scanf("%d",&b[i][j]);}}for(i=0;i<m;i++){for(j=0;j<q;j++){c[i][j]=0;for(s=0;s<n;s++)c[i][j]=c[i][j]+a[i][s]*b[s][j];}}printf("\n\n\t\t\tProduct of matrix A and matrix B is: ");for(i=0;i<m;i++){for(j=0;j<q;j++){printf("%d ",c[i][j]);}printf("\n\n\t\t\t\t\t\t\t ");}getch();}

Page 35: Focp File - Cc++ programsopy

OUTPUT SCREEN

Page 36: Focp File - Cc++ programsopy