ADD









ANSI C by E. Balagurusamy chapter THREE solution


3.1 State whether the following statements are true or false

a)    The expression !(x<=y) is same as the expression x>y (True)

b)   A unary expression consists of only one operand with no operators (False)

c)    All arithmetic operators have the same level of precedence (False)

d)    An expression statement is terminated with a period

 e)    The operators <=, >=and !=all enjoy the same level of priority (False)

f)    The modulus operator % can be used only with integers (True)

g)    In C, if a data item is zero, it is considered false (True)

h)    During the evaluation of mixed expressions, an implicit cast is generated automatically (True)

i)    An explicit cast can be used to change the expression (True)

j)    Associativity is used to decide which of several different expressions is evaluated first

k)    Parentheses can be used to change the order of evaluation expressions (True)

l)    During modulo division, the sign of the result is positive, if both the operands are of the same sign (False)


PROGRAMMING EXERCISES 

Problem 3.1: Given the values of the variables X,Y and Z write a program to rotate their values such that X has the value of Y,Y has the value of Z and Z has the value of X.

(নম্বর সোয়াপিং : তিনটি ভেরিএবল এর মাঝে ,x  এর ম্যান যাবে y তে ,y   এর ম্যান যাবে z  তে , z   এর ম্যান যাবে a  তে ,)


#include<stdio.h>
void main()
{
int x,y,z,t;

printf("enter   value of x,y,z\n");
scanf("%d %d %d",&x,&y,&z);
t=x;
x=y;
y=z;
z=t;
printf("%d %d %d",x,y,z);

}

Problem 3.2: 

write a program that reads a floating-point number and then displays right-most digit of the integral part of the number.

(একটি দশমিক সংখ্যা নিতে হবে। এবং এর পূর্ণ অংশটির শেষ সংখ্যাটি দেখতে হবে। যেমনঃ ১২৩.৪৫ হলে ৩ প্রিন্ট করতে হবে। )


#include<stdio.h>
void main()
{
 int a,e;
 float p;

 printf("Enter a float number\n");
 scanf("%f",&p);
 a=int(p);

 e=a%10;
 if(a>10)
 printf("%d\n",e);

}

Problem 3.3: Modify the above program to display tow  right-most digits of the integral part of the number.

(আগের প্রব্লেম এর মতোই একটি দশমিক সংখ্যা নিতে হবে কিন্তু  এর পূর্ণ অংশটির শেষ দুটি  সংখ্যাটি দেখতে হবে। যেমনঃ ১২৩.৪৫ হলে  ২৩ প্রিন্ট করতে হবে। )

#include<stdio.h>
void main()
{
 int a,e;

 printf("Enter the value of a\n");
 scanf("%d",&a);
 e=a%100;
 if(a>100)
 printf("last two digit %d\n",e);

 }

Problem 3.4: Write a program that will obtain the length and width of a rectangle from the user and compute its area and perimeter.

(আয়ত ক্ষেত্রের  ক্ষেত্রফল  নির্ণয় কর )


#include<stdio.h>
void main()
{
  int len,wid,area,perimeter;

  printf("Enter the value of length,width\n");
  scanf("%d %d",&len,&wid);
  area=(len*wid);
  perimeter=2*(len+wid);
  printf("area is=%d\nprerimeter is= %d",area,perimeter);

  }

Problem 3.5:Given an integer number, write a program that displays the number as follows:

(চার অংকের একটি সংখ্যা নিবে এবং তা নিচের মতো প্রিন্ট করবে )

First line: all digitsSecond line: all except first digitThird line: all except first two digits…………Last line: The last digitFor example the number 5678 will be displayed as:5 6 7 8 (সব সংখ্যা )6 7 8 (প্রথমটি বাদে বাকি গুলা )78 (প্রথম দুটি বাদে বাকি গুলা )

8 (শেষ সংখ্যাটি )




#include<stdio.h>
void main()
{
 int a,b,c,e,x;
 float p;

 printf("Enter the number\n");
 scanf("%f",&p);
 a=int(p);
 printf(" the digit are\n");
 e=a%10000;
 b=e%1000;
 c=b%100;
  x=c%10;
 if(a>10000)
 printf("%d\n%d\n%d\n%d\n",a,e,b,c,x);
 else if(a>1000)
 printf("%d\n%d\n%d\n",a,b,c,x);
 else if(a>100)
 printf("%d\n%d\n",a,c,x);
 else if(a>10)
 printf("%d\n%d\n",a,x);
 printf("%d\n",a%10);

 }

Problem 3.7:The straight-line method of computing the yearly depreciation of the value of an item is given by

Depreciation=
Write a program to determine the salvage value of an item when the purchase price , years of service, and the annual depreciation are given.


#include<stdio.h>
void main()
{
  int years;
  float s, d,p;
  printf("Enter the value of years,d,p\n");
  scanf("%d %f %f",&years,&d,&p);
  s=p-(years*d);
  printf("salvage value is :%0.3f\n",s);
   
  }

Problem 3.7Write the program that will read a real number from the keyboard and print the following output in one line:Smallest integer                  The given               Largest integernot less then                         number               not greater thanthe number                                                          the number

#include<stdio.h>
void main()
{

 float m;
 int n,p;
 printf("give me the value of m\n");
 scanf("%f",&m);


 n=(m/1)+1;
 p=m;
 printf("%d %0.2f %d",n,m,p);
 }

Problem 3.8The total distance traveled by a vehicle in t seconds is given by

                Distance= ut+(at2)/2Where is the initial velocity( meter per second),is the acceleration (meter per second2). Write a program to evaluate the distance traveled at intrevales of time, give the value of u and a. the program should provide the flexibility to the user to select his own time intervals and repeat the calculation for different value of u and a.

#include<stdio.h>
void main()
{
 int a,u,t;
 float dis;

 printf("Enter the value of a,u,t\n");
 scanf("%d %d %d",&a,&u,&t);
 dis=u*t+(a*t*t)/2;
 printf("distance is:%0.3f\n",dis);

 }


Problem 3.8: In inventory management ,the Economic Order Quantity for a single item is given by       EOQ=sqrt { ( 2*demand rate*setup rate ) / ( holding cost per item per unit time ) }
And the Time Between Orders
     TBO =sqrt { ( 2* setup cost ) / (demand rate * holding cost per item per unit time ) }

3.9 1st part

#include<stdio.h>
#include<math.h>
void main()
{
float EOQ,d,s,h,x;

printf("Enter the value of d,s,h\n");
scanf("%f %f %f",&d,&s,&h);
x=(2*d*s)/h;

EOQ=sqrt(x);
printf(" EOQ is :%0.3f",EOQ);

}

second part of 3.9

#include<stdio.h>
#include<math.h>
void main()
{
            float x,s,d,h,TOB;
           
            printf("Enter  value of s,d,h\n");
            scanf("%f%f%f",&s,&d,&h);
            x=(2*s)/(d*h);
    TOB=sqrt(x);

            printf("TOB is  %.3f",TOB);
       
  }


       





লিখেছেন ,
 Md. Rusul Azom Sumon
 CEO & FOUNDER azomTech

 (লেখাটি লেখক কতৃক সংরক্ষিত কপি করা কপি করে পরিমার্জন করে অন্যকোথোও প্রকাশ করা সম্পূর্ণ নিষিদ্ধ ,কিন্তু অবাণিজ্যিক উদ্যেশে(শিক্ষার জন্য ) লেখকের অনুমতি নিয়ে ব্যবহার করা যাবে )

No comments

Theme images by lishenjun. Powered by Blogger.