0% found this document useful (0 votes)
9 views

PPS PROGRAMS FINAL-Copy

It is a pps file type presentation with programming of c+

Uploaded by

Vansh Sohal
Copyright
© © All Rights Reserved
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)
9 views

PPS PROGRAMS FINAL-Copy

It is a pps file type presentation with programming of c+

Uploaded by

Vansh Sohal
Copyright
© © All Rights Reserved
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/ 25

VIBHU BHASIN,858/22,BTPS102-18

PROGRAM: 30
AIM: - A Program For Multiplication Of Matrices

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART:-0

PROGRAM:-
#include<stdio.h>

#include<conio.h>

void main()

float a[10][10], b[10][10], c[10][10];

int n,m,p,q,i,j,k;

58
VIBHU BHASIN,858/22,BTPS102-18

printf("enter size of A:");

scanf("%d %D",&m,&n);

printf("enter size of B:");

scanf("%d %d",&p, &q);

if(n==p)

printf("enter elements of A:");

for(i=0; i<m; i++)

for(j=0; j<n; j++)

scanf("%f",&a[i][j]);

printf("enter elements of B:");

for(i=0; i<p; i++)

for(j=0; j<q; j++)

scanf("%f",&b[i][j]);

for(i=0; i<m; i++)

for(j=0; j<q; j++)

c[i][j]=0;

for(k=0; k<n; k++)

c[i][j]+=a[i][k]*b[k][j];

printf("product is \n");

for(i=0; i<m; i++)

59
VIBHU BHASIN,858/22,BTPS102-18

for(j=0; j<q; j++)

printf("%f",c[i][j]);

printf("\n");

getch();

OUTPUT:-

60
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM: 31
AIM: - A Program For Transpose Of A Matrix

SOFTWARE USED: - Turbo C (Version 3.0)

FLOWCHART:

61
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10];
int i,j,m,n;
clrscr();
printf("enter the rows and coloumns of A:\n");
scanf("%d %d",&m,&n);
printf("enter the elements of matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[i][j]=a[j][i];
printf("transpose is\n");
for(i=0;i<m;i++){
for(j=0;j<m;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:-

62
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:- 32

AIM:- To Demonstrate The Concept Of Call By Value In Functions

SOFTWARE USED:-Turbo C++(Version 3.0)


FLOWCHART:

PROGRAM:-
#include<stdio.h>

#include<conio.h>

int mul(int x, int y, int z);

void main()

int a,b,c,prod;

printf("enter three numbers:");

63
VIBHU BHASIN,858/22,BTPS102-18

scanf("%d%d%d",&a,&b,&c);

prod=mul(a,b,c);

printf("product is: %d",prod);

getch();

int mul(int x, int y, int z)

int p;

p=x*y*z;

return(p);

OUTPUT:-

64
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:- 33

AIM:- To Demonstrate The Concept Of Call By Reference In Functions

SOFTWARE USED: Turbo C++(Version 3.0)

FLOWCHART:

PROGRAM:-
#include<stdio.h>

#include<conio.h>

void swap(int *, int *);

void main()

int a=10, b=20;

clrscr();

65
VIBHU BHASIN,858/22,BTPS102-18

printf("\n before swapping, a=%d",a);

printf("\n before swapping, b=%d",b);

swap(&a,&b);

printf("\n after swapping, a=%d",a);

printf("\n after swapping, b=%d",b);

getch();

void swap(int *x, int *y)

int temp;

temp=*x;

*x=*y; f

*y=temp;

OUTPUT:-

66
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-34

AIM:- To Demonstrate The Concept Of Local And Global Variables In Functions

SOFTWARE USED:-Turbo C++(Version 3.0)


FLOWCHART:

PROGRAM:

#include<stdio.h>

#include<conio.h>

//global variable

int a=20;

int sum(int, int);

void main()

67
VIBHU BHASIN,858/22,BTPS102-18

//local variables

int a=10, b=20;

int c;

clrscr();

printf("value of a before function call: %d",a);

c=sum(a,b);

printf("value of c= %d",c);

getch();

int sum(int a, int b){

printf("after function call, a= %d\n", a);

printf("after function call, b= %d\n", b);

return a+b;

OUTPUT:-

68
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-35

AIM:- To Print Factorial Of A Number Using Functions

SOFTWARE USED:-Turbo C++(Version 3.0)


FLOWCHART:

START

Read n

I=1

Fact=1

Is i<=n

Fact=fact*i
Print fact

I=i+1
END

69
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-
#include<stdio.h>

#include<conio.h>

int fact(int n);

void main(){

int n, factorial;

clrscr();

printf("enter a no. whose factorial you want:- ");

scanf("%d", &n);

factorial=fact(n);

printf("\n factorial of %d = %d",n,factorial);

getch();

int fact(int n)

int i=1, fact=1;

for(i=1; i<=n; i++)

fact=fact*i;

return (fact);

OUTPUT:-

70
VIBHU BHASIN,858/22,BTPS102-18

71
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-36

AIM:- To Print Fibonacci Series Using Functions

SOFTWARE USED:-Turbo C++(Version 3.0)


FLOWCHART:

72
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-
#include<stdio.h>

#include<conio.h>

int fib(int i);

void main()

int n,j;

clrscr();

printf("enter number of elements:-");

scanf("%d", &n);

for(j=1; j<=n; j++)

printf("%d", fib(j));

getch();

int fib(int i)

static int p=1, c=1;

int next;

if(i==1||i==2)

return(1);

else

next=p+c;

p=c;

c=next;

73
VIBHU BHASIN,858/22,BTPS102-18

return(next);

OUTPUT:-

74
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:- 37

AIM:- To Calculate Interest Using User-Defined Functions

SOFTWARE USED:-Turbo C++(Version 3.0)

FLOWCHART:-

PROGRAM:-
#include<stdio.h>

#include<conio.h>

float si(float p, float r, float t);

void main()

75
VIBHU BHASIN,858/22,BTPS102-18

float p,r,t,interest;

clrscr();

printf("enter principal amount: ");

scanf("%f",&p);

printf("enter rate of interest: ");

scanf("%f",&r);

printf("enter time period: ");

scanf("%f",&t);

interest=si(p,r,t);

printf("interest = %f",interest);

getch();

float si(float p, float r, float t)

float x;

x=(p*r*t)/100;

return x;

OUTPUT:-

76
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-38

AIM:- To Print Sum Of N Numbers Using Recursive Functions

SOFTWARE USED:-Turbo C++(Version 3.0)

FLOWCHART:-

PROGRAM:-
#include<stdio.h>

#include<conio.h>

int sum(int);

77
VIBHU BHASIN,858/22,BTPS102-18

void main(){

int n,temp;

clrscr();

printf("till what no. you want the sum: ");

scanf("%d",&n);

temp=sum(n);

printf("value=%d",temp);

getch();

int sum(int n)

int value=0;

if(n==0)

return(value);

else

value= n+(sum(n-1));

return(value);

OUTPUT:-

78
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-39

AIM:- To Print GCD Of Two Numbers Using Recursive Functions

SOFTWARE USED:-Turbo C++(Version 3.0)

FLOWCHART:-

PROGRAM:-
#include<stdio.h>

#include<conio.h>

int hcf(int, int);

79
VIBHU BHASIN,858/22,BTPS102-18

void main()

int n1,n2;

clrscr();

printf("enter two numbers:");

scanf("%d %d",&n1,&n2);

printf("gcd of %d and %d is %d",n1,n2,hcf(n1,n2));

getch();

int hcf(int n1, int n2)

if(n2!=0)

return hcf(n2, n1%n2);

else

return n1;

OUTPUT:-

80
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-40

AIM:- To Demonstrate The Concept Of Pointers

SOFTWARE USED:-Turbo C++(Version 3.0)

FLOWCHART:-

START

DECLARE C=22 AND


PC

PRINT VALUE AND


ADDRESS OF C AND
PC

END

81
VIBHU BHASIN,858/22,BTPS102-18

PROGRAM:-
#include<stdio.h>

#include<conio.h>

void main()

int c,*pc;

clrscr();

c=22;

printf("address of c: %p\n", &c);

printf("value of c: %d\n",c);

pc=&c;

printf("address of pointer pc: %p\n",pc);

printf("value of pointer pc: %d\n", *pc);

getch();

OUTPUT:-

82

You might also like