You are on page 1of 11

QUESTION 1-

Declare 8 variables including all basic data types and initialize all the variables with zero.
Find the size of each variable using sizeof() operator and print the result. All variables
name
should contain at least three characters.
PROGRAM IS-
#include <stdio.h>
int main() {
int num=0;
float flt=0.0;
double dble=0.0;
char cha='\0';
unsigned int unsgn=0;
short shrt=0;
long lng=0L;
signed char sgn='\0';
printf("Size of num = %lu bytes\n",sizeof(num));
printf("Size of flt = %lu bytes\n",sizeof(flt));
printf("Size of dbl = %lu bytes\n",sizeof(dble));
printf("Size of cha = %lu bytes\n",sizeof(cha));
printf("Size of unsgn = %lu bytes\n",sizeof(unsgn));
printf("Size of sho = %lu bytes\n",sizeof(shrt));
printf("Size of lng = %lu bytes\n",sizeof(lng));
printf("Size of sgn = %lu bytes\n",sizeof(sgn));
return 0;
}

OUTPUT OF PROGRAM-
QUESTION 2-
Declare some integer variables showing all the modifiers and qualifiers applicable for
integer. Set a random value for each variable and print each value using printf() function
and tab separator.
PROGRAM IS-
#include<stdio.h>
int main()
{
signed int a =25;
unsigned int b =40;
short int c =111;
long int d =10111;
long long int e =100111;
register int f =38;
static int g =1900;
printf("a =\t%d\n",a);
printf("b =\t%u\n",b);
printf("c =\t%hd\n",c);
printf("d =\t%ld\n",d);
printf("e =\t%lld\n",e);
printf("f =\t%d\n",f);
printf("g =\t%d\n",g);
return 0;
}
PROGRAM OUTPUT-

QUESTION 3-
Write a C program that accepts three float values from the user. Add the numbers and
print the result up to three digits after decimal point.
PROGRAM IS-
#include<stdio.h>
int main()
{
float num1,num2,num3,sum;
printf("Enter first flat value= ");
scanf("%f",&num1);
printf("Enter second float value= ");
scanf("%f",&num2);
printf("Enter third float value= ");
scanf("%f",&num3);
sum =num1+num2+num3;
printf("the sum of %.3f,%.3f and %.3f is %.3f",num1,num2,num3,sum);
return 0;
}
PROGRAM OUTPUR-

QUESTION 4-
Write a program which will take the input as a floating (real) number. This number
represents the centimeters. Print out the equivalent number of feet (floating, 1 decimal)
and inches (floating, 1 decimal), with feet and the inches given to an accuracy of one
decimal place.
Assume 2.54 centimeters per inch, and 12 inches per foot.
If the input value is 333.3, the output format should be:
333.3 centimeters is 10.9 feet
333.33 centimeters is 131.2 inches
PROGRAM IS-
#include<stdio.h>
int main()
{
float cm,inches,foot;
printf("Enter the value : ");//value in cm
scanf("%f",&cm);
inches =cm/2.54;
foot =inches/12.0;
printf("%.2f centimeters is %.1f feet\n",cm,foot);
printf("%.2f centimeters is %.1f inches\n",cm,inches);
return 0;
}
PROGRAM OUTPUT-

QUESTION 5-
Write a program to evaluate the net salary of an employee given the following
constraints:
Basic salary : BDT 35000
DA : 12% of Basic salary
HRA : BDT 12000
TA : BDT 6000
Others : BDT 4500
Tax cuts – a) PF :14% of Basic salary and b) IT: 15% of Basic salary
Net Salary = Basic Salary + DA + HRA + TA + Others – (PF + IT)

PROGRAM IS-
PROGRAM OUTPUT-
#include<stdio.h>
int main() {
float Basic_salary =35000;
float DA =0.12*Basic_salary;
float HRA =12000;
float TA =6000;
float Others =4500;
float PF =0.14*Basic_salary;
float IT =0.15*Basic_salary;
float Net_Salary =Basic_salary+DA+HRA+TA+Others-(PF+IT);
printf("Net Salary: %.2f BDT\n",Net_Salary);
return 0;
}
PROGRAM OUTPUT-

QUESTION 6-
Write a program that accepts two numbers a and b and checks whether or not a is
divisible by b.
PROGRAM IS-
#include<stdio.h>
int main()
{
int n,a;
printf("enter the first number : ");
scanf("%d",&n);
printf("enter the second number : ");
scanf("%d",&a);
if (n%a==0)
{
printf("%d is divisible by %d\n",n,a);
}
else
{
printf("%d is not divisible by %d\n",n,a);
}
return 0;
}
PROGRAM OUTPUT-

QUESTION 7-

Write a program that accept 2 numbers. Calculate the difference between the
two values.
If the difference is equal to any of the values entered, then display the
following message:
PROGRAM IS-
#include <stdlib.h>
int main()
{
int num1,num2,dif;
printf("enter first value : ");
scanf("%d",&num1);
printf("enter second value : ");
scanf("%d",&num2);
dif =(num1-num2);
if (dif == num1)
{
printf("difference is equal to the value of %d\n",num1);
}
else if (dif == num2)
{
printf("difference is equal to the value of %d\n",num2);
} else
{
printf("difference is not equal");
}
return 0;
}
OUTPUT PROGRAM-

QUESTION 8-
Declare two variables x and y. Take values of these variables from the user.
Number x should be printed only if it is less than 2000 or greater than 3000,
and number y should be printed only if it is between 100 and 500.
PROGRAM IS-
#include<stdio.h>
int main()
{
int n,a;
printf("enter the value of x : ");
scanf("%d", &n);
printf("enter the value of y : ");
scanf("%d",&a);
if (n<2000||n>3000)
{
printf("x=%d\n",n);
}
if (a>= 100&&a<=500)
{
printf("y=%d\n",a);
}
return 0;
}
PROGRAM OUTPUT-

QUESTION 9-
Develop a C program that will first accept your roll number. Then the program
will ask you to enter three integer values. The program will print the largest
of the numbers if you have even roll number and print smallest number for
an odd roll number.
#include<stdio.h>
int main()
{
int n,num1,num2,num3;
printf("Enter roll number : ");
scanf("%d",&n);
printf("Enter first integers : ");
scanf("%d",&num1);
printf("Enter second integers : ");
scanf("%d",&num2);
printf("Enter third integers : ");
scanf("%d",&num3);
if (n%2 == 0)
{
int largest = num1;
if (num2>largest)
{
largest=num2;
}
if (num3>largest)
{
largest=num3;
}
printf("the largest number is : %d\n",largest);
}
else {
int smallest=num1;
if (num2<smallest)
{
smallest=num2;
}
if (num3<smallest)
{
smallest=num3;
}
printf("the smallest number is : %d\n",smallest);
}
return 0;
}
PROGRAM OUTPUT-

You might also like