Lab mannual -'C' programming

Lab mannual -'C' programming

EXP-1

Objective(s): simple Program to Display "Hello, World!"

Required apparatus:Computer,turbo C++ software.

programme:
 
 #include <stdio.h>

int main() {

   // printf() displays the string inside quotation

   printf("Hello, World!");

   return 0;

}

output:- Hello, World!

 

 EXP-2

Objective: Write simple input output programs using library functions printf, scanf, getch

 

Required apparatus:Computer,turbo C++ software.

programme:

 

#include <stdio.h>
#include <conio.h>
 
void main();
{
int a;
float b;
clrscr();
printf("Enter any two numbers: ");
scanf("%d %f",&a,&b);
printf("%d %f",a,b);
getch();
}

 

Output

Enter any two numbers:
10
3.5

 


EXP-3

 

Objective: Write simple programme on if statement.

Required apparatus:Computer,turbo C++ software.

programme:

 

 

 

Example

#include<stdio.h>
#include<conio.h>
 
void main()
{
int a=10;
if(a<=10)
{
printf("a is less than 10");
}
getch();
}

Output

a is less than 10

 

 

 

 

 

 

EXP-4

 

Objective: Write simple programme on if-else statement.

Required apparatus:Computer,turbo C++ software.

programme:

 

Example

#include<stdio.h>
#include<conio.h>
 
void main()
{
int time=10;
clrscr();
if(time>12)
{
printf("Good morning");
}
else
{
printf("Good after noon");
}
getch();
}

Output

Good morning

 

 

 

 

 

EXP-5

 

Objective: Write simple programme on switch statement.

Required apparatus:Computer,turbo C++ software.

programme:

 

Example of switch case

#include<stdio.h>

#include<conio.h>

 

void main()

{

int ch;

clrscr();

printf("Enter any number (1 to 7)");

scanf("%d",&ch);

switch(ch)

{

case  1:

printf("Today is Monday");

break;

case  2:

printf("Today is Tuesday");

break;

case  3:

printf("Today is Wednesday");

break;

case  4:

printf("Today is Thursday");

break;

case  5:

printf("Today is Friday");

break;

case  6:

printf("Today is Saturday");

break;

case  7:

printf("Today is Sunday");

break;

default:

printf("Only enter value 1 to 7");

}

getch();

}

Output

Enter any number (1 to 7): 5 Today is Friday

 

  

EXP-6


Objective: Write simple programme on for loop.

Required apparatus:Computer,turbo C++ software.

programme:

Example of for loop

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

Output

1
2
3
4

 

 

 

 

 

 

 

EXP-7

 

Objective: Write simple programme on while loop.

Required apparatus:Computer,turbo C++ software.

programme: Example of while loop

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

Output

1
2
3
4

 

 

 

 

 

 

 

 

Previous
Next Post »