100% found this document useful (1 vote)
646 views

Practical File For FCP B

The document contains 14 programs with descriptions and outputs. The programs include: finding the greatest number in an array and its position; finding the greatest and second greatest numbers in an array; adding and multiplying matrices; concatenating and reversing strings; checking for palindromes; and basic math operations like addition, subtraction, multiplication and division.

Uploaded by

YOGESH MUNEJA
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 DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
646 views

Practical File For FCP B

The document contains 14 programs with descriptions and outputs. The programs include: finding the greatest number in an array and its position; finding the greatest and second greatest numbers in an array; adding and multiplying matrices; concatenating and reversing strings; checking for palindromes; and basic math operations like addition, subtraction, multiplication and division.

Uploaded by

YOGESH MUNEJA
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 DOC, PDF, TXT or read online on Scribd
You are on page 1/ 28

PROGRAM-8

/*PROGRAM TO FIND A NUMBER GREATEST IN TEN


NUMBERS & PRINT IT WITH ITS POSITION*/

#include<conio.h>
#include<stdio.h>
main()
{
int a[10],i,j,t,k;
k=0;
printf(“enter ten numbers”);
for(i=0;i<10;i++)
{
if(t<a[i])
{
t=a[i];
k=i;
}
}
printf(“%d\t%d”,t,k);
getch();
}
PROGRAM-9

/*PROGRAM TO FIND THE GREATEST & SECOND


GREATEST NUMBER IN TEN NUMBERS*/

#include<conio.h>
#include<stdio.h>
main()
{
int a[10],i,j,t;
printf(“enter ten numbers”);
for(i=0;i<10;i++)
scanf(“%d”,&a[i]);
for(i=0;i<10;i++)
{
for(j=0;j<9;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf(“%d\t%d”,a[0],a[1]);
getch();
}
PROGRAM-10

/*PROGRAM TO ADD TWO MATRIX*/

#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf(“enter the elements of first matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,a[i][j]);
}
printf(“enter the elements of second matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“enter the elements of second matrix”);
}
for(i=0;i<3;i++)
{
for(j=o;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(“%d\t”),c[i][j]);
printf(“\n”);
}
getch();
}
PROGRAM-11

/*PROGRAM TO MULTIPLY TWO MATRIX*/

#include<stdio.h>
#include<conio.h>
main()
{
int a[3][3],b[3][3],c[3][3],i,j,k;
printf(“enter the elements of first matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&a[i][j]);
}
printf(“enter elements of second matrix”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf(“%d”,&b[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf(“%d\t”,c[i][j]);
printf(“\n”);
}
getch();
}
PROGRAM-12

/*PROGRAM TO CONCATENATE TWO STRING*/

#include<conio.h>
#include<stdio.h>
main()
{
char a[10],b[10];
int i,j;
printf(“enter a string”);
scanf(“%s”,a);
printf(“enter another string”);
scanf(“%s”,b);
for(i=0;a[i]!=’\0’;i++);
for(j=0;b[j]!=’\0’;j++,i++)
a[i]=b[j];
printf(“%s”,a);
getch();
}
PROGRAM-13

/*PROGRAM TO CHECK WHETHER THE STRING IS


PALLINDROM OR NOT*/

#include<stdio.h>
#include<conio.h>
main()
{
char a[10];
int i,j,flag;
printf(“enter a string”);
scanf(“%s”,a);
for(j=0;a[j]!=’\0’;j++);
for(i=0,j--;i<j;i++,j--)
{
if(a[i]==a[j])
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
printf(“string is pallindrom”);
else
printf(“string is not pallindrom”);
getch();
}
PROGRAM-14

/*PROGRAM TO REVERSE A STRING*/

#include<stdio.h>
#include<conio.h>
main()
{
char a[10],t;
int i,j;
printf(“enter a string”);
scanf(“%s”,a);
for(i=0;a[i]!=’\0’;i++);
for(j=0,i--;j<i;j++,i--)
{
t=a[i];
a[j]=a[i];
a[i]=t;
}
printf(“%s”,a);
getch();
}
PROGRAM-1

/*PROGRAM FOR ADDITION, MULTIPLICATION,


SUBTRACTION &DIVISION*/

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e,f;
printf(“enter the value of a”);
scanf(“%d”,&a);
printf(“enter the value of b”);
scanf(“%d”,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf(“\nthe sum is”);
printf(“%d”,c);
printf(“\nthe difference is”);
printf(“%d”,d);
printf(“\nthe product is”);
printf(“%d”,e);
printf(“\nthe division is”);
printf(“%d”,f);
getch();
}
PROGRAM-2

/*PROGRAM TO SWAP TWO NUMBERS USING THIRD


VARIABLE*/

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf(“enter the first number”);
scanf(“%d”,&a);
printf(“enter the second number”);
scanf(“%d”,&b);
c=a;
a=b;
b=c;
printf(“%d\t%d”,a,b);
getch();
}
PROGRAM-3

/*PROGRAM TO SWAP TWO NUMBERS WITHOUT


USING THIRD VARIABLE*/

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
printf(“enter the first number”);
scanf(“%d”,&a);
printf(“enter the second number”);
scanf(“%d”,&b);
a=a+b;
b=a-b;
a=a-b;
printf(“%d\t%d”,a,b);
getch();
}
PROGRAM-4

/*PROGRAM TO CHECK WHETHER NUMBER IS EVEN


OR ODD*/

#include<stdio.h>
#include<conio.h>
main()
{
int n;
printf(“enter a number”);
scanf(“%d”,&n);
if(n%2==0)
printf(“even number”);
else
printf(“odd number”);
getch();
}
PROGRAM-5

/*PROGAM TO FIND THE GREATEST NUMBER IN


THREE NUMBERS*/

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf(“enter three numbers”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b&&a>c)
{
printf(“%d”,a);
printf(“is greatest”);
}
else
if(b>a&&b>c)
{
printf(“%d”,b);
printf(“is greatest”);
}
else
{
printf(“%d”,c);
printf(“is greatest”);
}
getch();
}
PROGRAM-6

/*PROGRAM TO FIND THE SUM OF DIGITS OF A


NUMBER USING WHILE LOOP*/

#include<stdio.h>
#include<conio.h>
main()
{
int sum,a,n;
sum=0;
printf(“enter the number”);
scanf(“%d”,&n);
while(n>0)
{
a=n%10;
n=n/10;
sum=sum+a;
}
printf(“%d”,sum);
getch();
}
PROGRAM-7

/*PROGRAM TO FIND OUT FACTORIAL OF A


NUMBER*/

#include<stdio.h>
#include<conio.h>
main()
{
int n,a,sum;
sum=1;
printf(“enter the number”);
scanf(“%d”,&n”);
while(n>0)
{
sum=sum*n;
n--;
}
printf(“%d”,sum);
getch();
}
PROGRAM-1
OUTPUT

enter the value of a4


enter the value of b5

the sum is9


the difference is1
the product is20
thedivision is0
PROGRAM-2
OUTPUT

enter the first number45


enter the second number48
48 45
PROGRAM-3
OUTPUT

enter the first number47


enter the second number54
54 47
PROGRAM-4
OUTPUT

enter the number465


odd number
PROGRAM-5
OUTPUT

enter three numbers45 98 54


98is greatest
PROGRAM-6
OUTPUT

enter the number45


9
PROGRAM-7
OUTPUT

enter the number5


20
PROGRAM-8
OUTPUT

enter ten numbers54 21 23 45 23 12 42 12 42 15


54 0
PROGRAM-9
OUTPUT

enter ten numbers24 54 67 54 88 79 45 44 54 64


88 79
PROGRAM-10
OUTPUT

enter elements of first matrix88 44 54 56 45 85 45 12 54


enter elements of second matrix99 57 45 63 45 45 12 45 45
187 101 99
119 90 130
57 57 99
PROGRAM-11
OUTPUT

enter elements of first matrix54 85 78 54 36 24 12 45 12


enter elements of second matrix36 45 25 45 12 45 52 42 12
9825 6726 6111
4812 3870 3258
3081 1584 2469
PROGRAM-12
OUTPUT

enter a stringtech
enter another stringnology
technology
PROGRAM-13
OUTPUT

enter a stringnitin
string is pallindrom
PROGRAM-14
OUTPUT

enter a stringyatin
nitay

You might also like