ADD









ANSI C by E. Balagurusamy chapter TOW solution



2.1: STATE WHETHER THE FOLLOWING STATEMENTS ARE  TRUE OR FALSE:
(a)    All variables must be given a type when they are declared. ( True )
(b)  ANSI C treats the variable name and Name to be same. ( False )
(c) Character constants are coded using double quotes. (False )
  
(d)   The keyword void is a data type in C. ( True )
(e)  Declarations can appear anywhere in a program. ( False )
(f)   Initialization is the process  of assigning a value to a variable at the time of declaration.   ( true )
  
(g)The scanf function can be used to read only one value at a time. ( False )
   

(h)   Any valid printable ANSII character can be used in an identifier. ( False )

(i)   The underscore can be used anywhere in an identifier. ( True )
  
(j)   Floating point data constants, by default, denote float type values. ( False )

(k)   Like variables, constants have a type. ( True )
(l)    All static variables are automatically initialized to zero. ( True )

2.2  Fill in the blanks with appropriate words:

(a)A variable can be made constant by declaring it with the qualifier ……………. At the time of initialization.
Answer: constant
(b) …………… is the largest value that an unsigned short int type variable can store.
Answer: 255
(c) A global variable is also known as …………….variable.
Answer: external
(d) The keyword ……………..can be used to create a data type identifier.
Answer: int

PROGRAMMING EXERCISES 

 Problem no 2.1: Write a program to determine and print the sum of the following harmonic series for a given value of n:

1+1/2+1/3+………………+1/n
The value of n should be given interactively through the terminal.

#include<stdio.h>
void main()
{
int n;
float i, sum, t;

printf("enter value of n:\n");
scanf("%d",&n);
sum=0;

for(i=1;i<=n;i++)
        {
        t=1/i;
        sum=sum+t;
}
printf("%0.3f",sum);

}


Problem no 2.2: Write a program to read the price of an item in decimal form (  like 15.95 ) and print the output in paisa ( like 1595 paisa) .

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

 printf("enter prince in float:\n");
scanf("%lf",&a);

b=100*a;
printf("%d",b);

}


Problem no 2.3: Write a program that’s prints the even numbers from 1 to 100.

#include<stdio.h>
void main()
{
int b,i;
        printf("even number 1 to 100\n");

for(i=1;i<=100;i++)
{
if(i%2==0)
printf("%d ",i);
        }



}

Problem no 2.4: Write a program that request two float type numbers from the users and then divides the first number by the second and display the result along with the numbers.

#include<stdio.h>

void main()
{
float  num1, num2, num3;

printf("Enter the value of number1 and number2\n");
scanf("%f %f",&num1,&num2);
num3=num1/num2;
printf("%.3f/.3%f=.3%f",num1,num2,num3);
}

Problem no 2.5: The price of one kg of rice is Rs. 16.75 and one kg of sugar is Rs. 15. Write a program to get these values from the user and display the prices as follows:
         ***LIST OF ITEMS***
            Item                 Price
            Rice                 Rs 16.75
            Sugar               Rs 15.00

#include<stdio.h>
void main ()
{
int r,s;
float rice,sugar;
rice=16.75;
sugar=15.00;

printf("Enter vlue of rice and sugar\n");
scanf("%d%d",&r,&s);

printf("***LIST OF ITEMS***\n");
printf("Item \ttotal_Price\n");
printf("Rice\tRs%.2f\n",rice*r);
printf("Sugar\tRs%.2f\n",sugar*s);

}

PROBLEM 2.6


#include<stdio.h>
void main()
{
int n,pos=0,neg=0;

input:
printf("Enter your number one by one to end your set press 0\n");
scanf("%d",&n);
if(n>0){
        pos++;
}
if (n<0){
        neg++;
}

if(n==0){
        goto output;
}else{
        goto input;
}

output:
    printf("there are %d posative and %d negative number in this seat\n",pos,neg);
}

 PROBLEM 2.7

#include<stdio.h>
void main()
{
short int x=123456,y=654321,z;

z=x+y;
    printf("x=%d\ny=%d\nsum=%d\n",x,y,z);
    printf("compiler printing worng value beacuse short ineteger data type range is only -128 to 127\n");
}

 PROBLEM 2.8

#include<stdio.h>

void main()

{

int sum;
float x,y;

        scanf("%f%f",&x,&y);
sum=x+y;
    printf("x=%f\ny=%f\nsum=%d\n",x,y,sum);
}


 PROBLEM 2.9

#include<stdio.h>

void main()
{
int n;
typedef int taka;

taka sumon=10,shamu=20,total;
total=sumon+shamu;

        printf("total tk: %d\n",total);

}

 PROBLEM 2.10

#include<stdio.h>

#define PI 3.14159
void main()
{
float A,R;

printf("Enter redious of your wheel\n");
scanf("%f",&R);

        A=2*PI*R;

        printf("peremiter of your while is: %f\n",A);
}







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



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

No comments

Theme images by lishenjun. Powered by Blogger.