ANSI C by E. Balagurusamy chapter ONE solution
1) State whether the following statements are true or false.
a) Every line in a C program should end with a semicolon (True)
b) The closing brace of the main( ) in a program is the logical end of the program (True)
c) Comments cause the computer to print the text enclosed between /* and */ when executed (F)
d) Every C program ends with an END word (False)
e) A printf statement can generate only one line of output (false)
f) The purpose of the header file such as stdio.h is to store the source code of a program (True)
g) A line in a program may have more than one statement (False)
h)Syntax errors will be detected by the compiler (True)
i) In C language lowercase letters are significant (True)
j) main( ) is where the program begins its execution (True)
PROGRAMMING EXERCISES
problem 1.1:
#include<stdio.h>
void main()
{
int a=5,b=8,c=18;
printf("%dx+%dy=%d",a,b,c);
}
#include<stdio.h>
void main()
{
printf("Name\t:\t\tRusul azom\nDoorNo,street\t:\txxx\nCity,Pin coke\t:\tDhaka-1230\n");
}
problem 1.2:
#include<stdio.h>
void main()
{
printf("Name\t:\t\tRusul azom\nDoorNo,street\t:\txxx\nCity,Pin coke\t:\tDhaka-1230\n");
}
problem 1.3:
#include<stdio.h>
void main()
{
int i,num=5;
for(i=1;i<=10;i++){
printf("%d*%d=%d\n",num,i,i*num);
}
}
problem 1.4 (A,B):
#include<stdio.h>
void main()
{
float x,a,b,c,d;
a=250;
b=85;
c=25;
d=(b-c);
x=a/d;
if(d!=0){
printf("x=%.3f",x);
}else{
printf("error! undefine",x);
}
}
problem 1.5 (A):
#include<stdio.h>void main()
{
float F,C;
printf("Enter temparature in celcious");
scanf("%f",&C);
F=((9*C)/5)+32;
printf("%f C in F is : %0.3f",C,F);
}
problem 1.5(B):
#include<stdio.h>void main()
{
float F,C;
printf("Enter temparature in farenhide");
scanf("%f",&F);
C=((5*F)/9)-32;
printf("%.3f F in C is : %0.3f",F,C);
}
problem 1.6 :
#include <stdio.h>#define PI 3.14
int main()
{
float a,r;
printf("enter redious of circle");
scanf("%f",&r);
a=PI*r*r;
printf("area of circle is %f",a);
return 0;
}
problem 1.7
#include<stdio.h>int sum(int num1, int num2) {
int sm;
sm = num1 + num2;
return (sm);
}
int sub(int num1, int num2) {
int sb;
sb = num1 - num2;
return (sb);
}
int main() {
int num1=20, num2=10, add,sbb;
add = sum(num1, num2);
sbb=sub(num1,num2);
printf("sum and subtraction of two number is :sum= %d \n sub= %d ",add,sbb);
return (0);
}
problem 1.8
#include<stdio.h>void main()
{
printf("|''''''''''''''''''''''''''''''''''''|\n");
printf("| Name\t:\t\tRusul azom |\n| DoorNo,street\t:\txxxxx |\n| City,Pin coke\t:\tDhaka-1230 |\n");
printf("|....................................|\n");
}
problem 1.9
#include<stdio.h>void main()
{
int i,j;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++){
printf("*\t");
}
printf("\n");
}
}
problem 1.10
void main()
{
printf("|''''''''''| |''''''''''|\n");
printf("| |>>-------------> | |\n");
printf("|__________| |__________|\n");
}
problem 1.11
#include<stdio.h>#include<math.h>
void main()
{
float a,b,c,A,S;
printf("enter value of a,b,c\n");
scanf("%f%f%f",&a,&b,&c);
S=(a+b+c)/2;
A=sqrt(S*(S-a)*(S-b)*(S-c));
printf("area of circle is %.3f",A);
}
problem 1.12
#include<stdio.h>void main()
{
printf("x=\t|''''|\t y=\t\t|''''|\n");
printf("\t------\t\t\t------\n");
printf("sum=\t|''''|\t Difference=\t|''''|\n");
printf("\t------\t\t\t------\n");
printf("product=|''''|\t Divition=\t|''''|\n");
printf("\t------\t\t\t------\n");
}
problem 1.13
#include<math.h>
void main()
{
int x1,y1,x2,y2;
double D,d;
printf("enter value of point one\n");
scanf("%d%d",&x1,&x2);
printf("enter value of point two\n");
scanf("%d%d",&y1,&y2);
d=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
D=sqrt(d);
printf("distecse of two point is %.3lf",D);
}
problem 1.14
#include<math.h>
void main()
{
int x1=0,x2=0,y1=4,y2=5;
double D,d,red,area,peri,PI=3.14159;
d=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
D=sqrt(d);
red=D/2;
peri=2*PI*red;
area=PI*red*red;
printf("area is %.3lf\nperimeter is %.3lf\n",area,peri);
}
/
problem 1.15
#include<math.h>
void main()
{
int x1=2,x2=2,y1=5,y2=6;
double D,d,red,area,PI=3.14159;
d=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
D=sqrt(d);
red=D/2;
area=PI*red*red;
printf("area is %.3lf\n",area);
}
জুলাইয়ে আমেরিকার রাস্তায় নামছে চালক বিহীন গাড়ি
লিখেছেন ,
Md. Rusul Azom Sumon
CEO & FOUNDER azomTech
(লেখাটি লেখক কতৃক সংরক্ষিত কপি করা কপি করে পরিমার্জন করে অন্যকোথোও প্রকাশ করা সম্পূর্ণ নিষিদ্ধ ,কিন্তু অবাণিজ্যিক উদ্যেশে(শিক্ষার জন্য ) লেখকের অনুমতি নিয়ে ব্যবহার করা যাবে )
No comments