Focp File - Cc++ programsopy
-
Upload
karanbhalla22 -
Category
Documents
-
view
16 -
download
1
description
Transcript of Focp File - Cc++ programsopy
![Page 1: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/1.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/2.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/3.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/5.jpg)
OUTPUT SCREEN
![Page 6: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/7.jpg)
break;}}if(t==1){printf("\nLargest no.:%d",a[i]);break;}}getch();}
OUTPUT SCREEN
![Page 8: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/8.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/9.jpg)
}}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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/10.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/11.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/12.jpg)
OUTPUT SCREEN
![Page 13: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/13.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/14.jpg)
OUTPUT SCREEN
![Page 15: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/15.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/16.jpg)
getch();}
OUTPUT SCREEN
![Page 17: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/17.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/18.jpg)
OUTPUT SCREEN
![Page 19: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/19.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/20.jpg)
OUTPUT SCREEN
![Page 21: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/21.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/22.jpg)
OUTPUT SCREEN
![Page 23: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/23.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/24.jpg)
OUTPUT SCREEN
![Page 25: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/25.jpg)
PROGRAM TO SUM DIGITS OF A NUMBER ENTERED THROUGH KEYBOARD
Ask for this program from teacher in lab.
![Page 26: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/26.jpg)
OUTPUT SCREEN
![Page 27: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/27.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/28.jpg)
OUTPUT SCREEN
![Page 29: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/29.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/30.jpg)
OUTPUT SCREEN
![Page 31: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/31.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/32.jpg)
OUTPUT SCREEN
![Page 33: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/33.jpg)
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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/34.jpg)
{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](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/35.jpg)
OUTPUT SCREEN
![Page 36: Focp File - Cc++ programsopy](https://reader034.fdocuments.in/reader034/viewer/2022051108/545dd96fb0af9fec168b486d/html5/thumbnails/36.jpg)