Practical List for Week 2 (Class A and Class B)
Program 1:
// C program to show input and output
#include<stdio.h>
#include<conio.h>
void main()
{
// Declare the variables
int num;
char ch;
float f;
// --- Integer ---
// Input the integer
printf("Enter the integer: ");
scanf("%d", &num);
// Output the integer
printf("\nEntered integer is: %d", num);
// --- Float ---
//For input Clearing buffer
while((getchar()) != '\n');
// Input the float
printf("\n\nEnter the float: ");
scanf("%f", &f);
// Output the float
printf("\nEntered float is: %f", f);
// --- Character ---
// Input the Character
printf("\n\nEnter the Character: ");
scanf("%c", &ch);
// Output the Character
printf("\nEntered character is: %c", ch);
getch();
}
Program 2
// C program to print Integer data types.
#include<stdio.h>
#include<conio.h>
void main()
{
// Integer value with positive data.
int a = 9;
// integer value with negative data.
int b = -9;
// U or u is Used for Unsigned int in C.
int c = 89U;
// L or l is used for long int in C.
long int d = 99998L;
printf("Integer value with positive data: %d\n", a);
printf("Integer value with negative data: %d\n", b);
printf("Integer value with an unsigned int data: %u\n",
c);
printf("Integer value with an long int data: %ld", d);
getch();
}
Program 3:
// C Program to demonstrate use
// of Floating types
#include<stdio.h>
#include<conio.h>
void main()
{
float a = 9.0f;
float b = 2.5f;
// 2x10^-4
float c = 2E-4f;
printf("%f\n", a);
printf("%f\n", b);
printf("%f", c);
getch();
}
Program 4:
// C Program to demonstrate
// use of double data type
#include<stdio.h>
#include<conio.h>
void main()
{
double a = 123123123.00;
double b = 12.293123;
double c = 2312312312.123123;
printf("%lf\n", a);
printf("%lf\n", b);
printf("%lf", c);
getch();
}
Program 5:
// C Program to print size of
// different data type in C
#include<stdio.h>
#include<conio.h>
void main()
{
int size_of_int = sizeof(int);
int size_of_char = sizeof(char);
int size_of_float = sizeof(float);
int size_of_double = sizeof(double);
printf("The size of int data type : %d\n", size_of_int);
printf("The size of char data type : %d\n", size_of_char);
printf("The size of float data type : %d\n" size_of_float);
printf("The size of double data type : %d",size_of_double);
getch();
}
Program 6:
// C program to show input and output
#include <stdio.h>
#include<conio.h>
void main()
{
// Declare the variables
int num;
char ch;
float f;
// --- Integer ---
// Input the integer
printf("Enter the integer: ");
scanf("%d", &num);
// Output the integer
printf("\nEntered integer is: %d", num);
// --- Float ---
//For input Clearing buffer
while((getchar()) != '\n');
// Input the float
printf("\n\nEnter the float: ");
scanf("%f", &f);
// Output the float
printf("\nEntered float is: %f", f);
// --- Character ---
// Input the Character
printf("\n\nEnter the Character: ");
scanf("%c", &ch);
// Output the Character
printf("\nEntered character is: %c", ch);
getch();
}