Lab Program in C
Lab Program in C
**NAME :
**GROUP NO: 5.
void main() {
printf("Use of format specifiers :");
char ch = 'A';
char str[50] = "Here we use format specifier";
int a = 12;
float b = 23.54;
int c = 3444;
float d = 32.542;
printf("charcter : %c ", ch);
printf("\n String : %s ", str);
printf("\n integer : %d", a);
printf("\n float : %f", b);
printf("\n Octal : %o", a);
printf("\n Hexadecimal : %x", a);
printf("\n int upto 6 digit : %6d", c );
printf("\n float upto 6 digit : %6f", d);
printf("\n float upto 6 digit integer & decimal upto 2 : %6.2f", d);
printf("\n float upto2 decimal : %.2f", d);
getch();
}
Output:-
---------------------------------------------------------------------------------------------------------
02.WAP for character input & output (use getchar() & putchar()).
#include <stdio.h>
#include <conio.h>
void main()
{
char c;
printf ("\n Enter a character :-");
c = getchar(); // get a single character
printf(" You have entered : ");
putchar(c); // print a single character using putchar
getch();
}
Output:-
---------------------------------------------------------------------------------------------------------
03.WAP to read from keyboard & display on console (use printf() & scanf()).
#include <stdio.h>
void main() {
printf("Use of Printf & scanf : \n");
char ch;
char str[20];
int a;
float b;
double c;
printf("Enter a charcter : ");
scanf("%c",&ch);
printf("Enter a String : ");
scanf("%s",&str);
printf("Enter a integer : ");
scanf("%d",&a);
printf("Enter a float : ");
scanf("%f",&b);
printf("Enter a double : ");
scanf("%lf",&c);
printf("charcter : %c ", ch);
printf("\n String : %str ", str);
printf("\n integer : %d", a);
printf("\n float : %f", b);
printf("\n Octal : %o", a);
printf("\n double : %lf", c );
}
Output :-
---------------------------------------------------------------------------------------------------------
04. WAP to print different data types with qualifiers usinf sizeof().
#include <stdio.h>
int 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);
int size_of_short = sizeof(short);
int size_of_long = sizeof(long);
int size_of_long_long = sizeof(long long);
int size_of_signed = sizeof(signed);
int size_of_unsigned = sizeof(unsigned);
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\n",size_of_double);
printf("The size of short data type : %d\n",size_of_short);
printf("The size of long data type : %d\n",size_of_long);
printf("The size of long long data type : %d\n",size_of_long_long);
printf("The size of signed data type : %d\n",size_of_signed);
printf("The size of unsigned data type : %d\n",size_of_unsigned);
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
#include<stdio.h>
enum week{Mon =1, Tue, Wed, Thur, Fri, Sat, Sun};
int main()
{
enum week day;
day = Wed;
printf("Value of week is %d",day);
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
06. WAP to understand type conversion (implicit & explicit) concepts by performing
addition & subtraction using int,float & char data type.
#include<stdio.h>
#include<conio.h>
int main(){
int a;
float b;
char c;
printf("Enter the value of char : ");
scanf("%c", &c);
printf("Enter the value of integer : ");
scanf("%d", &a);
printf("Enter the value of float : ");
scanf("%f", &b);
c = (int)c;
printf("Addition in int : %d ", (int)(a+b+c));
printf("\n Subtraction in int : %d ", (int)(a-b-c));
printf("\n Addition in float : %f ", (a+b-c));
printf("\n Subtraction in float : %f ", (a-b-c));
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
07. WAP to understand the shortand or compound assignment operator concept using
all arithemetic and bitwise operators.
#include<stdio.h>
#include<conio.h>
int main(){
int a,b;
printf("Enter the value of a & b : ");
scanf("%d %d",&a,&b);
printf("AND operator : %d", a & b);
printf("\n OR operator : %d", a | b);
printf("\n XOR operator : %d", a ^ b);
printf("\n Right shift operator : %d", a>>2);
printf("\n Left shift operator : %d", a<<2);
printf("\n Complement operator : %d %d", ~a,~b);
printf("\n Addition : %d", a+=b);
printf("\n Subtraction : %d", a-=b);
printf("\n Multiplication : %d", a*=b);
printf("\n Division : %d", a/=b);
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main(){
int l,u,i,r;
float c;
printf("Enter lower & upper limit & range of temp in Fehrenheit: \n");
scanf("%d %d %d",&l,&u,&r);
printf("Temperature in Celsius : \n");
for(i=l;i<=u;i+=r){
c = 5*(i-32)/9;
printf("%f \n",c);
}
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
9. WAP to check whether a given no. is even or odd using if-else statement.
# include<stdio.h>
int main(){
int n;
printf("Enter a no. :");
scanf("%d",&n);
if(n%2 == 0)
printf("No. is even");
else
printf("No. is odd");
return 0;
}
Output :-
---------------------------------------------------------------------------------------------------------
10. WAP to find largest among three given no.s using an if-else statement.
#include<stdio.h>
int main(){
int a,b,c;
printf("Enter three no.s :\n");
scanf("%d %d %d",&a,&b,&c);
if(a>b && a>c)
printf("Greater no. is %d",a);
---------------------------------------------------------------------------------------------------------