Saturday 29 April 2023

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 1


SET A

1. Accept dimensions of a cylinder and print the surface area and volume (Hint: surface area =
2pr2 + 2prh, volume = pr2h)

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

void main()
{
 float r,h,sa,v;
 clrscr();

 printf("\nFinding Surface Area of cylinder and volume:");
 printf("\nEnter the radius of cylinder in cm:");
 scanf("%f",&r);
 printf("\nEnter the height of cylinder in cm:");
 scanf("%f",&h);

 sa=(2*3.14*r*r)+(2*3.14*r*h);
 printf("\nSurface area of cylinder:%f",sa);

 v=3.14*r*r*h;
 printf("\nvolum of Cylinder:%f",v);

 getch();
} 
/*
output:

Finding Surface Area of cylinder and volume:                                   
Enter the radius of cylinder in cm:3                                           
                                                                               
Enter the height of cylinder in cm:3                                           

Surface area of cylinder:113.040001
volum of Cylinder       :84.779999
*/ 



 
8. Accept a character from the user and display its ASCII value.

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

void main()
{
 char c;

 clrscr();

 printf("\nFinding the ASCII value of characher:");
 printf("\nEnter the character:");
 scanf("%c",&c);

 printf("\n ASCII value of %c is\t %d",c,c);

 getch();
}          

/*

Finding the ASCII value of characher:                                          
Enter the character:A                                                          
                                                                               
 ASCII value of A is     65                                                    
 */                                                                 
SET B




1. Accept the x and y coordinates of two points and compute the distance between the two
points.

 

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

float distance(int x1,int y1,int x2,int y2)
{
 float formula;
 formula=sqrt((x1-y1)*(x1-y1)+(x2-y2)-(x2-y2));
 return formula;
}

void main()
{
 int x1,y1,x2,y2;
 float result;
 clrscr();

 printf("\nFinding the distance between 2 co-ordinate:");
 printf("\nEnter the point A co-ordinat: ");
 printf("\nEnter the  x co-ordinate:");
 scanf("%d",&x1);
 printf("\nEnter the y  co-ordinate:");
 scanf("%d",&y1);
 printf("\nEnter the point B co-ordinate:");
 printf("\nEnter the x - co-ordinate:");
 scanf("%d",&x2);
 printf("\nEnter the y - co-ordinate:");
 scanf("%d",&y2);
 result=distance(x1,y1,x2,y2);
 printf("\nDistance between A and B point is:%f",result);


 getch();


/*

Finding the distance between 2 co-ordinate:                                    
Enter the point A co-ordinat:                                                  
Enter the  x co-ordinate:4                                                     
                                                                               
Enter the y  co-ordinate:5                                                     
                                                                               
Enter the point B co-ordinate:                                                 
Enter the x - co-ordinate:1                                                    
                                                                               
Enter the y - co-ordinate:3                                                    
                                                                               
Distance between A and B point is:1.000000                                     
 */




2. Accept two integers from the user and interchange them. Display the interchanged numbers   
                
#include<stdio.h>
#include<conio.h>

void main()
{
 int a,b,temp;

 clrscr();

 printf("\nInterching of 2 numbers");
 printf("\nEnter the first no A values:");
 scanf("%d",&a);
 printf("\nEnter the second no B values:");
 scanf("%d",&b);

 temp=a;
 a=b;
 b=temp;
 printf("\nvalue of A is:%d ",a);
 printf("\nValue of B is %d",b);

 getch();

}
/*

Interching of 2 numbers                                                       
Enter the first no A values:22                                                
                                                                              
Enter the second no B values:55                                               
                                                                              
value of A is:55                                                              
Value of B is 22                                                              
*/


3. A cashier has currency notes of denomination 1, 5 and 10. Accept the amount to be
withdrawn from the user and print the total number of currency notes of each denomination the
cashier will have to give. 

            
#include<stdio.h>
#include<conio.h>
void main()
{
 int amt,ans;
 clrscr();
 printf("\nEnter amount:");
 scanf("%d",&amt);
 ans=amt/10;
 printf("\n 10 rs notes :%d",ans);
 ans=amt%10;
 ans=ans/5;
 printf("\n 5 rs notes :%d ",ans);
 ans=amt%5;
 printf("\n1 rs notes : %d ",ans);
 getch();
}
 /*
Enter amount:239                                                              
                                                                              
 10 rs notes :23                                                              
 5 rs notes :1                                                                
1 rs notes : 4                                                                
                                                                              
  */

SET C
1. Consider a room having one door and two windows both of the same size. Accept
dimensions of the room, door and window. Print the area to be painted (interior walls) and area to
be whitewashed (roof).


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

void main()
{
 float pa,wa,rl,rh,rw,wl,wh,dl,dh;

 clrscr();

 printf("\nEnter the detail about room: ");
 printf("\nEnter Room lenght:");
 scanf("%f",&rl);
 printf("\nEnter Room Height:");
 scanf("%f",&rh);
 printf("\nEnter Room widht:");
 scanf("%f",&rw);
 printf("\nEnter door height:");
 scanf("%f",&dh);
 printf("\nEnter  door lenght:");
 scanf("%f",&dl);
 printf("\nEnter window lenght:");
 scanf("%f",&wl);
 printf("\nEnter  window height:");
 scanf("%f",&wh);

 pa=4*rl*rh-dl*dh-2*wl*wh;
 printf("\nPaint area:%f",pa);

 wa=rl*rw;
 printf("\nWhitewash area:%f",wa);

 getch();
}        

/*

Enter the detail about room:                                                   
Enter Room lenght:10                                                           
                                                                               
Enter Room Height:                                                             
15                                                                             
                                                                               
Enter Room widht:20                                                            
                                                                               
Enter door height:10                                                           
                                                                               
Enter  door lenght:5
                                                                               
Enter window lenght:7                                                          
                                                                               
Enter  window height:7                                                         
                                                                               
Paint area:452.000000                                                          
Whitewash area:200.000000                                                      

*/                   


2. The basic salary of an employee is decided at the time of employment, which may be
different for different employees. Apart from basic, employee gets 10% of basic as house rent,
30% of basic as dearness allowance. A professional tax of 5% of basic is deducted from salary.
Accept the employee id and basic salary for an employee and output the take home salary of the
employee. 


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

void main()
{
 int id;
 float bs,ts;
 clrscr();

 printf("\nEnter the id of employee:");
 scanf("%d",&id);
 printf("\nEnter the basic salary of employee:");
 scanf("%f",&bs);

 ts=bs*1.35;
 printf("\nTake home salary:%f",ts);

 getch();
}
/*
Enter the id of employee:1                                                     
                                                                               
Enter the basic salary of employee:7000                                        
                                                                               
Take home salary:9450.000000                                                   
     */                                                                          

No comments:

Post a Comment

Questions

  Exercise 1 Set A . Apply all the three program development steps for the following examples.  1. Accept dimensions of a cylinder and p...