0% found this document useful (0 votes)
23 views12 pages

Lab Program in C

This document contains details of a lab assignment for a programming using C course. It provides 10 programming tasks to understand various C programming concepts like data types, operators, conditional statements, loops etc. The tasks include programs to read different data types using format specifiers, character input/output, type conversion, data type sizes, enumerations, Fahrenheit to Celsius conversion, checking even/odd numbers, and finding the largest of three numbers.

Uploaded by

Tilak Datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views12 pages

Lab Program in C

This document contains details of a lab assignment for a programming using C course. It provides 10 programming tasks to understand various C programming concepts like data types, operators, conditional statements, loops etc. The tasks include programs to read different data types using format specifiers, character input/output, type conversion, data type sizes, enumerations, Fahrenheit to Celsius conversion, checking even/odd numbers, and finding the largest of three numbers.

Uploaded by

Tilak Datta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

LAB ASSIGNMENT -1

 **NAME :

 **ROLL NUMBER: 523110004.

 **DEPARTMENT: Masters Of Computer and Application.

 **SUBJECT: PROGRAMMING USING C.

 **GROUP NO: 5.

 **TASK: LAB ASSIGNMENT-1.

LAB PROGRAM IN C (111)

01.WAP to understand format specifiers for reading different types of variables.


#include <stdio.h>
#include <conio.h>

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 :-

---------------------------------------------------------------------------------------------------------

05.WAP to print the values of weekdays using enum data type.

#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 :-

---------------------------------------------------------------------------------------------------------

8. WAP to convert Fahrenheit to Celsius.

#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);

else if(b>a && b>c)


printf("Greater no. is %d",b);

else if(c>a && c>a)


printf("Greater no. is %d",c);
else
printf("Enter different values of a,b & c");
return 0;
}
Output :-

---------------------------------------------------------------------------------------------------------

You might also like