You are on page 1of 48

M.K.

M GROUP OF COLLEGES

PRACTICAL FILE OF

C
PROGRAMMING

SUBMITTED TO : SUBMITTED BY :

MISS. KAVITA DESHWAL NAME :

(Asst. prof. in cs dept.) ROLL-

CLASS : MSC(CS),1ST SEM.

1
INDEX
S.N PROGRAM NAME Page.NO REMARKS
o
1 W.A.P to Find even or odd
number.
2 W.A.P to find print of 1
12
123
3 W.A.P to find largest of
three numbers.
4 W.A.P to find square root
of number.
5 W.A.P to calculate factorial
of a number .
6 W.A.P to print table of any
number.
7 W.A.P to calculate total
marks and average of a
student.
8 W.A.P to calculate simple
interest.
9 W.A.P to perform
swapping of two number .
10 W.A.P to find the year is
entered is leap or not.
11 W.A.P to perform an
arithmetic operation.
12 W.A.P function using call
by reference.
13 W.A.P to print table of any

2
number.
14 W.A.P to print addition of
two numbers.
15 W.A.P function using call
by value.
16 W.A.P to find the power of
number.
17 W.A.P to calculate
percentage of a student.
18 W.A.P to find function
value.
19 W.A.P by show use of
formal and actual
parameter.
20 W.A.P by using structure of
student.
21 W.A.P by using switch
statement.
22 W.A.P to illustrate the use
of pointer.
23 W.A.P to show the
concatination of two
string.
24 W.A.P to show the length
of the string.
25 W.A.P to find out the
numbers is prime or not.

3
WAP TO FIND OUT THE NUMBER IS
EVEN OR ODD.

#include<stdio.h>

#include<conio.h>

void main()

int n;

clrscr();

printf("enter a number:");

scanf("%d",&n);

if(n%2==0)

printf("number is even");

else

printf("number is odd");

getch();

4
OUTPUT:

5
WAP TO FIND PRINT OF PATTERN.
#include<stdio.h>

#include<conio.h>

void main()

int i=1; int j;

clrscr();

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

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

printf("%d",j);

printf("\n");

getch();

6
OUTPUT:

7
WAP TO FIND LARGEST OF THREE
NUMBERS.
#include<stdio.h>

#i.nclude<conio.h>

void main()

float a,b,c,big;

clrscr();

printf("enter three numbers\n");

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

if(a>b)

if(a>c) big=a;

else big=c;

else

if(b>c) big=b;

else big=c;

printf("largest number is:%f",big);

getch();

8
OUTPUT:

9
WAP TO FIND SQUARE ROOT OF
NUMBER.
#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

int n;

clrscr();

float result;

start:printf("enter a number :");

scanf("%d",&n);

if(n<0)

goto start;

else

result=sqrt(n);

printf("square root is:%f",result);

getch();

10
OUTPUT:

11
WAP TO CACULATE FACTORIAL OF A
NUMBER.
#include<stdio.h>

#include<conio.h>

void main()

int num=0; int fac=1;

clrscr();

printf("\n Enter a number");

scanf("%d",&num);

while(num>=1)

fac=fac*num;

num--;

printf("\n The factorial of the number is%d",fac);

getch();

12
OUTPUT:

13
WAP TO PRINT TABLE OF ANY NUMBER.
#include<stdio.h>

#include<conio.h>

void main()

int number,i;

printf("Enter the number whose multiples are required:");

scanf("%d",&number);

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

printf("%3d",i*number);

getch();

OUTPUT:

14
WAP TO CALCULATE TOTAL MARKS
AND AVERAGE OF A STUDENT.
#include<stdio.>

#include<conio.h>

void main()

float sum=0,number,mean;

int n,i;

printf("Enter total number to be average:");

scanf("%d",&n);

printf("\n Enter %d number\n",n);

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

scanf("%f",&number);

sum+=number;

mean=sum/n;

printf("\n Average is :%f",mean);

getch();

15
OUTPUT:

16
WAP TO CALCULATE SIMPLE INTEREST.
#include<stdio.h>

#include<conio.h>

void main()

float p,r,t,si;

clrscr();

printf("Enter the value of principle,rate and time\n");

scanf("%d%d%d",&p,&r,&t);

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

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

getch();

17
OUTPUT:

18
WAP TO PERFORM SWAPPING OF TWO
NUMBERS.
#include<stdio.h>

#include<conio.h>

void main()

int a,b,c;

clrscr();

printf("Enter the value of a and b\n");

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

c=a;

a=b;

b=c;

printf("After swapping value of a and b is\n%d\n%d\n",a,b);

getch();

19
OUTPUT:

20
WAP TO FIND THE YEAR IS ENTERED
IS LEAP OR NOT.
#include<stdio.h>

#include<conio.h>

void main()

int year;

clrscr();

printf("enter the year\n");

scanf("%d",&year);

if(year%4==0)

printf("year is leap");

else

printf("year is not leap");

getch();

21
OUTPUT:

22
WAP TO PERFORM AN ARITHMETIC
OPERATIONS.
#include<stdio.h>

#include<conio.h>

void main()

int a,b,sum,diff,mul,div, mod;

clrscr();

printf("Enter the value of a and b\n");

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

sum=a+b;

printf("The sum of a and b is %d\n",sum);

diff=a-b;

printf("The difference of a and b is %d\n",diff);

mul=a*b;

printf("Multiplication of a and b is %d\n",mul);

div=a/b;

printf("Division of a and b is %d\n",div);

mod=a%b;

printf("Modulu of a and b is %d",mod);

getch();

23
OUTPUT:

24
WAP FUNTION USING CALL BY
REFERENCE.
#include<stdio.h>

#include<conio.h>

void call_ref(int*);

void main()

clrscr();

int a;

a=10;

printf("\n value of a in main before funtion call:%d",a);

call_ref(&a);

printf("\n value of a in main after funtion call:%d",a);

getch();

void call_ref(int* n)

*n=*(n)+1;

printf("\n value of formal parameter in function:%d",*n);

25
OUTPUT:

26
WAP TO PRINT ADDITION OF TWO
NUMBERS.
#include<stdio.h>

#include<conio.h>

void main()

clrscr();

int a[10][10],b[10][10],s[10][10],i,j,m,n;

printf("enter the order of matrix\n");

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

printf("enter the element of first matrix\n");

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

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

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

printf("enter the element of second matrix\n");

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

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

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

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

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

s[i][j]=a[i][j]+b[i][j];

printf("resultant matrix is\n");

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

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

printf("%4d",s[i][j]);

printf("\n");

getch();

OUTPUT:

28
WAP TO PRINT TABLE OF ANY
NUMBERS.
#include<stdio.h>

#include<conio.h>

void main()

int i;

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

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

getch();

OUTPUT:

29
WAP FUCTION USING CALL BY VALUE.
#include<stdio.h>

#include<conio.h>

void call_value(int);

void main()

clrscr();

int a;

a=10;

printf("\n value of a in main before funtion call:%d",a);

call_value(a);

printf("\n value of a in main after funtion call:%d",a);

getch();

void call_value(int n)

n=n+1;

printf("\n value of formal parameter in function:%d",n);

30
OUTPUT:

31
WAP TO FIND THE POWER OF NUMBER.
#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

clrscr();

int x,y,t;

scanf("%d%d",&x,&y);

t=pow(x,y);

printf("%d",t);

getch();

OUTPUT:

32
WAP TO CALCULATE PERCENTAGE OF
STUDENT.
#include<stdio.h>

#include<conio.h>

void main()

int per;

clrscr();

printf("Enter percentage");

scanf("%d",&per);

if(per>80 && per<=100)

printf("First division with honour");

else if(per<80 && per>=60)

printf("1st division");

else if(per<60 && per>=50)

printf("2nd division");

else if(per<50 && per>=40)

printf("pass");

33
else

printf("fail");

getch();

OUTPUT:

34
WAP TO FIND FUNCTION VALUE.
#include<stdio.h>

#include<conio.h>

void main()

int sum(int,int);

int a,b,ans;

printf("\n Enter two numbers");

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

ans =sum(a,b);

printf("\n The result after addition:%d",ans);

getch();

int sum(int f1,int f2)

int result;

result=f1+f2;

return(result);

35
OUTPUT:

36
WAP TO SHOW THE USE OF FORMAL
AND ACTUAL PARAMETER.
#include<stdio.h>

#include<conio.h>

void main()

clrscr();

void sum();

printf("\n now redirecting control of sum function");

sum();

getch();

void sum()

int a,b;

printf("\n enter two numbers");

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

printf("\n the sum of entered numbers is %d",a+b);

37
OUTPUT:

38
WAP BY USING STRUCTURE OF
STUDENT.
#include<stdio.h>

#include<conio.h>

struct student

int rollno;

clrscr();

char name[10];

char course[5];

float fees;

};

void main()

struct student s1;

printf("\n enter the rollno of the student");

scanf("%d",&s1.rollno);

printf("\n enter the name of student");

scanf("%s",&s1.name);

printf("\n enter the course of student");

scanf("%s",&s1.course);

printf("\n enter the fees of the student");

scanf("%f",&s1.fees);

printf("\n the rollno of the student is:%d",s1.rollno);

printf("\n the name of the student is:%s",s1.name);

printf("\n the course of the student is:%s",s1.course);

39
printf("\n the fees of student is:%f",s1.fees);

getch();

Output:

Enter the Rollno of the student:8

Enter the Name of the student:indu

Enter the course of the student:m.sc(c.s)1 s t year

Enter the fees of the student:15000

The Rollno of the student:8

The name of the student:indu

The course of the student:m.sc(c.s)1 s t year

The fees of of the student:15000.000000

40
WAP BY USING SWITCH STATEMENT.
#include<stdio.h>

#include<conio.h>

void main()

int month,days,year;

clrscr();

printf("Enter the month(1-12)and year\n");

scanf("%d%d",&month,&year);

switch(month)

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days=31;

break;

case 4:

case 6:

case 9:

case 11:

days=30;

break;

41
case 2:

if(year%4==0)

days=29;

else

days=28;

break;

printf("Number of days are:%d",days);

getch();

OUTPUT:

42
WAP TO ILLUSTRSTE THE USE OF
POINTER.
#include<stdio.h>

#include<conio.h>

void main()

int var1=100;

int var2=200;

clrscr();

int*ptr;

ptr=&var1;

printf("\n\n\t the pointer points to var1");

printf ("\n\n\t the value of ptr is %u",ptr);

printf("\n\n\t the data of ptr is %d",*ptr);

ptr=&var2;

printf("\n\n\t the pointer now points to var2");

printf("\n\n\t the value of ptr is %u",ptr);

printf("\n\n\t the data of ptr is %d",*ptr);

getch();

43
OUTPUT:

44
WAP TO SHOW THE CONCATENATION
OF TWO STRING.
#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char s1[20],s2[20];

clrscr();

printf("Enter the first string:");

gets(s1);

printf("Enter the 2nd string:");

gets(s2);

strcat(s1,s2);

printf("first string after appending second string is:%s",s1);

getch();

OUTPUT:

45
WAP TO SHOW THE LENGTH OF THE
STRING .
#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

clrscr();

char str[21];

int n;

printf("\nEnter astring:");

gets(str);

n=strlen(str);

printf("The lenth of given string is:%d",n);

getch();

OUTPUT:

46
WAP TO FIND OUT THE NUMBER IS
PRIME OR NOT.
#include<stdio.h>

#include<conio.h>

void main()

int n,i;

clrscr();

printf("Enter anumber:");

scanf("%d",&n);

i=2;

while(i<=n/2)

if(n%i==0)

printf("not prime");

goto end;

i++;

printf("prime number");

end:7

getch();

47
OUTPUT:

48

You might also like