Program 01.01:-: Practical Assignment - Programing in C'
Program 01.01:-: Practical Assignment - Programing in C'
Program 01.01:-
/* Write a program to interchange value of two variables without
#include<stdio.h>
#include<conio.h>
void main()
int a,b;
clrscr();
scanf("%d",&a );
scanf("%d",&b );
a=a+b;
b=a-b;
a=a-b;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
getch();
The value of a = 20
The value of b = 40
The value of a = 60
The value of b = 20
The value of a = 40
a= 40
b= 20
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program 01.02:-
/* W.A.P to interchange two no with using third variable.
#include<stdio.h>
#include<conio.h>
void main()
int a,b,c;
clrscr();
scanf("%d",&a);
scanf("%d",&b);
c=a;
a=b;
b=c;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
The value of a is 20
The value of b is 10
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program 2:-
/* Write a program to convert temperature in degree fahrenheit to degree
#include<stdio.h>
#include<conio.h>
main()
float c,f;
clrscr();
scanf("%f",&f );
c=(5.0/9.0)*(f-32.0);
printf("\n%f",c);
getch();
Temperature in celsius
100.555557
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program3:-
/*W.A.P to change in kilometers into meter,inchies,centimeters,feet.
# include <iostream>
# include <cmath>
# include <string>
double feet;
double inches;
double meters;
double centimeters;
double final;
double conversion();//prototype
output ();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
double conversion ()
return 0;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program4:-
/*W.A.p to find the simple interest.
#include<stdio.h>
#include<conio.h>
void main()
int p,t,r,si;
clrscr();
scanf("%d",&p);
scanf("%d",&r);
scanf("%d",&t);
si=(p*t*r)/100;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
enter the time in years= 3
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program05.01:-
/*W.A.P to find the area and parameter of rectangle. Karan Jain B.C.A 1st year
1205 */
#include<stdio.h>
#include<conio.h>
void main()
scanf("%d",&l);
scanf("%d",&b);
area=l*b;
perimeter=2*(l+b);
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program05.02:-
/*W.A.P to find the area and perimeter of circle.
#include<stdio.h>
#include<conio.h>
void main()
float radius,perimeter,area;
scanf("%f",&radius);
perimeter=2*3.14*radius;
area=3.14*radius*radius;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program06:-
/* Write a program to calculate the gross salary for any basic salary entered
through keyboard where dearness allowance is 15% of basic salary and house
#include<stdio.h>
#include<conio.h>
void main()
int net_sal,gro_sal,dear_all,ho_rent;
clrscr();
scanf("%d" ,&net_sal);
dear_all=0.14*net_sal;
ho_rent=0.25*net_sal;
gro_sal=net_sal+dear_all+ho_rent;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Enter the net salary2500
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program07:-
/* Write a program to find the sum,div,pro,sub,mod of two no.
#include<stdio.h>
#include<conio.h>
void main()
int a,b,c,d,e,f,g;
clrscr();
scanf("%d" ,&a);
scanf("%d" ,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
g=a%b;
getch();
The sum = 88
The sub = 42
The div = 2
The mod = 19
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program08:-
/* W.A.P to check the no is odd or even.
#include<stdio.h>
#include<conio.h>
void main()
int n ;
clrscr();
scanf("%d",&n);
if(n%2==0)
printf("no is even\n");
else
printf("no. is odd\n");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
enter a number :6
no is even
enter a number :5
no. is odd
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program09:-
/*W.A.P to enter a no and find out that the no is (+ve),(-ve),0.
#include<stdio.h>
#include<conio.h>
void main()
int i,a[20],n,countp=0,countn=0,countz=0;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
if(a[i]>0)
countp++;
else if(a[i]<0)
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
{
countn++;
else
countz++;
getch();
Enter the no 3
-2
There are 1 0 no
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program10:-
/* W.A.P to input the current year and date joining year of an empolyee if the
service time is more than 3 years then company will give 3000/-as bonous.
#include<stdio.h>
#include<conio.h>
void main()
int cur_yr=2010,dt_of_yr,ser_time;
scanf("%d",&dt_of_yr);
ser_time=cur_yr-dt_of_yr;
if(ser_time>3)
printf("\n3000/-as bonus");
else
printf("\nno bonous");
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
getch();
3000/-as bonus
no bonous
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program11:-
/*W.A.P to determine whether the input year is leap or not use logical
operator &&||.
#include<stdio.h>
#include<conio.h>
void main()
int year;
if (year%4==0)
else
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Enter the year 2005
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program12:-
/*W.A.P to find the seller made profit or incurred loss. Also determine how
#include<stdio.h>
#include<conio.h>
void main()
int cost_price,sell_price,profit_loss;
clrscr();
scanf("%d",&cost_price);
scanf("%d",&sell_price);
profit_loss=sell_price-cost_price;
if(profit_loss>0)
else
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
{
if(profit_loss<0)
else
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
The Profit or loss is 0
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program13:-
/* W.A.P a discount of 10% is offered if the quantity purchased more than 1000.
#include<stdio.h>
#include<conio.h>
void main( )
if ( bs < 1500 )
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
else
hra = 500 ;
da = bs * 98 / 100 ;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
gs = bs + hra + da ;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program14:-
/*Example : In a company an employee is paid as under: If his basic salary is less
than
$ 1500, then HRA = 10% of basic salary and DA = 90% of basic salary.
If his salary is either equal to or above $ 1500, then HRA = $ 500 and DA = 98%
of
#include<stdio.h>
#include<conio.h>
void main( )
if ( bs < 1500 )
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
else
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
{
hra = 500 ;
da = bs * 98 / 100 ;
gs = bs + hra + da ;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program15:-
/*W.A.P to calculate the grade of students according to marks obetained in 5
subjects:-
a) % above or = 60 first
b) % between 50 to 59 second
c) % between 40 to 49 third
#include<stdio.h>
#include<conio.h>
void main()
int m1,m2,m3,m4,m5,per;
clrscr();
scanf("%d",&m1);
scanf("%d",&m2);
scanf("%d",&m3);
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
scanf("%d",&m4);
scanf("%d",&m5);
per=(m1+m2+m3+m4+m5)/5;
if(per>=60)
printf("\nfirst division");
else
if(per>=50<=60)
printf("\nsecond division");
else
if(per>=40<=50)
printf("\nthird division");
else
printf("\nfail");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Enter the marks in second subject 21
first division
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program16:-
/*Write a program is to determine whether an employee is male and unmerried
above 30 years
#include<stdio.h>
#include<conio.h>
main()
char sex,ms;
int age;
if (ms=='M')
else
if (sex=='M')
if (age>30)
else
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
printf ("Driver is not insured");
else
if (age>25)
else
getch();
Driver is insured
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program17:-
/*W.A.P to determine the character rntered is capital letter ,lower letter
#include<stdio.h>
#include<conio.h>
void main()
char charac;
scanf("%c", &charac);
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
printf("The entered character is a Number");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program18:-
/* W.A,P to cnvert decimal to binary number system.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
clrscr();
scanf("%ld",&n);
for (i=0;n>=1;i++)
a[i]=n%10;
n=n/10;
count=count + 1;
for (i=0;i<=count-1;i++)
b[i]=pow(2,i);
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
for (i=0;i<=count-1;i++)
c[i]=a[i] * b[i];
sum=sum +c[i];
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program19:-
/*W.A.P to sum up series 1+1/2+1/3+1/4+--------------+pow(-1)n*1/n.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
int n,i,count;
float sum;
clrscr();
scanf("%d",&n);
i=1;
count=1;
sum=0.0;
while(count<=n)
sum+=(float)pow(-1,count-1)/i;
i++;
count++;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
printf("\n%f",sum);
getch();
Enter the no 21
0.716390
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program20:-
/*W.A.P to Reverse of the Number.
#include<stdio.h>
#include<conio.h>
void main()
int a,b,c,d,e;
clrscr();
scanf("%d",&a);
while(a!=0)
b=a%10;
c=a/10;
printf("%d",b);
a=c;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program21:-
/*Write a program to find the factorial value of number
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
temp=1;
factorial=1;
while (temp<=number)
factorial=factorial*temp;
temp++;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program22:-
/*W.A.P to check a no is armstrong or not.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
int n,sum=0,rem=0,cube=0,n1,i;
clrscr();
scanf("%d",&n);
n1=n;
while(n!=0)
rem=n%10;
cube=pow(rem,3);
sum=sum+cube;
n=n/10;
if(sum==n1)
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
{
printf("\n\tangstrom");
else
printf("\n\tnot armstromg");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program24:-
/*W.A.P program to find the sum of entered digit.
#include<stdio.h>
#include<conio.h>
void main()
int n,num,x,sum=0;
clrscr();
printf("Enter a number=");
scanf("%d",&n);
while(n>0)
x=n%10;
sum=sum+x;
n=n/10;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program25:-
/*W.A.P to print prime numbers.
#include<stdio.h>
#include<conio.h>
void main()
int i,j,n;
clrscr();
scanf("%d",&n);
printf("\n");
for(i=2;i<=n;i++)
for(j=2;j<=i-1;j++)
if(i%j==0)
break;
if(i==j)
printf("\t%d",i);
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
2 3 5 7 11 13 17 19 23
29 31 37 41 43 47 53 59 61 67
113
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program26:-
/* Write a program to calculate the n tables.
#include<stdio.h>
#include<conio.h>
void main()
int i,n,j,r;
clrscr();
scanf("%d",&n);
for (i=1;i<=n;i++)
for (j=1;j<=10;j++)
r=i*j;
printf(" \n%d*%d=%d",i,j,r);
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
Enter the no 4
The table of 1 is
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10
The table of 2 is
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
2*9=18
2*10=20
The table of 3 is
3*1=3
3*2=6
3*3=9
3*4=12
3*5=15
3*6=18
3*7=21
3*8=24
3*9=27
3*10=30
The table of 4 is
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
4*9=36
4*10=40
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program27:-
/* Write a program to print the fibbonoci series.
#include<stdio.h>
#include<conio.h>
void main()
int a=0,b=1,i,n,c;
clrscr();
scanf("\n%d" ,&n);
for (i=0;i<n;i++)
c=a+b;
printf("\t%d" ,c);
a=b;
b=c;
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
1 2 3 5 8 13 21 34 55
89 144 233
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program28:-
/*W.A.P to print the prime no from 1-100.
#include<stdio.h>
#include<conio.h>
void main()
int i,number=1;
clrscr();
while(number<=100)
i=2;
while(i<=number)
if(number%i==0)
break;
i++;
if(i==number)
printf("\n%d is Prime",number);
number++;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
getch();
2 is Prime
3 is Prime
5 is Prime
7 is Prime
11 is Prime
13 is Prime
17 is Prime
19 is Prime
23 is Prime
29 is Prime
31 is Prime
37 is Prime
41 is Prime
43 is Prime
47 is Prime
53 is Prime
59 is Prime
61 is Prime
67 is Prime
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
71 is Prime
73 is Prime
79 is Prime
83 is Prime
89 is Prime
97 is Prime
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program30:-
/*W.A.P to combinations of 1, 2, 3 using for loop
#include<stdio.h>
#include<conio.h>
void main()
int i, j, k;
clrscr();
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
111
112
113
121
122
123
131
132
133
211
212
213
221
222
223
231
232
233
311
312
313
321
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
322
323
331
332
333
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program31:-
/*W.A.P tofind the value of one number raised to the power of another.
#include<stdio.h>
#include<conio.h>
void main()
scanf("%d", &index);
result=1;
temp=1;
while(temp<=index)
result = result*num1;
temp++;
getch(); }
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program32:-
/*W.A.P to print all the ASCII values and their equivalent
characters using a while loop. The ASCII values vary from 0 to 255.
#include<stdio.h>
#include<conio.h>
void main()
int num;
num = 1;
while(num<=255)
num++;
printf("\n\nEND\n");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program33:-
/*W.A.P to add first sevan terms of the following series using for loop
1/1!+2/2!+3/3!+4/4!+5/5!+6/6!+7/7!.
#include<conio.h>
#include<stdio.h>
void main()
int i,n=7;
float s=0;
clrscr();
scanf("%d",&n);
for(i=1;i<=n;i++)
s+=(i/fact(i));
printf("\n\tSum= %f",s);
getch();
float fact(int x)
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
{
if(x<=7)
return(1);
else
return(x*fact(x-1));
Sum= 28.000000
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program34:-
/*W.A.P to check whether the string is palindrome or not.
#include<stdio.h>
#include<string.h>
#define size 26
void main()
char strsrc[size];
char strtmp[size];
clrscr();
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
else
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program35:-
/*W.A.P to check the no is divisible by 3and 7 or not.
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
scanf("%d",&num);
if((num%3==0)&&(num%7==0))
else
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Enter the no 21
Enter the no 25
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program36:-
/*W.A.driven program of factorial values, prime or not,odd or even,exit.*/
#include<stdio.h>
#include<conio.h>
void main()
int choice;
clrscr();
while (1)
printf("\n1. Factorial");
printf("\n2. Prime");
printf("\n4. Exit");
switch (choice)
case 1:
break;
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
case 2:
case 3:
break;
case 4:
exit();
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program40:-
/* W.A.P to to multiply two matrices.
#include<stdio.h>
#include<conio.h>
void main()
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j,x;
clrscr();
scanf("%d",&m,&n);
scanf("%d",&p,&q);
if(n==p)
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<p;i++)
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
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(x=0;x<p;x++)
c[i][j]=c[i][j]+(a[i][x]*b[x][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)
printf(" %d ",c[i][j]);
printf(" ");
printf("\n");
getch(); }
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program41:-
/* W.A.P to find transpose of a matrix.
#include<stdio.h>
#include<conio.h>
void main()
int a[20],b[20],i,j,m,n;
clrscr();
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[j][i]=a[i][j]);
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
printf("\nTransepose is \n ");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
printf("%d",b[i][j]);
printf(" ");
printf("\n");
getch();
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
Program42:-
/* WAP to calculate product of two matrices.
#include<stdio.h>
#include<conio.h>
void main()
int a[10][10],b[10][10],c[10][10],m,n,p,q,i,j,k;
clrscr();
scanf("%d%d",&m,&n);
scanf("%d%d",&p,&q);
if(n==p)
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d%d",&a[i][j]);
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
printf("\nEnter B's element=\n ");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d%d",&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];
for(i=0;i<m;i++)
for(j=0;j<q;j++)
printf("%d",c[i][j]);
printf(" ");
Page 1
PRACTICAL ASSIGNMENT – PROGRAMING IN ‘C’
}
printf("\n");
getch();
Page 1