Вы находитесь на странице: 1из 77

PRACTICAL ASSIGNMENT – PROGRAMING

IN ‘C’
Program 01.01:-
/* Write a program to interchange value of two variables
without

using third variable.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int a,b;

clrscr();

printf("\nThe value of a = ",a );

scanf("%d",&a );

printf("\nThe value of b = ",b );

scanf("%d",&b );

a=a+b;

printf("\nThe value of a = %d ",a );

b=a-b;

printf("\nThe value of b = %d ",b );

a=a-b;

printf("\nThe value of a = %d " ,a );

printf("\na= %d\nb= %d ",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

Program 01.02:-

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
/* W.A.P to interchange two no with using third variable.

Karan Jain B.C.A.1st year 1205.*/

#include<stdio.h>

#include<conio.h>

void main()

int a,b,c;

clrscr();

printf("Enter the first no ");

scanf("%d",&a);

printf("\nEnter thw second no ");

scanf("%d",&b);

c=a;

a=b;

b=c;

printf("\nThe value of a is %d\nThe value of b is %d


",a,b);

getch();

Enter the first no 10

Enter thw second no 20

The value of a is 20

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
The value of b is 10

Program 2:-

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
/* Write a program to convert temperature in degree
fahrenheit to degree

celsius using formula c=(5/9)*(f-32) .

karan jain B.C.A 1 1205 */

#include<stdio.h>

#include<conio.h>

main()

float c,f;

clrscr();

printf("\n Enter the fahrenheit ");

scanf("%f",&f );

c=(5.0/9.0)*(f-32.0);

printf("\n Temperature in celsius ");

printf("\n%f",c);

getch();

Enter the fahrenheit 213

Temperature in celsius

100.555557

Program3:-

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
/*W.A.P to change in kilometers into
meter,inchies,centimeters,feet.

karan jain B.C.A.1 1205 */

# include <iostream>

# include <cmath>

# include <string>

using namespace std;

double feet;

double inches;

double meters;

double centimeters;

double final;

double conversion();//prototype

double output (); //prototype

int main () //Input Function

cout << "Please enter a length in feet " << endl;

cin >> feet;

cout << "Please enter a length in inches" << endl;

cin >> inches;

output ();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
double conversion ()

meters = 0.3048 * feet;

centimeters = 2.54 * inches;

return 0;

Program4:-
/*W.A.p to find the simple interest.

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int p,t,r,si;

clrscr();

printf("enter the principal= ");

scanf("%d",&p);

printf("enter the rate of interest= ");

scanf("%d",&r);

printf("enter the time in years= ");

scanf("%d",&t);

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

printf("the simple interest is %d",si);

getch();

enter the principal= 300

enter the rate of interest= 6

enter the time in years= 3

the simple interest is 54

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>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
#include<conio.h>

void main()

int l,b,area, perimeter;

printf("Enter the length");

scanf("%d",&l);

printf("Enter the breadth ");

scanf("%d",&b);

area=l*b;

printf("\n Area of the Rectangle=%d",area);

perimeter=2*(l+b);

printf("\n Perimetre of the Rectangle=%d",perimeter);

getch();

Enter the length25

Enter the breadth 12

Area of the Rectangle=300

Perimetre of the Rectangle=74

Program05.02:-
/*W.A.P to find the area and perimeter of circle.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
#include<conio.h>

void main()

float radius,perimeter,area;

printf("Enter the radius= ");

scanf("%f",&radius);

perimeter=2*3.14*radius;

printf("\nPerimeter of circle is = %f",perimeter);

area=3.14*radius*radius;

printf("\nArea of circle is = %f ",area);

getch();

Enter the radius= 12

Perimeter of circle is = 75.360001

Area of circle is = 452.160004

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
rent is 25% of basic salary .

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int net_sal,gro_sal,dear_all,ho_rent;

clrscr();

printf("\n Enter the net salary");

scanf("%d" ,&net_sal);

dear_all=0.14*net_sal;

printf("\n the dearness alloeance is %d" ,dear_all);

ho_rent=0.25*net_sal;

printf("\n the house rnnt is %d" ,ho_rent);

gro_sal=net_sal+dear_all+ho_rent;

printf("\n gross salary paid %d " ,gro_sal);

getch();

Enter the net salary2500

the dearness alloeance is 350

the house rnnt is 625

gross salary paid 3475

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program07:-
/* Write a program to find the sum,div,pro,sub,mod of two
no.

Karan Jain B.C.A 1st year 1205 */

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
#include<stdio.h>

#include<conio.h>

void main()

int a,b,c,d,e,f,g;

clrscr();

printf("\n Enter the first no ");

scanf("%d" ,&a);

printf("\n Enter the second no ");

scanf("%d" ,&b);

c=a+b;

printf("\n The sum = %d",c);

d=a-b;

printf("\n The sub = %d",d);

e=a*b;

printf("\n The pro = %d",e);

f=a/b;

printf("\n The div = %d",f);

g=a%b;

printf("\n The mod = %d",g);

getch();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
Enter the first no 65

Enter the second no 23

The sum = 88

The sub = 42

The pro = 1495

The div = 2

The mod = 19

Program08:-
/* W.A.P to check the no is odd or even.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

int n ;

clrscr();

printf("enter a number :");

scanf("%d",&n);

if(n%2==0)

printf("no is even\n");

else

printf("no. is odd\n");

getch();

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.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
{

int i,a[20],n,countp=0,countn=0,countz=0;

clrscr();

printf("Enter the no ");

scanf("%d",&n);

printf("\nEnter the element ");

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)

countn++;

else

countz++;

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

printf("\nThere are %d (+ve) no",countp);

printf("\nThere are %d (-ve) no",countn);

printf("\nThere are %d 0 no",countz);

getch();

Enter the no 3

Enter the element 1

-2

There are 1 (+ve) no

There are 1 (-ve) no

There are 1 0 no

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.

Karan Jain B.C.A.1 1205.*/

#include<stdio.h>

#include<conio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

int cur_yr=2010,dt_of_yr,ser_time;

printf("The date of year is ");

scanf("%d",&dt_of_yr);

ser_time=cur_yr-dt_of_yr;

printf("\nthe service time is %d",ser_time);

if(ser_time>3)

printf("\n3000/-as bonus");

else

printf("\nno bonous");

getch();

The date of year is 2003

the service time is 7

3000/-as bonus

The date of year is 2009

the service time is 1

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
no bonous

Program11:-
/*W.A.P to determine whether the input year is leap or not
use logical

operator &&||.

Karan Jain B.C.A 1st year 1205.*/

#include<stdio.h>

#include<conio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

int year;

printf ("Enter the year ");

scanf ("%d", &year);

if (year%4==0)

printf ("\nThe year is a Leap Year.");

else

printf("\nThe year is not a Leap Year.");

getch();

Enter the year 2005

The year is not a Leap Year.

Enter the year 2004

The year is a Leap Year.

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program12:-
/*W.A.P to find the seller made profit or incurred loss. Also
determine how

much profit he made or loss he incurred.

Karan Jain B.C.A.1st year 1205.*/

#include<stdio.h>

#include<conio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

int cost_price,sell_price,profit_loss;

clrscr();

printf("Enter the cost price ");

scanf("%d",&cost_price);

printf("Enter the selling price ");

scanf("%d",&sell_price);

profit_loss=sell_price-cost_price;

printf("The Profit or loss is %d",profit_loss);

if(profit_loss>0)

printf("\nProfit earned %d",profit_loss);

else

if(profit_loss<0)

printf("\nLoss earned %d",profit_loss);

else

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("\nThere is no profit loss earned %d
",profit_loss);

getch();

Enter the cost price 1235

Enter the selling price 125

The Profit or loss is -1110

Loss earned -1110

Enter the cost price 1235

Enter the selling price 6500

The Profit or loss is 5265

Profit earned 5265

Enter the cost price 1235

Enter the selling price 1235

The Profit or loss is 0

There is no profit loss earned 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.

if quantity and price per item are input through keyboard.

Write a program to cal culate expenses.

Karan Jain B.C.A.1st year 1205.*/

#include<stdio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
#include<conio.h>

void main( )

float bs, gs, da, hra ;

printf ( "Enter basic salary " ) ;

scanf ( "%f", &bs ) ;

if ( bs < 1500 )

hra = bs * 10 / 100 ;

da = bs * 90 / 100 ;

else

hra = 500 ;

da = bs * 98 / 100 ;

gs = bs + hra + da ;

printf ( "gross salary = Rs. %f", gs ) ;

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
basic salary. If the employee's salary is input through the
keyboard

write a program to find his gross salary.

Karan Jain B.C.A 1st year 1205.*/

#include<stdio.h>

#include<conio.h>

void main( )

float bs, gs, da, hra ;

printf ( "Enter basic salary " ) ;

scanf ( "%f", &bs ) ;

if ( bs < 1500 )

hra = bs * 10 / 100 ;

da = bs * 90 / 100 ;

else

hra = 500 ;

da = bs * 98 / 100 ;

gs = bs + hra + da ;

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf ( "gross salary = Rs. %f", gs ) ;

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
c) % between 40 to 49 third

d) % less than 40 fail

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int m1,m2,m3,m4,m5,per;

clrscr();

printf("Enter the marks in first subject ");

scanf("%d",&m1);

printf("\nEnter the marks in second subject ");

scanf("%d",&m2);

printf("\nEnter the marks in third subject ");

scanf("%d",&m3);

printf("\nEnter the marks in fourth subject ");

scanf("%d",&m4);

printf("\nEnter the marks in fifth subject ");

scanf("%d",&m5);

per=(m1+m2+m3+m4+m5)/5;

printf("\nThe precent in marks=%d",per);

if(per>=60)

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("\nfirst division");

else

if(per>=50<=60)

printf("\nsecond division");

else

if(per>=40<=50)

printf("\nthird division");

else

printf("\nfail");

getch();

Enter the marks in first subject 45

Enter the marks in second subject 21

Enter the marks in third subject 65

Enter the marks in fourth subject 99

Enter the marks in fifth subject 99

The precent in marks=65

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

and female is unmerried above 25 years to be insured or


not.

Karan Jain B.C.A.1st year 1205.*/

#include<stdio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
#include<conio.h>

main()

char sex,ms;

int age;

printf ("Enter age, sex, marital status:");

scanf ("%d %c %c", &age, &sex, &ms);

if (ms=='M')

printf ("The driver is insured");

else

if (sex=='M')

if (age>30)

printf ("Driver is insured");

else

printf ("Driver is not insured");

else

if (age>25)

printf ("Driver is insured");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
else

printf ("Driver is not insured");

getch();

Enter age, sex, marital status:23

Driver is not insured

Enter age, sex, marital status:35

Driver is insured

Program17:-
/*W.A.P to determine the character rntered is capital
letter ,lower letter

,digit or special symbol.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

char charac;

printf ("Enter the character ");

scanf("%c", &charac);

if ((charac>=65) && (charac<=95))

printf("The entered character is a Capital


Letter");

else if ((charac>=97) && (charac<=122))

printf("The entered character is a Small Letter.");

else if ((charac>=48) && (charac<=57))

printf("The entered character is a Number");

else if ((charac>=0) && (charac<=47) ||(charac>=58)


&& (charac<=64) ||(charac>=91) && (charac<=96) ||
(charac>=123) && (charac<=127))

printf("The entered character is a special symbol.


");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

getch();

Enter the character karan

The entered character is a Small Letter.

Enter the character KARAN

The entered character is a Capital Letter

Program18:-
/* W.A,P to cnvert decimal to binary number system.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

#include<math.h>

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
void main()

long int a[20],i,n,count=0,b[20],c[20],sum=0;

clrscr();

printf("Enter the number in binary form= ");

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);

for (i=0;i<=count-1;i++)

c[i]=a[i] * b[i];

sum=sum +c[i];

printf("Decimal form =%ld",sum);

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
getch();

Enter the number in binary form= 326

Decimal form =22

Program19:-
/*W.A.P to sum up series 1+1/2+1/3+1/4+--------------
+pow(-1)n*1/n.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
{

int n,i,count;

float sum;

clrscr();

printf("Enter the no ");

scanf("%d",&n);

i=1;

count=1;

sum=0.0;

while(count<=n)

sum+=(float)pow(-1,count-1)/i;

i++;

count++;

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.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int a,b,c,d,e;

clrscr();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("Enter the Number ");

scanf("%d",&a);

while(a!=0)

b=a%10;

c=a/10;

printf("%d",b);

a=c;

getch();

Enter the Number 123 .The reverse no is 321

Program21:-
/*Write a program to find the factorial value of number

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int number, factorial, temp;

clrscr();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("Enter the number ");

scanf ("%d", &number);

temp=1;

factorial=1;

while (temp<=number)

factorial=factorial*temp;

temp++;

printf("The factorial is=%d", factorial);

getch();

Enter the number 6

The factorial is=720

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program22:-
/*W.A.P to check a no is armstrong or not.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

int n,sum=0,rem=0,cube=0,n1,i;

clrscr();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("Enter a number= ");

scanf("%d",&n);

n1=n;

while(n!=0)

rem=n%10;

cube=pow(rem,3);

sum=sum+cube;

n=n/10;

if(sum==n1)

printf("\n\tangstrom");

else

printf("\n\tnot armstromg");

getch();

Enter a number= 2 not armstromg

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program24:-
/*W.A.P program to find the sum of entered digit.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int n,num,x,sum=0;

clrscr();

printf("Enter a number=");

scanf("%d",&n);

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
while(n>0)

x=n%10;

sum=sum+x;

n=n/10;

printf("Sum of digits of a number=%d",sum);

getch();

Enter a number=659 Sum of digits of a number=20

Program25:-
/*W.A.P to print prime numbers.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int i,j,n;

clrscr();

printf(" Enter the number= ");

scanf("%d",&n);

printf("\n");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
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();

Enter the number= 123

2 3 5 7 11 13 17 19 23

29 31 37 41 43 47 53 59 61 67

71 73 79 83 89 97 101 103 107


109

113

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program26:-
/* Write a program to calculate the n tables.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int i,n,j,r;

clrscr();

printf("Enter the no ");

scanf("%d",&n);

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("\n The table of %d is " ,i);

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

r=i*j;

printf(" \n%d*%d=%d",i,j,r);

getch();

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
2*1=2

2*2=4

2*3=6

2*4=8

2*5=10

2*6=12

2*7=14

2*8=16

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
4*1=4

4*2=8

4*3=12

4*4=16

4*5=20

4*6=24

4*7=28

4*8=32

4*9=36

4*10=40

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program27:-
/* Write a program to print the fibbonoci series.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int a=0,b=1,i,n,c;

clrscr();

printf(" Enter the no= ");

scanf("\n%d" ,&n);

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

c=a+b;

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("\t%d" ,c);

a=b;

b=c;

getch();

Enter the no= 12

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.

Karan Jain B.C.A 1st year 1205 */

#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)

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
break;

i++;

if(i==number)

printf("\n%d is Prime",number);

number++;

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
43 is Prime

47 is Prime

53 is Prime

59 is Prime

61 is Prime

67 is Prime

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

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int i, j, k;

clrscr();

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

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

for (k=1; k<=3; k++)

printf("\n%d %d %d", i, j, k);

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

getch();

111

112

113

121

122

123

131

132

133

211

212

213

221

222

223

231

232

233

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
311

312

313

321

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.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int num1, index, result, temp;

printf("Enter the number:");

scanf ("%d", &num1);

printf("Enter the index:");

scanf("%d", &index);

result=1;

temp=1;

while(temp<=index)

result = result*num1;

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
temp++;

printf("%d raised to %d is: %d ", num1, index, result);

getch(); }

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.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int num;

printf("Printing ASCII values Table...\n\n");

num = 1;

while(num<=255)

printf("\nValue:%d = ASCII Character:%c", num,


num);

num++;

printf("\n\nEND\n");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
getch();

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!.

Karan Jain B.C.A 1st year 1205 */

#include<conio.h>

#include<stdio.h>

float fact (int n);

void main()

int i,n=7;

float s=0;

clrscr();

scanf("%d",&n);

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

s+=(i/fact(i));

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
printf("\n\tSum= %f",s);

getch();

float fact(int x)

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.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<string.h>

#define size 26

void main()

char strsrc[size];

char strtmp[size];

clrscr();

printf("\n Enter String:= "); gets(strsrc);

strcpy(strtmp,strsrc);

strrev(strtmp);

if(strcmp(strsrc,strtmp)==0)

printf("\n Entered string \"%s\"


ispalindrome",strsrc);

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

else

printf("\n Entered string \"%s\" is not


palindrome",strsrc);

getch();

Enter String:= 121

Entered string "121" ispalindrome

Enter String:= 123

Entered string "123" is not palindrome

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program35:-
/*W.A.P to check the no is divisible by 3and 7 or not.

Karan Jain B.C.A 1st year 1205 */

#include<stdio.h>

#include<conio.h>

void main()

int num;

clrscr();

printf("Enter the no ");

scanf("%d",&num);

if((num%3==0)&&(num%7==0))

printf("\nNumber is divisible by 3 and 7 ");

else

printf("\nNumber is not divisible by 3 and 7 ");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

getch();

Enter the no 21

Number is divisible by 3 and 7

Enter the no 25

Number is not divisible by 3 and 7]

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("\n3. Odd/ Even");

printf("\n4. Exit");

printf("\n Your Choice? : ");

scanf ("%d", &choice);

switch (choice)

case 1:

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
//logic for factorial of a number

break;

case 2:

//logic for deciding a prime number

case 3:

//logic for odd/even

break;

case 4:

exit();

getch();

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’

Program40:-
/* W.A.P to to multiply two matrices.

Karan Jain B.C.A.1st year 1205.*/

#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();

printf("Order of matrix A : \n");

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

printf("Order of matrix B : \n");

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

if(n==p)

printf("Enter A's element: \n ");

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

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

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

printf("Enter B's elements: \n ");

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.

Karan JAin B.C.A.1st year 1205.*/

#include<stdio.h>

#include<conio.h>

void main()

int a[20],b[20],i,j,m,n;

clrscr();

printf("\nOrder of matrix : ");

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

printf("\nEnter the elements : ");

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();

Program42:-

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
/* WAP to calculate product of two matrices.

Karan Jain B.C.A.1st year 1205 */

#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();

printf("The Order of matrix A=\n ");

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

printf("\nThe Order of natrix B=\n ");

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

if(n==p)

printf("\nEnter A's element=\n ");

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

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

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

printf("\nEnter B's element=\n ");

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

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
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(" ");

printf("\n");

Page 1
PRACTICAL ASSIGNMENT – PROGRAMING
IN ‘C’
}

getch();

Page 1