Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

/*

A c program contains the following declarations and initial assignments: int i=8,j=5;
float x=0.005,y=-0.01; char c=‟c‟,d=‟d‟;
Determine the value of each of the following expressions. Use the values initially
assigned to the variables for each expression.
(a) (3*i-2*j))+(i%2*d-c)
(b) 2*((i/5)+(4*(j-3))%(i+j-2)
(c) (i-3*j)%(c+2*d)/(x-y)
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i=8,j=5;
float x=0.005,y=-0.01,p,q,r;
char c='c',d='d';
p=((3*i-2*j)+(i%2*d-c));
q=2*((i/5)+(4*(j-3))%(i+j-2));
r=(i-3*j)%(c+2*d)/(x-y);

printf("\nPrinting result of first expression -> ");


printf("%f",p);
printf("\nPrinting result of second expression -> ");
printf("%f",q);
printf("\nPrinting result of third expression -> ");
printf("%f",r);

return 0;
}
/*
A c program contains the following declarations and initial assignments: int i=8,j=5,k;
float x=0.005,y=-0.01,z; char a,b,c=‟c‟,d=‟d‟;
Determine the value of each of the following assignment expression expressions. Use
the values initially assigned to the variables for each expression.
a. k=(i+j)
b. z=(x+y)
c. k=(x+y)
d. z=i/j
e. i=i%j
*/

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=8,j=5,k;
float x=0.005,y=-0.01,z;

k=(i+j);
printf("\nk->%d",k);
z=(x+y);
printf("\nz->%f",z);
k=(x+y);
printf("\nk->%d",k);
z=i/j;
printf("\nz->%f",z);
i=i%j;
printf("\ni->%d",i);

return 0;
}
/*
Ram‟s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and
house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
*/

#include <stdlib.h>
#include <stdio.h>

int main()
{
float G_Salary, B_Salary, D_Allowance, House_rent_A;
printf("\nEnter basic salary -> ");
scanf("%f",&B_Salary);
D_Allowance=0.4*B_Salary;
House_rent_A=0.2*B_Salary;
G_Salary=B_Salary+D_Allowance+House_rent_A;
printf("\nYour Gross Salary is -> %f",G_Salary);

return 0;
}
/*Write a program in “SUM.C” which reads two integers and prints out the sum, the
difference and the product. Divide them too, printing your answer to two decimal
places. Also print the remainder after the two numbers are divided. Introduce a test to
ensure that when dividing the numbers, the second number is not zero.*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
int first, second,SUM,DIFFERENCE,PRODUCT,REMAINDER;
float DIVISION;
char condition='F';
printf("\n Enter the first integer -> ");
scanf("%d",&first);
while(condition=='F')
{
printf("\n Enter the second integer -> ");
scanf("%d",&second);
if(second!=0)
{
condition='T';
break;
}
printf("\n Wrong input enter again (NON ZERO) ");
}

SUM= first+second;
DIFFERENCE=first-second;
PRODUCT=first*second;
DIVISION=first/second;
REMAINDER=first%second;

printf("\n The result of SUM is -> %d",SUM);


printf("\n The result of DIFFERENCE is -> %d",DIFFERENCE);
printf("\n The result of PRODUCT is -> %d",PRODUCT);
printf("\n The result of DIVISION is -> %.2f",DIVISION);
printf("\n The REMAINDER of division is -> %d",REMAINDER);

return 0;
}
/*
Write a program in a file called “VOL.C” which finds the area using radius. In
addition to the radius, it prompts for a height with which it calculates the volume of a
cylinder. The formula is volume = area * height.
*/

#include <stdio.h>
#include <stdlib.h>
#define pi (22.0/7.0)

int main()
{
float Area, Radius, Height, Volume;

printf("\n Enter the radius of the circle -> ");


scanf("%f",&Radius);
printf("\n Enter the Height -> ");
scanf("%f",&Height);

Area = pi*Radius*Radius;
printf("\n Area is -> %.2f",Area);
Volume= Area*Height;
printf("\n Volume is -> %.2f",Volume);

return 0;
}

You might also like