Lab 1
Lab 1
Lab Manual
Programming in C
Lab 1
Fundamental of Programming
Index
Lab Objectives
Background
Some Examples
Exercises
Lab Objectives:
Explain the component of a Program code,
To study about the pre processor library, data type, identifiers and operators,
Background:
The types of header files:
<stdio.h> Contains functions prototypes for the standard input output library function
and the information to use them
<stdlib.h> Contains function prototypes for conversions of numbers to text and text to
numbers, memory allocation, random number, and other utility functions
<time.h> Contains function prototypes and types for manipulating the time and date
2. Write a program that read an integer/ floating point/ long number and display
that number.
Program Code:
#include<stdio.h>
int main()
{
int i;
float f;
double d;
long l;
//for integer number
printf("Enter a integer: ");
scanf("%d",&i);
printf("\n your integer is %d ",i);
//for floating point
printf("\nEnter a floating point number: ");
scanf("%f",&f);
printf("\n your floating point number is %f ",f);
//for double
printf("\nEnter a double number: ");
scanf("%lf",&d);
printf("\n your double number is %lf ",d);
//for long
printf("\nEnter a long number: ");
scanf("%ld",&l);
printf("\n your long number is %ld ",l);
return 0;
}
3. Write a program that read two integers and display their sum/ subtract/
product.
Program Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter first integer:\n");
scanf("%d",&a);
printf("\nEnter second integer:\n");
scanf("%d",&b);
printf("\nSum is %d",a+b); //for summation
printf("\nSubtract is %d",a-b); //for subtraction
printf("\nproduct is %d",a*b); //for production
return 0;
}
4. Write a program that read any upper case character and display in lower.
Program Code:
#include<stdio.h>
int main()
{
char u;
//upper to lower
printf("\nEnter upper character: ");
scanf("%c",&u);
printf("\n your lower character is %c ",u+32);
return 0;
}
Exercise:
1. Write a program that read temperature in Celsius and display in Fahrenheit.
To convert temperature the equation is-
C/5 = (f-32)/9
Here, C is in Celsius and f is in Fahrenheit.
2. Write a program that read radius of a circle and display its area.
To calculate area of a circle the equation is-
Area= pi*r*r
Here, r is the radius of a circle and pi=3.1416.