Programming in c Lab Manuall
Programming in c Lab Manuall
LAB EXERCISE :1
1: Write a Program to calculate and display the volume of a CUBE having it height
(h=10cm), width (w=12cm) and depth (8cm).
Algorithm:
1. Start
6. StoP
Flowchart:
Program:
#include<stdio.h>
void main()
volume
getch();
Output :
#include <stdio.h>
/*structure declaration*/
struct employee{
char name[30];
int empId;
float salary;
};
int main()
return 0;
it.
#include<stdio.h>
struct student
char name[30];
int roll;
float marks;
} s[5];
int main( )
{
int i;
printf(“Information of students:”);
s[i].roll =i+1;
printf(“Enter name:”);
scanf(“%s”, s[i].name);
printf(“Enter marks:”);
scanf(“%f”, &s[i].marks);
for(i=0;i<10;++i)
printf(“Name:”);
puts(s[i].name);
return 0;
}
4. Write a program to be familiar with different data types, Operators and
Expressions in C.
#include<stdio.h>
#include<conio.h>
void main()
char name[20];
int rollno;
scanf(“%s”,&name[]);
scanf("%d", &rollno);
sum=sub1+sub2+sub3+sub4;
score = (sum/500)*100;
getch();
}
Output:
Roll Number: 25
50
75
85
62
Roll Number: 25
#include<stdio.h>
#include<conio.h>
void main()
int num;
scanf(“%d”,&num);
if(num%2==0)
getch();
Output:
6 is even
6.To understand the programming using Loop & nested loop Statements
(for,while, do-while).
#include<stdio.h>
#include<conio.h>
void main()
int i;
for(i=1; i<=10;i++)
getch();
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
while(i<=10)
i++;
getch();
#include<stdio.h>
#include<conio.h>
void main()
int i=1;
do
i++;
while(i<=10);
getch()
}
Output:
10
**
***
****
*****
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1; i<=5;i++)
for(j=1;j<=i;j++)
printf(“*”);
printf(“\n”);
getch();
#include<stdio.h>
int main()
int num;
long fact;
scanf(“%d”, &num);
if(num<0)
fact = factorial(num);
return 0;
//Function definition
if(num==0)
return 1;
else
return(num*factorial(num-1));
#include<stdio.h>
#include<conio.h>
int main()
int a,b,c;
int*ptra=&a,*ptrb=&b,*ptrc=&c;
printf("enter three values");
scanf("%d%d%d",ptra,ptrb,ptrc);
printf("biggest number=%d",*ptra);
else
printf("biggest number=%d",*ptrc);
getch();
return 0;
10.Write a program to create a file called emp.rec and store information about
#include <stdio.h>
void main()
FILE *fptr;
char name[20];
int age;
float salary;
if (fptr == NULL)
return;
scanf("%s", name);
scanf("%d", &age);
scanf("%f", &salary);
fclose(fptr);
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;
char filename[15];
char ch;
scanf("%s", filename);
if (fptr == NULL)
exit(0);
ch = fgetc(fptr);
ch = fgetc(fptr);
fclose(fptr);