0% found this document useful (0 votes)
201 views25 pages

C Programming Practicals Guide

BSC it f.y. PC PRACTICAL

Uploaded by

flagpro077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views25 pages

C Programming Practicals Guide

BSC it f.y. PC PRACTICAL

Uploaded by

flagpro077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

F.

Y Bsc IT Programming in C
Practical No.1
Write a C program to print “Hello World”

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("\n Hello world \n");
getch();
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.2
Write a C program to swap number with using 3
variable.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n Enter first number\n");
scanf("%d",&a);
printf("\n Enter second number \n");
scanf("%d",&b);
printf("\n Before swapping \n");
printf("\n A = %d ,B = %d \n",a,b);
c=a;
a=b;
b=c;
printf("\n After swapping \n");
printf("\n A = %d ,B = %d \n",a,b);
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.3
Write a C program to make an artithematic
calculator.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n Enter first number\n");
scanf("%d",&a);
printf("\n Enter Second number \n");
scanf("%d",&b);
c=a+b;
printf("\n Addition \n=%d \n",c);
c=a-b;
printf("\n Substraction \n=%d \n",c);
c=a*b;
printf("\n Multiplication \n=%d \n",c);
c=a/b;
printf("\n Division \n=%d \n",c);
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.4
Write a C program to calculate simple interest.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
float si,p,t,r;
clrscr();
printf("\n Enter principle amount\n");
scanf("%f",&p);
printf("\n Enter rate of interest \n");
scanf("%f",&r);
printf("\n Enter Time \n");
scanf("%f",&t);
si=((p*r*t)/100);
printf("\n Simple interest is %f \n",si);
getch();
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.5
Write a C program to calculate greatest of two
numbers.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b;
clrscr();
printf("\n Enter first number \n");
scanf("%d",&a);
printf("\n Enter second number \n");
scanf("%d",&b);
if (a>b)
{
printf("Greatest number is %d",a);
}
else
{
printf("greatest number is %d",b);
}
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.6
Write a C program to find factorial of given number.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,f=1;
clrscr();
printf("\n Enter a number \n");
scanf("%d",&n);
for ( i = 1; i <=n ; i++)
{
f=f*i;
}
printf("\n Factorial of given number
%d",f);
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.7A
Write a C program to print the following nested for
loop pattern given below:
*
**
***
****
*****

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.7B
Write a C program to print the following nested for
loop pattern given below:
1
12
123
1234
12345

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.7C
Write a C program to print the following nested for
loop pattern given below:
1
22
333
4444
55555

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.7D
Write a C program to print the following nested for
loop pattern given below:
1
23
456
78910

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,num=1;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<i;j++)
{
printf("%d",num);
num++;
}
printf("\n");
}
getch();
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.8
Write a C program to print array elements.

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void main()
{
int i,arr[5];
clrscr();
printf("\n Enter Array Element \n");
for ( i = 1; i <=5 ; i++)
{
scanf("%d",&arr[i]);
}
printf("\n Array elements are below");
for ( i = 1; i <= 5; i++)
{
printf("%3d",arr[i]);
}
getch();
}
OUTPUT:
F.Y Bsc IT Programming in C
Practical No.9
Write a C program to implement pointer
(call by value call by reference)

SOURCE CODE
#include <stdio.h>
#include <conio.h>
void swap(int*,int*);
void main()
{
int a=2,b=3;
clrscr();
printf("\n Before swapping \n");
printf("\n A = %d ,B = %d \n",a,b);
swap(&a,&b);
printf("\n After swapping \n");\
printf("\n A = %d ,B = %d \n",a,b);
getch();
}
void swap(int*a,int*b)
{
int c;
c=*a;
*a=*b;
*b=c;
}

OUTPUT:
F.Y Bsc IT Programming in C
Practical No.10
Write a C program to implement structure.
SOURCE CODE
#include <stdio.h>
#include <conio.h>
struct emp
{
int id;
char name[30];
float sal;
};
void main()
{
struct emp e1;
clrsrc();
printf("\n Enter Employee Details \n");
printf("\n--------------------------\n");
printf("\n Enter Employee Name: ");
gets(e1.name);
printf("\n Enter Employee ID: ");
scanf("%d", &e1.id);
printf("\n Enter Employee Salary: ");
scanf("%f", &e1.sal);
printf("\n Employee Details are below
\n");
printf("\n--------------------------\n");
printf("\n ID = %d \n", e1.id);
printf("\n NAME =");
puts(e1.name);
printf("\n SALARY = %.2f \n", e1.sal);
getch();}

OUTPUT:

You might also like