C Practical Lab File
C Practical Lab File
Lab File
C Programming (Lab)
3
write a program to calculate the average of two number.
4
write a program to calculate simple interest.
5
write a program to calculate area and perimeter of a
rectangle
6
write a program to implement Relational operator.
7
write a program to find sizeof int ,char ,float and double
9
write a program to check leap year.
10
write a program to check no is positive, negative or zero.
11
write a program to find largest of three number.
15
WAP to reverse a number.
16 WAP to implement Fibonacci series with
recursion.
20
Write a program to print sum of two matrix.
21
Write a Program to access Array of
int Pointers
22
WAP to sawp two number using pointers.
24
WAP for the implementation of Union.
Signature ……………..
PROGRAM 1
OBJECTIVE:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
OUTPUT:
Hello, World!
Algorithm:
1.Start
3.Stop
Flow Chart:
PROGRAM 2
OBJECTIVE:
CODING:
#include <stdio.h>
int main()
float divide;
divide = first / (float)second; //typecasting, you can also write: divide = (float)first/second
printf("Division = %.2f\n", divide); // "%.2lf" to print two decimal digits, by default (%lf) we get
six
return 0;
OUTPUT:
ALGORITHM:
do yourself.
FLOW CHART:
Do yourself.
PROGRAM 3
OBJECTIVE:
write a program to calculate the average of two number.
CODING:
#include <stdio.h>
int main(){
float num1,num2,avg;
printf("Enter the first number ");
scanf("%f",&num1);
scanf("%f",&num2);
avg=(num1+num2)/2;
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 4
OBJECTIVE:
write a program to calculate simple interest.
CODING:
#include<stdio.h>
int main()
float P , R , T , SI ;
P =34000; R =30; T = 5;
SI = (P*R*T)/100;
return (0);
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 5
OBJECTIVE:
write a program to calculate area and perimeter of a rectangle.
CODING:
#include<stdio.h>
int main() {
scanf("%d", &length);
scanf("%d", &breadth);
perimeter=2*(length+breadth);
return (0);
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 6
OBJECTIVE:
write a program to implement Relational operator.
CODING:
#include <stdio.h>
int main()
int m=40,n=20;
if (m == n)
{
printf("m and n are equal");
else
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 7
OBJECTIVE:
write a program to find sizeof int ,char ,float and double
CODING:
#include <stdio.h>
#include <limits.h>
int main()
{int a;
char b;
float c;
double d;
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 8
OBJECTIVE:
write a program to check the no is even or odd.
CODING:
#include<stdio.h>
void main()
int n;
if (n%2==0)
printf ("even number");
else
printf("odd number");
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 9
OBJECTIVE:
write a program to check leap year.
CODING:
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if (year % 400 == 0) {
printf("%d is a leap year.", year);
// but divisible by 4
else if (year % 4 == 0) {
else {
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 10
OBJECTIVE:
write a program to check no is positive, negative or zero.
CODING:
#include <stdio.h>
int main() {
double num;
scanf("%lf", &num);
else
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 11
OBJECTIVE:
write a program to find largest of three number.
CODING:
#include <stdio.h>
int main() {
else
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Do yourself.
PROGRAM 12
OBJECTIVE:
CODING:
#include<stdio.h>
#include<conio.h>
void main()
int fact, i, n;
fact = 1;
scanf("%d" , &n);
fact = fact*i;
getch();
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 13
OBJECTIVE:
CODING:
#include<stdio.h>
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
return 0;
if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 14
OBJECTIVE:
CODING:
#include <stdio.h>
int main()
int week;
switch(week)
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
return 0;
}
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 15
OBJECTIVE:
CODING:
#include <stdio.h>
int main() {
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
n =n/10;
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
Structure of array
PROGRAM 16
OBJECTIVE:
CODING:
#include<stdio.h>
int f(int);
int main()
{
int n, i = 0, c;
scanf("%d", &n);
printf("Fibonacci series terms are:\n");
for (c = 1; c <= n; c++)
{
printf("%d\n", f(i));
i++;
}
return 0;
}
int f(int n)
{
if (n == 0 || n == 1)
return n;
else
return (f(n-1) + f(n-2));
}
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 17
OBJECTIVE:
**
***
****
*****
CODING:
#include<stdio.h>
#define MAX 5
int main()
int i,j;
for(j=0;j<=i;j++) j=,3<=2
printf("*");
printf("\n");
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 18
OBJECTIVE:
123
12345
1234567
123456789
CODING:
#include<stdio.h>
int main()
int i,j,k,l=1;
printf(" ");
printf("%d",k);
l = l+2;
printf("\n");
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 19
OBJECTIVE:
CODING:
#include<stdio.h>
int main()
scanf("%d", &size);
scanf("%d", &a[i]);
}
}
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 20
OBJECTIVE:
CODING:
#include <stdio.h>
int main()
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
printf("\nSum Of Matrix:");
for (int i = 0; i < 2; ++i)
if (j == 1)
printf("\n");
return 0;
}
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 21
OBJECTIVE:
CODING:
#include
<stdio.h>
void main()
int *p = a;
printf("%d", *p);
p++;
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 22
OBJECTIVE:
CODING:
#include<stdio.h>
int main()
int a, b;
int temp;
scanf("%d", &a);
scanf("%d", &b);
return 0;}
Output:
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 23
OBJECTIVE:
CODING:
#include <stdio.h>
struct Student
char Student_Name[50];
int C_Marks;
int DataBase_Marks;
int CPlus_Marks;
int English_Marks;
};
int main()
int i;
};
printf(".....Student Details....");
for(i=0; i<4; i++)
return 0;
OUTPUT:
ALGORITHM:
FLOW CHART:
PROGRAM 24
OBJECTIVE:
WAP for the implementation of Union.
CODING:
#include <stdio.h>
#include <string.h>
union abc
{
int a;
char b;
}var;
int main()
{
var.a = 66;
printf("\n a = %d", var.a);
printf("\n b = %c", var.b);
OUTPUT:
a = 66
b=B
ALGORITHM:
FLOW CHART:
PROGRAM 25
OBJECTIVE:
CODING:
#include<stdio.h>
#include<string.h>
int main()
char ch[20]={'j','a','v','a','t','p','o','i','n','t','\0'};
char ch2[20];
strcpy(ch2,ch);
strcat(ch,ch2);
return 0;
OUTPUT:
FLOW CHART: