BIRLA INSTITUTE OF T ECHNOLOGY, MESRA
DEPARTMENT OF REMOTE SNSING
A
PRACTICAL FILE
ON
“COMPUTER PROGRAMMING LAB”
(TRS 2022)
MASTER OF TECHNOLOGY
(REMOTE SENSING )
(20012-2014)
SUBMITTED BY -
SUMANT KR. DIWAKAR
C Practical File
Sumant Diwakar
Program:
Write a Program in C to convert Temperature from Fahrenheit
to Celsius.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
float Fahrenheit, Celsius;
clrscr();
printf("Enter Temperature in Fahrenheit: ");
scanf("%f",&Fahrenheit);
Celsius = 5.0/9.0 * (Fahrenheit-32);
printf("\n\n Temperature in Fahrenheit = %.2f",
Fahrenheit);
printf("\n\n Temperature in Celsius = %.2f",
Celsius);
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to check the number for Perfect Square.
Source Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int a, n;
clrscr();
printf("Enter a number: ");
scanf("%d", &n);
for(a = 0; a <= n; a++)
{
if (n == a * a)
{
printf("\n\n\tYES, Number is Perfect Square
Number");
}
}
printf("\n\n\tNO, Not a Perfect square number");
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to arrange numbers in Ascending and
Descending Order.
Program:
Write a Program in C to check the entered uppercase characters
for vowel using switch statement.
Source Code:
#include <stdio.h>
void main()
{
char ch;
clrscr();
printf("\nInput a character in UPPERCASE only: ");
scanf("%c", &ch);
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("\n\t%c is a vowel.\n", ch);
break;
default:
printf("\n\t%c Not in UPPERCASE\n", ch);
}
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the Factorial of a number.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int f=1,i,n;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
while(i<=n)
{
f=f * i;
i=i+1;
}
printf("Factorial of %d is %d",n,f);
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the number and their sum between
100 to 200 which are divisible by 7.
int n1,n2,sum=0;
clrscr();
printf("\nThe Number which are divisible by 7
are\n\n");
for(n1=100; n1<200; n1++)
{
if(n1%7==0)
{
printf("%d\t",n1);
sum=sum+n1;
}
}
printf("\nSum of numbers that are divisible by 7 is
= %d",sum);
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the number is prime number or
Composite number.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,np=0; //np is boolean operator (true/false)
clrscr();
printf("\n Enter a number :");
scanf("%d",&n);
for(i=2;i<=(n-1);i++)
{
if(n%i==0)
{
np=1;
break; //come out of for loop
}
}
if(np==1) // in if statement np=1 ,it confirms that
number is composite.
{
printf("\n\n%d is composite number.",n);
}
else
{
printf("\n\n%d is a prime number.",n);
}
getch();
}
C Practical File
Sumant Diwakar
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the Average of Five Numbers.
Source Code:
# include <stdio.h>
#include <conio.h>
void main()
{
int first, second, third, fouth, fifth, sum=0, avg=0;
clrscr();
printf("Enter First Number:");
scanf("%d", &first);
printf("\n\nEnter Second Number:");
scanf("%d", &second);
printf("\n\nEnter Third Number:");
scanf("%d", &third);
printf("\n\nEnter Fourth Number:");
scanf("%d", &fourth);
printf("\n\nEnter Fifth Number:");
scanf("%d", &fifth);
sum = (first+second+third+fourth+fifth);
avg = sum/5;
printf("\n\n\tThe Average of Five Number is : %d",avg);
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the Biggest and smallest number
from the given list of numbers.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,big,sml,i,totalNumber;
clrscr();
printf("\n How many number you will enter : ");
scanf("%d",&totalNumber);
for (i=0;i<totalNumber;i++)
{
printf("\n Enter number %d : ",i+1);
scanf("%d",&n);
if(i==0)
{
big=sml=n;
}
if(big<n) big=n;
if(sml>n) sml=n;
}
printf("\n\nBiggest number is: %d",big);
printf("\n\nSmallest number is : %d",sml);
getch();
}
C Practical File
Sumant Diwakar
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the sum of a digit of a number.
Source Code:
#include<stdio.h>
void main()
{
int num,sum=0,r;
printf("Enter a number: ");
scanf("%d",&num);
while(num){
r=num%10;
num=num/10;
sum=sum+r;
}
printf("Sum of digits of number: %d",sum);
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to enter three digit numbers and find the
sum of the digits.
Source Code:
#include<stdio.h>
void main()
{
int num,sum=0,r;
clrscr();
printf("Enter a #-digit number[100-999]: ");
scanf("%d",&num);
if(num>999 && num<100)
printf("\n\nSorry!, Number Out of Range ");
else
{
while(num)
{
r=num%10;
num=num/10;
sum=sum+r;
}
printf("\nSum of digits of number: %d",sum);
}
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to generate the Fibonacci Series.
(0, 1, 1, 2, 3, 5, 8…)
Source Code:
#include <stdio.h>
void main()
{
int n, first = 0, second = 1, next, c;
clrscr();
printf("Enter the number of terms:");
scanf("%d",&n);
printf("\n\nFirst %d terms of Fibonacci series are :-
\n\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d ",next);
}
getch();
}
C Practical File
Sumant Diwakar
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to display the following patterns using
loop.
Sumant Diwakar
Program:
Write a Program in C to find factorial of given number using
recursive function.
Source Code:
#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("Enter the value for A and B\n");
scanf("%d %d",&a,&b);
printf("\nBefore Swaping:\n\n\tA= %d, B=%d",a,b);
swap(a,b);
getch();
}
swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("\n\nAfter Swaping:\n\n\tA=%d, B=%d",x,y);
}
Output:
C Practical File
Sumant Diwakar
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find factorial of given number using
recursive function.
Source Code:
#include<stdio.h>
main()
{
int a, fact;
printf("\nEnter any number: ");
scanf ("%d", &a);
fact=rec (a);
printf("\nFactorial Value = %d", fact);
}
rec (int x)
{
int f;
if (x==1)
return (1);
else
f=x*rec(x-1);
return (f);
}
C Practical File
Sumant Diwakar
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to print Identity Matrix.
Program:
Write a Program in C to find the addition of two 3 x 3 matrices.
C Practical File
Sumant Diwakar
Source Code:
#include<stdio.h>
Void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("Enter the First matrix->");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
printf("\nThe Second matrix is\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",b[i][j]);
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
printf("\nThe Addition of two matrix is\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",c[i][j]);
}
C Practical File
Sumant Diwakar
getch();
}
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the multiplication of two matrices.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,sum=0,m,n,o,p;
clrscr();
printf("\nEnter the row and column of first matrix");
scanf("%d %d",&m,&n);
printf("\nEnter the row and column of second matrix");
scanf("%d %d",&o,&p);
if(n!=o)
{
printf("Matrix mutiplication is not possible");
printf("\nColumn of first matrix must be same
as row of second matrix");
}
else
{
printf("\nEnter the First matrix->");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the Second matrix->");
for(i=0;i<o;i++)
for(j=0;j<p;j++)
scanf("%d",&b[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<n;j++){
printf("%d\t",a[i][j]);
}
}
printf("\nThe Second matrix is\n");
C Practical File
Sumant Diwakar
for(i=0;i<o;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",b[i][j]);
}
}
for(i=0;i<m;i++)
for(j=0;j<p;j++)
c[i][j]=0;
for(i=0;i<m;i++){ //row of first matrix
for(j=0;j<p;j++){ //column of second matrix
sum=0;
for(k=0;k<n;k++)
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;
}
}
}
printf("\nThe multiplication of two matrix is\n");
for(i=0;i<m;i++){
printf("\n");
for(j=0;j<p;j++){
printf("%d\t",c[i][j]);
}
}
getch();
}
C Practical File
Sumant Diwakar
Output:
C Practical File
Sumant Diwakar
Program:
Write a Program in C to find the length of a string and count the
number of vowel in it.
Source Code:
#include <stdio.h>
#include <string.h>
void main()
{
char str[50];
int vowels=0;
int consonants=0;
int space=0;
int len,i;
printf("enter the string \ n \n");
gets(str);
len=strlen(str);
for(i=0; i< len ;i++)
{