From 2757248632062f90d7cf88c1eaff131a3206ab7a Mon Sep 17 00:00:00 2001 From: lakshmanan Date: Sun, 11 Apr 2010 21:43:01 +0530 Subject: [PATCH] move to repo.or.cz --- ch1/examples/example1.c | 23 +++++++++++++++++++++++ ch1/examples/example2.c | 17 +++++++++++++++++ ch1/examples/example3.c | 15 +++++++++++++++ ch1/examples/example4.c | 12 ++++++++++++ ch1/exercises/ex1.c | 19 +++++++++++++++++++ ch1/exercises/ex10.c | 31 +++++++++++++++++++++++++++++++ ch1/exercises/ex11.c | 25 +++++++++++++++++++++++++ ch1/exercises/ex12.c | 16 ++++++++++++++++ ch1/exercises/ex13.c | 15 +++++++++++++++ ch1/exercises/ex13.c~ | 15 +++++++++++++++ ch1/exercises/ex2.c | 23 +++++++++++++++++++++++ ch1/exercises/ex3.c | 18 ++++++++++++++++++ ch1/exercises/ex4.c | 15 +++++++++++++++ ch1/exercises/ex5.c | 26 ++++++++++++++++++++++++++ ch1/exercises/ex6.c | 20 ++++++++++++++++++++ ch1/exercises/ex7.c | 36 ++++++++++++++++++++++++++++++++++++ ch1/exercises/ex8.c | 32 ++++++++++++++++++++++++++++++++ ch1/exercises/ex9.c | 24 ++++++++++++++++++++++++ ch2/examples/example1.c | 15 +++++++++++++++ ch2/examples/example2.c | 24 ++++++++++++++++++++++++ ch2/examples/example3.c | 22 ++++++++++++++++++++++ ch2/examples/example4.c | 24 ++++++++++++++++++++++++ ch2/examples/example5.c | 30 ++++++++++++++++++++++++++++++ ch2/examples/example6.c | 18 ++++++++++++++++++ ch2/examples/rough.c | 10 ++++++++++ ch2/exercises1/a.out | Bin 0 -> 6692 bytes ch2/exercises1/ex1.c | 28 ++++++++++++++++++++++++++++ ch2/exercises1/ex10.c | 30 ++++++++++++++++++++++++++++++ ch2/exercises1/ex12.c | 17 +++++++++++++++++ ch2/exercises1/ex3.c | 17 +++++++++++++++++ ch2/exercises1/ex4.c | 35 +++++++++++++++++++++++++++++++++++ ch2/exercises1/ex5.c | 41 +++++++++++++++++++++++++++++++++++++++++ ch2/exercises1/ex6.c | 21 +++++++++++++++++++++ ch2/exercises1/ex7.c | 20 ++++++++++++++++++++ ch2/exercises1/ex8.c | 15 +++++++++++++++ ch2/exercises1/ex9.c | 23 +++++++++++++++++++++++ ch2/exercises1/exa2.c | 16 ++++++++++++++++ ch2/exercises1/exe11.c | 35 +++++++++++++++++++++++++++++++++++ ch2/exercises2/a.out | Bin 0 -> 6787 bytes ch2/exercises2/ex1.c | 14 ++++++++++++++ ch2/exercises2/ex2.c | 22 ++++++++++++++++++++++ ch2/exercises2/ex3.c | 27 +++++++++++++++++++++++++++ ch2/exercises2/ex4.c | 22 ++++++++++++++++++++++ ch2/exercises2/ex5.c | 39 +++++++++++++++++++++++++++++++++++++++ ch2/exercises2/ex6.c | 30 ++++++++++++++++++++++++++++++ ch2/exercises2/ex7.c | 24 ++++++++++++++++++++++++ ch2/exercises2/ex8.c | 21 +++++++++++++++++++++ ch2/exercises3/a.out | Bin 0 -> 6611 bytes ch2/exercises3/exA1.c | 14 ++++++++++++++ ch2/exercises3/exA2.c | 15 +++++++++++++++ ch2/exercises3/exB.c | 12 ++++++++++++ ch2/exercises3/exC.c | 16 ++++++++++++++++ ch3/examples/a.out | Bin 0 -> 6420 bytes ch3/examples/exa1.c | 20 ++++++++++++++++++++ ch3/examples/exa10.c | 10 ++++++++++ ch3/examples/exa11.c | 11 +++++++++++ ch3/examples/exa12.c | 18 ++++++++++++++++++ ch3/examples/exa13.c | 19 +++++++++++++++++++ ch3/examples/exa14.c | 27 +++++++++++++++++++++++++++ ch3/examples/exa15.c | 16 ++++++++++++++++ ch3/examples/exa16.c | 19 +++++++++++++++++++ ch3/examples/exa2.c | 14 ++++++++++++++ ch3/examples/exa3.c | 10 ++++++++++ ch3/examples/exa4.c | 9 +++++++++ ch3/examples/exa5.c | 16 ++++++++++++++++ ch3/examples/exa6.c | 10 ++++++++++ ch3/examples/exa7.c | 13 +++++++++++++ ch3/examples/exa8.c | 12 ++++++++++++ ch3/examples/exa9.c | 12 ++++++++++++ ch3/exercises/a.out | Bin 0 -> 6769 bytes ch3/exercises/ex1.c | 30 ++++++++++++++++++++++++++++++ ch3/exercises/ex2.c | 24 ++++++++++++++++++++++++ ch3/exercises/ex3.c | 21 +++++++++++++++++++++ ch3/exercises/ex4.c | 15 +++++++++++++++ ch3/exercises/ex5.c | 35 +++++++++++++++++++++++++++++++++++ 75 files changed, 1440 insertions(+) create mode 100644 ch1/examples/example1.c create mode 100644 ch1/examples/example2.c create mode 100644 ch1/examples/example3.c create mode 100644 ch1/examples/example4.c create mode 100644 ch1/exercises/ex1.c create mode 100644 ch1/exercises/ex10.c create mode 100644 ch1/exercises/ex11.c create mode 100644 ch1/exercises/ex12.c create mode 100644 ch1/exercises/ex13.c create mode 100644 ch1/exercises/ex13.c~ create mode 100644 ch1/exercises/ex2.c create mode 100644 ch1/exercises/ex3.c create mode 100644 ch1/exercises/ex4.c create mode 100644 ch1/exercises/ex5.c create mode 100644 ch1/exercises/ex6.c create mode 100644 ch1/exercises/ex7.c create mode 100644 ch1/exercises/ex8.c create mode 100644 ch1/exercises/ex9.c create mode 100644 ch2/examples/example1.c create mode 100644 ch2/examples/example2.c create mode 100644 ch2/examples/example3.c create mode 100644 ch2/examples/example4.c create mode 100644 ch2/examples/example5.c create mode 100644 ch2/examples/example6.c create mode 100644 ch2/examples/rough.c create mode 100755 ch2/exercises1/a.out create mode 100755 ch2/exercises1/ex1.c create mode 100755 ch2/exercises1/ex10.c create mode 100644 ch2/exercises1/ex12.c create mode 100755 ch2/exercises1/ex3.c create mode 100755 ch2/exercises1/ex4.c create mode 100755 ch2/exercises1/ex5.c create mode 100755 ch2/exercises1/ex6.c create mode 100755 ch2/exercises1/ex7.c create mode 100755 ch2/exercises1/ex8.c create mode 100755 ch2/exercises1/ex9.c create mode 100755 ch2/exercises1/exa2.c create mode 100644 ch2/exercises1/exe11.c create mode 100755 ch2/exercises2/a.out create mode 100644 ch2/exercises2/ex1.c create mode 100644 ch2/exercises2/ex2.c create mode 100644 ch2/exercises2/ex3.c create mode 100644 ch2/exercises2/ex4.c create mode 100644 ch2/exercises2/ex5.c create mode 100644 ch2/exercises2/ex6.c create mode 100644 ch2/exercises2/ex7.c create mode 100644 ch2/exercises2/ex8.c create mode 100755 ch2/exercises3/a.out create mode 100644 ch2/exercises3/exA1.c create mode 100644 ch2/exercises3/exA2.c create mode 100644 ch2/exercises3/exB.c create mode 100644 ch2/exercises3/exC.c create mode 100755 ch3/examples/a.out create mode 100644 ch3/examples/exa1.c create mode 100644 ch3/examples/exa10.c create mode 100644 ch3/examples/exa11.c create mode 100644 ch3/examples/exa12.c create mode 100644 ch3/examples/exa13.c create mode 100644 ch3/examples/exa14.c create mode 100644 ch3/examples/exa15.c create mode 100644 ch3/examples/exa16.c create mode 100644 ch3/examples/exa2.c create mode 100644 ch3/examples/exa3.c create mode 100644 ch3/examples/exa4.c create mode 100644 ch3/examples/exa5.c create mode 100644 ch3/examples/exa6.c create mode 100644 ch3/examples/exa7.c create mode 100644 ch3/examples/exa8.c create mode 100644 ch3/examples/exa9.c create mode 100755 ch3/exercises/a.out create mode 100644 ch3/exercises/ex1.c create mode 100644 ch3/exercises/ex2.c create mode 100644 ch3/exercises/ex3.c create mode 100644 ch3/exercises/ex4.c create mode 100644 ch3/exercises/ex5.c diff --git a/ch1/examples/example1.c b/ch1/examples/example1.c new file mode 100644 index 0000000..c8e2fc8 --- /dev/null +++ b/ch1/examples/example1.c @@ -0,0 +1,23 @@ +/*calculation of simple interest*/ +/*Author:lakshmanan*/ + +#include + +void main() +{ + int p=1000,n=3; + float r=n+5.5,si; + + /*p=1000; + n=3; + r=8.5;*/ + + + printf("value of r=%f n=%d",r,n); + + /*formula to find simple interest*/ + si=p*n*r/100; + + printf("\n%f\n",si); +} + diff --git a/ch1/examples/example2.c b/ch1/examples/example2.c new file mode 100644 index 0000000..ac6be7f --- /dev/null +++ b/ch1/examples/example2.c @@ -0,0 +1,17 @@ +/*calculation of simple interest 2 */ +/*using scanf */ + +#include + +void main() +{ + int p,n; + float si,r; + + printf("Enter the value of p,n,r: "); + scanf("%d %d %f",&p,&n,&r); + + si = p*n*r/100; + + printf("\n%f\n",si); +} diff --git a/ch1/examples/example3.c b/ch1/examples/example3.c new file mode 100644 index 0000000..7767e8c --- /dev/null +++ b/ch1/examples/example3.c @@ -0,0 +1,15 @@ +/*just for fun*/ + +#include + +void main() +{ + int num; + + printf("Enter a number: "); + scanf("%d",&num); + + printf("Now I am going to tell you a secret..\n"); + printf("you just entered %d\n",num); + +} diff --git a/ch1/examples/example4.c b/ch1/examples/example4.c new file mode 100644 index 0000000..1043358 --- /dev/null +++ b/ch1/examples/example4.c @@ -0,0 +1,12 @@ +/* performing a power function */ + +#include +#include + +void main() +{ + int a; + a=5%3; + printf("a is %d\n",a); + +} diff --git a/ch1/exercises/ex1.c b/ch1/exercises/ex1.c new file mode 100644 index 0000000..075776a --- /dev/null +++ b/ch1/exercises/ex1.c @@ -0,0 +1,19 @@ +/*ramesh sum*/ + +#include + +int main() +{ + float sal,da,hra; + float gross; + printf("Enter the basic salary: "); + scanf("%f",&sal); + + da=0.40*sal; + hra=0.20*sal; + + gross = sal+hra+da; + + printf("The gross salary is %.2f\n",gross); + return 0; +} diff --git a/ch1/exercises/ex10.c b/ch1/exercises/ex10.c new file mode 100644 index 0000000..5864caf --- /dev/null +++ b/ch1/exercises/ex10.c @@ -0,0 +1,31 @@ +/*population problem*/ + +#include + +int main() +{ + long pop=80000,lit_pop,ilit_pop; + int lit_men,ilit_men,lit_women,ilit_women; + int men,women; + + men = pop * 0.52; + women = pop - men; + + lit_pop = 0.48 * pop; + ilit_pop = pop - lit_pop; + + lit_men = 0.35*pop; + lit_women = lit_pop-(0.35*pop); + + printf("Literate population: %d\n",lit_pop); + printf("Literate men:%d\n",lit_men); + printf("Literate women: %d\n",lit_women); + + ilit_men = men - lit_men; + ilit_women = ilit_pop - ilit_men; + + printf("Illeterate men : %d\n",ilit_men); + printf("Illeterate women: %d\n",ilit_women); + + return 0; +} diff --git a/ch1/exercises/ex11.c b/ch1/exercises/ex11.c new file mode 100644 index 0000000..febdab7 --- /dev/null +++ b/ch1/exercises/ex11.c @@ -0,0 +1,25 @@ +/*currency notes*/ + +#include + +int main() +{ + int amount; + int hun,fif,tens; + printf("Enter the amount to be withdrawn: "); + scanf("%d",&amount); + + /*assume the amount is 4320*/ + + hun = (amount / 100)-1; + fif = 2; + + amount = amount /10; + tens = amount%10; + + printf("100s: %d\n",hun); + printf("50s: %d\n",fif); + printf("10s: %d\n",tens); + + return 0; +} diff --git a/ch1/exercises/ex12.c b/ch1/exercises/ex12.c new file mode 100644 index 0000000..5a0965f --- /dev/null +++ b/ch1/exercises/ex12.c @@ -0,0 +1,16 @@ +/*profit and loss problem*/ + +#include + +int main() +{ + float sp,profit; + float cp; + + printf("Enter the SP and profit: "); + scanf("%f %f",&sp,&profit); + + cp = (sp - profit)/15; + printf("The cp of each item is %.2f\n",cp); + return 0; +} diff --git a/ch1/exercises/ex13.c b/ch1/exercises/ex13.c new file mode 100644 index 0000000..82bf0f5 --- /dev/null +++ b/ch1/exercises/ex13.c @@ -0,0 +1,15 @@ +/*add 1 to each digit*/ + +#include + +int main() +{ + long num; + long num2; + printf("enter num: "); + scanf("%ld",&num); + + num2 = num + 11111; + printf("Num2: %ld\n",num2); + return 0; +} diff --git a/ch1/exercises/ex13.c~ b/ch1/exercises/ex13.c~ new file mode 100644 index 0000000..82bf0f5 --- /dev/null +++ b/ch1/exercises/ex13.c~ @@ -0,0 +1,15 @@ +/*add 1 to each digit*/ + +#include + +int main() +{ + long num; + long num2; + printf("enter num: "); + scanf("%ld",&num); + + num2 = num + 11111; + printf("Num2: %ld\n",num2); + return 0; +} diff --git a/ch1/exercises/ex2.c b/ch1/exercises/ex2.c new file mode 100644 index 0000000..3fa9f6c --- /dev/null +++ b/ch1/exercises/ex2.c @@ -0,0 +1,23 @@ +/*distance problem*/ + +#include + +int main() +{ + float km; + float m,feet,inches,cm; + + printf("Enter the distance in Km: "); + scanf("%f",&km); + + m=km*1000; + feet = 3280.8399*km; + inches = km * 39370.0787; + cm = m *100; + + printf("m=%.2f\n",m); + printf("feet=%.2f\n",feet); + printf("inches=%.2f\n",inches); + printf("cm=%.2f\n",cm); + return 0; +} diff --git a/ch1/exercises/ex3.c b/ch1/exercises/ex3.c new file mode 100644 index 0000000..012d496 --- /dev/null +++ b/ch1/exercises/ex3.c @@ -0,0 +1,18 @@ +/*marks problem*/ + +#include + +int main() +{ + float s1,s2,s3,s4,s5; + float avg; + + printf("Enter the marks: "); + scanf("%f %f %f %f %f",&s1,&s2,&s3,&s4,&s5); + + avg = (s1+s2+s3+s4+s5)/5; + + printf("The average is %.2f\n",avg); + + return 0; +} diff --git a/ch1/exercises/ex4.c b/ch1/exercises/ex4.c new file mode 100644 index 0000000..1da5e60 --- /dev/null +++ b/ch1/exercises/ex4.c @@ -0,0 +1,15 @@ +/*fahrenheit to celcius*/ + +#include + +int main() +{ + float fh,cs; + printf("Enter the temp in fahrenheit: "); + scanf("%f",&fh); + + cs = (fh-32)*(5.0/9.0); + + printf("The Temp in celcius is %.2f C",cs); + return 0; +} diff --git a/ch1/exercises/ex5.c b/ch1/exercises/ex5.c new file mode 100644 index 0000000..8baaf82 --- /dev/null +++ b/ch1/exercises/ex5.c @@ -0,0 +1,26 @@ +/*area of circle and rectangle*/ + +#include + +int main() +{ + float len,bre,rad; + float area_rect,area_circle; + float perimeter,cir_circle; + printf("Enter the len and bre of rectangle: "); + scanf("%f %f",&len,&bre); + printf("Enter the radius of the circle: "); + scanf("%f",&rad); + + area_rect = len*bre; + area_circle = 3.14*rad*rad; + + perimeter = 2*(len+bre); + cir_circle = 2*3.14*rad; + + printf("Area of Rectangle=%.2f perimeter=%.2f\n",area_rect,perimeter); + printf("Area of circle=%.2f cir_cirle=%.2f\n",area_circle,cir_circle); + + return 0; + +} diff --git a/ch1/exercises/ex6.c b/ch1/exercises/ex6.c new file mode 100644 index 0000000..2bb4492 --- /dev/null +++ b/ch1/exercises/ex6.c @@ -0,0 +1,20 @@ +#include + +int main() +{ + int c,d,temp; + + printf("Enter C: "); + scanf("%d",&c); + printf("Enter D: "); + scanf("%d",&d); + + temp = c; + c = d; + d = temp; + + printf("Now C:%d D:%d\n",c,d); + + return 0; + +} diff --git a/ch1/exercises/ex7.c b/ch1/exercises/ex7.c new file mode 100644 index 0000000..5940dd7 --- /dev/null +++ b/ch1/exercises/ex7.c @@ -0,0 +1,36 @@ +/*calculate the sum of digits in a 5 digit number*/ + +#include + +int main() +{ + long num; + int sum; + + + printf("Enter the five digit number: "); + scanf("%ld",&num); + + sum = 0; + + sum = sum + (num%10); + num=num/10; + + sum=sum+(num%10); + num = num/10; + + sum=sum+(num%10); + num = num/10; + + sum = sum+(num%10); + num = num/10; + + sum = sum+(num%10); + num = num/10; + + printf("The sum is %d\n",sum); + + return 0; + + +} diff --git a/ch1/exercises/ex8.c b/ch1/exercises/ex8.c new file mode 100644 index 0000000..7350a05 --- /dev/null +++ b/ch1/exercises/ex8.c @@ -0,0 +1,32 @@ +/*reverse a 5-digit number*/ + +#include +#include + +int main() +{ + long num,num2; + + printf("Enter num: "); + scanf("%ld",&num); + + num2=0; + + num2= num2 + (pow(10,4)*(num%10)); + num= num/10; + + num2 = num2 + (pow(10,3)*(num%10)); + num = num/10; + + num2 = num2 + (pow(10,2)*(num%10)); + num = num/10; + + num2 = num2 + (pow(10,1)*(num%10)); + num = num/10; + + num2 = num2 + (pow(10,0)*(num%10)); + num = num/10; + + printf("Reverse is %ld\n",num2); + return 0; +} diff --git a/ch1/exercises/ex9.c b/ch1/exercises/ex9.c new file mode 100644 index 0000000..61d9316 --- /dev/null +++ b/ch1/exercises/ex9.c @@ -0,0 +1,24 @@ +/*sum of first and last digit of a four digit number*/ + +#include + +int main() +{ + int num; + int sum; + printf("Enter the four digit number:"); + scanf("%d",&num); + + sum = 0; + + sum = sum + (num%10); + num = num / 10; + num = num / 10; + num = num/10; + sum = sum+(num%10); + + printf("The sum is %d\n",sum); + + + return 0; +} diff --git a/ch2/examples/example1.c b/ch2/examples/example1.c new file mode 100644 index 0000000..0c240c7 --- /dev/null +++ b/ch2/examples/example1.c @@ -0,0 +1,15 @@ +#include + +int main() +{ + int i; + printf("Enter a number less than 10: "); + scanf("%d",&i); + + if(i<10) + printf("What an obedient servant you are !!\n"); + + return 0; +} + + diff --git a/ch2/examples/example2.c b/ch2/examples/example2.c new file mode 100644 index 0000000..7904599 --- /dev/null +++ b/ch2/examples/example2.c @@ -0,0 +1,24 @@ +#include + +/* calculation of total expenses*/ + + +int main(void) +{ + int qty; + float rate; + int dis; + float expense; + + printf("Enter quantity and rate per item: "); + scanf("%d %f",&qty,&rate); + + if(qty>1000) + dis = 10; + + expense = (rate*qty)-(0.10*rate*qty); + + printf("The total expense is %.2f\n",expense); + + return 0; +} diff --git a/ch2/examples/example3.c b/ch2/examples/example3.c new file mode 100644 index 0000000..a1182b2 --- /dev/null +++ b/ch2/examples/example3.c @@ -0,0 +1,22 @@ +#include + +int main() +{ + int hire_year,current_year; + float bonus; + + printf("Enter the hire year: "); + scanf("%d",&hire_year); + + printf("Enter the current year: "); + scanf("%d",¤t_year); + + if((current_year-hire_year)>3) + { + bonus=2500; + printf("Bonus is set to 2500/- \n"); + } +printf("bye\n"); + +return 0; +} diff --git a/ch2/examples/example4.c b/ch2/examples/example4.c new file mode 100644 index 0000000..ddea032 --- /dev/null +++ b/ch2/examples/example4.c @@ -0,0 +1,24 @@ +#include + +int main() +{ + + float basic,gross,hra,da; + + printf("Enter the basic salary: "); + scanf("%f",&basic); + + if(basic<1500) + { + hra=basic*10/100; + da=basic*90/100; + } + else + { + hra=500; + da=0.98*basic; + } + gross=basic+hra+da; + printf("The gross salary is %f\n",gross); + return 0; +} diff --git a/ch2/examples/example5.c b/ch2/examples/example5.c new file mode 100644 index 0000000..14fbeb0 --- /dev/null +++ b/ch2/examples/example5.c @@ -0,0 +1,30 @@ +#include + +int main() +{ + int s1,s2,s3,s4,s5; + float per; + printf("Enter the marks of all 5 subjects: "); + scanf("%d %d %d %d %d",&s1,&s2,&s3,&s4,&s5); + + per = (s1+s2+s3+s4+s5)/5; + if(per>=60) + { + printf("First Division\n"); + } + else if(per>=50 && per<=59) + { + printf("Second Division\n"); + } + else if(per>=40 && per<=49) + { + printf("Third Division\n"); + } + else if(per<40) + { + printf("Fail\n"); + } + + + return 0; +} diff --git a/ch2/examples/example6.c b/ch2/examples/example6.c new file mode 100644 index 0000000..8816e64 --- /dev/null +++ b/ch2/examples/example6.c @@ -0,0 +1,18 @@ +#include + +int main() +{ + + char sex,marital; + int age; + + printf("Enter age, sex, marital: "); + scanf("%d %c %c",&age,&sex,&marital); + + if((marital=='m')||(marital=='u' && sex=='m' && age>30)||(marital=='u' && sex=='f' && age>25)) + printf("you are insured !\n"); + else + printf("You are not married !\n"); + + return 0; +} diff --git a/ch2/examples/rough.c b/ch2/examples/rough.c new file mode 100644 index 0000000..9ce570c --- /dev/null +++ b/ch2/examples/rough.c @@ -0,0 +1,10 @@ +#include + +int main() +{ + int i; + printf("Enter value of i less than 10: "); + scanf("%d",&i); + (i<10?printf("What an obedient student u are !\n"):printf("useless student\n")); + return 0; +} diff --git a/ch2/exercises1/a.out b/ch2/exercises1/a.out new file mode 100755 index 0000000000000000000000000000000000000000..f98a8e927489e135efba427d897007018fbbfee3 GIT binary patch literal 6692 zcwV(wdu$v>8K2#I_!2vgUrpS+Sch|P1U}cUiBGdAe z+qxn}>73?fe)IiizHeUN&dhV+{=hc zmm!%3`83Ed-T;iz&vjsI0e%bU#;5>R9J1r@nQ^j85cS(qdbBMSZ%ye&z7Wc#LmjLf zR8!k}kDa7^nb!#r*5?W?7vtazg6nZ%!3P5s!pmNM@~;c7>h_os)|dS}{|X4|Al=1r zH(@x$@m`L1a{L|6-vn{Xj5mOG){^yvsA^(7ZKydjk~LM8z!1c+>s>_c8-UWdZm9X3 z7AKj!nIoC3ZkS^v7mFBUP!q|#=6FOmNN<1N!5+0E^a#@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6&LKewWL;36uZCVP6f{_bb59a$GBKB(DR; z=fI~4v+qq_U%b)2E!pe22FB}sz~6S@e{jBd!!5b^esD3r7xv5R$X3Ak?l{BsZI|u+ zUx)jjANeuC6EbAsW|K4XV`Gq2)t=#j6Ka3o(6FikI#h<9=y8B}T1}+V(MU?ACuud3 zFAz8-XHuG}#Y4OHbUsQln6wjm?pEXZ@$m_vAbjkQ-M#>aPjnv*TL_hjysax{>Cy`A z9cXcH|G>fSes$pR;i2%bI^2D*Ka5qde{f9CMkZ9vh?f`8S8JjkI(@ABXkQP(W4MvQn$b6Q6)I_yQhye`~UL{;oJzTB4)G + +/*profit and loss problem*/ + +//int main() +//{ +// float cp,sp; +// printf("Enter the cost price of the Item: "); +// scanf("%f",&cp); +// printf("Enter the selling price of the Item: "); +// scanf("%f",&sp); +// +// if(sp>cp) +// { +// printf("You have made a profit: "); +// printf("%.2f\n",(sp-cp)); +// } +// else if(cp>sp) +// { +// printf("You have a loss of: "); +// printf("%.2f\n",(cp-sp)); +// } +// else +// printf("You have neither made profit nor loss\n"); +// +// +// return 0; +//} diff --git a/ch2/exercises1/ex10.c b/ch2/exercises1/ex10.c new file mode 100755 index 0000000..2f4d0c9 --- /dev/null +++ b/ch2/exercises1/ex10.c @@ -0,0 +1,30 @@ +/* to check whether all the three points lie on a straight line */ + +#include + +int main() +{ + int x1,y1,x2,y2,x3,y3; + float area; + printf("Enter X1,Y1:"); + scanf("%d %d",&x1,&y1); + + printf("Enter X2,Y2:"); + scanf("%d %d",&x2,&y2); + + printf("Enter X3,Y3:"); + scanf("%d %d",&x3,&y3); + + /*compute the area formed by these three points. if + it is zero , then they all lie on a same line i.e they don form a triangle */ + area = (1/2)*((x1*(y2-y3))+(x2*(y3-y1))+(x3*(y1-y2))); + + if(area == 0) + printf("They lie on a straight line\n"); + else + printf("They dont lie on a straight line\n"); + + printf("Press any key to exit\n"); + getch(); + return 0; +} diff --git a/ch2/exercises1/ex12.c b/ch2/exercises1/ex12.c new file mode 100644 index 0000000..5804f85 --- /dev/null +++ b/ch2/exercises1/ex12.c @@ -0,0 +1,17 @@ +#include + +int main() +{ + int x,y; + printf("Enter x and y:"); + scanf("%d %d",&x,&y); + + if(y==0) + printf("It lies on X Axis\n"); + if(x==0) + printf("It lies on Y Axis\n"); + if(x==0 && y==0) + printf("It is in origin\n"); + + return 0; +} diff --git a/ch2/exercises1/ex3.c b/ch2/exercises1/ex3.c new file mode 100755 index 0000000..1cdac47 --- /dev/null +++ b/ch2/exercises1/ex3.c @@ -0,0 +1,17 @@ +/*leap year or not*/ + +#include + +//int main() +//{ +// int year; +// printf("Enter the year: "); +// scanf("%d",&year); +// +// if(!(year%4)) +// printf("The year %d is a leap year\n",year); +// else +// printf("It is not a leap year\n"); +// return 0; +//} + diff --git a/ch2/exercises1/ex4.c b/ch2/exercises1/ex4.c new file mode 100755 index 0000000..86022ec --- /dev/null +++ b/ch2/exercises1/ex4.c @@ -0,0 +1,35 @@ +#include + +//int main() +//{ +// int day=2; +// int n; +// int year; +// +// printf("Enter the year: "); +// scanf("%d",&year); +// +// n = year - 2001; +// +// if(n>7) +// n = n-7; +// +// day += n; +// +// if(day==1) +// printf("Sunday\n"); +// if(day==2) +// printf("Monday\n"); +// if(day==3) +// printf("Tuesday\n"); +// if(day==4) +// printf("Wednesday\n"); +// if(day==5) +// printf("Thursday\n"); +// if(day==6) +// printf("Friday\n"); +// if(day==7) +// printf("Saturday\n"); +// +// return 0; +//} diff --git a/ch2/exercises1/ex5.c b/ch2/exercises1/ex5.c new file mode 100755 index 0000000..fa0898c --- /dev/null +++ b/ch2/exercises1/ex5.c @@ -0,0 +1,41 @@ +/* reverse a five digit number and compare them for equality */ + +#include +#include + +//int main() +//{ +// long num,num_rev=0; +// int temp; +// printf("Enter the five digit number: "); +// scanf("%ld",&num); +// +// /*reverse the number */ +// +// temp = num%10; +// num_rev = num_rev + (temp*pow(10,4)); +// num = num/10; +// +// temp = num%10; +// num_rev = num_rev + (temp*pow(10,3)); +// num = num/10; +// +// temp = num%10; +// num_rev = num_rev + (temp*pow(10,2)); +// num = num/10; +// +// temp = num%10; +// num_rev = num_rev + (temp*pow(10,1)); +// num = num/10; +// +// temp= num%10; +// num_rev = num_rev + (temp*pow(10,0)); +// printf("The reverse is %ld\n",num_rev); +// +// /*check for equality*/ +// if(num==num_rev) +// printf("Both reverse and original are equal\n"); +// else +// printf("Both are not equal\n"); +// return 0; +//} diff --git a/ch2/exercises1/ex6.c b/ch2/exercises1/ex6.c new file mode 100755 index 0000000..bf85ec4 --- /dev/null +++ b/ch2/exercises1/ex6.c @@ -0,0 +1,21 @@ +#include + +//int main() +//{ +// int ram,shyam,ajay; +// +// printf("Enter the ages of ram, shyam and ajay: "); +// scanf("%d %d %d",&ram,­am,&ajay); +// +// if(ram +// +//int main() +//{ +// int a1,a2,a3; +// +// printf("Enter the angles of the triangle: "); +// scanf("%d %d %d",&a1,&a2,&a3); +// +// if((a1+a2+a3)==180) +// printf("The triangle is valid\n"); +// else +// printf("The triangle is invalid\n"); +// +// printf("Press any key to exit\n"); +// getch(); +// return 0; +//} \ No newline at end of file diff --git a/ch2/exercises1/ex8.c b/ch2/exercises1/ex8.c new file mode 100755 index 0000000..581add8 --- /dev/null +++ b/ch2/exercises1/ex8.c @@ -0,0 +1,15 @@ +/*To find the absolute value of the given number */ + +//#include +//#include +//int main() +//{ +// int i; +// printf("Enter a number: "); +// scanf("%d",&i); +// i = abs(i); +// printf("the absolute value is %d\n",i); +// printf("Pess any key to exit\n"); +// getch(); +// return 0; +//} diff --git a/ch2/exercises1/ex9.c b/ch2/exercises1/ex9.c new file mode 100755 index 0000000..145850b --- /dev/null +++ b/ch2/exercises1/ex9.c @@ -0,0 +1,23 @@ +/* area of a rectangle vs perimeter */ + +//#include +// +//int main() +//{ +// float len,bre,area,perim; +// +// printf("Enter the length and breadth of the rectangle: "); +// scanf("%f %f",&len,&bre); +// +// area = len * bre; +// perim = 2*(len + bre); +// +// if(area > perim) +// printf("Area is greater than perimeter\n"); +// else +// printf("Area is not greater than perimeter\n"); +// +// printf("Press any key to exit\n"); +// getch(); +// return 0; +//} \ No newline at end of file diff --git a/ch2/exercises1/exa2.c b/ch2/exercises1/exa2.c new file mode 100755 index 0000000..f6b7cb4 --- /dev/null +++ b/ch2/exercises1/exa2.c @@ -0,0 +1,16 @@ +/*Odd or even*/ + +#include + +int main() +{ + int i; + printf("Enter the Number: "); + scanf("%d",&i); + + if(!(i%2)) + printf("%d is even\n",i); + else + printf("%d is odd\n",i); + return 0; +} diff --git a/ch2/exercises1/exe11.c b/ch2/exercises1/exe11.c new file mode 100644 index 0000000..4cf23c2 --- /dev/null +++ b/ch2/exercises1/exe11.c @@ -0,0 +1,35 @@ +/*To find whether a point lies on,inside or outside a circle */ + +#include +#include +#include + +int main() +{ + int x1,y1,rad; + int x,y; + float d; + int temp; + + printf("Enter the center of the circle X1, Y1 :"); + scanf("%d %d",&x1,&y1); + printf("Enter the radius of the circle:"); + scanf("%d",&rad); + + printf("Enter the point (x,y):"); + scanf("%d %d",&x,&y); + + /*computing the distance between the two points*/ + temp = pow(x1-x,2)+pow(y1-y,2); + d = sqrt(temp); + + + if(d==rad) + printf("The point (%d,%d) lies on the circle\n",x,y); + else if(d3f(XPBV&;j9t#VoypD5Q+EkS5Yd{1k&9 z1rGQd5J&F=?*;DxUk8QMo$v;vhxs1z2J2;)-dR$oW!9a!Zw0By#_I-DZT-Fu9`V5 zMlz<6BbjVcHwH;A8rBCPCz5&2p>R?s+xmJp_o!=wYnV=%|5)Ekv>mIsJypr%Vr1;# z_`(@)zz@XVKv)Lh2N*(Q&0q+PcO648`a=w%;r5-rHISe47BKI@6VvlB&cMI7`=T1vK5^q=!L=XdShlNdb(l1cdNelc+!=2PLvK)5?u;=um= zTwwIM0@`C#+-b;9dEdH;CSE&-!Fbi!HS^B0kC)H=bEmB?%##B1kNVt@yN+kA0O?tj{sE-a z(){J71BWKU52l^|8bq#IgR zdBqItM$#Bj!g@^U$!f8rp|q@NRd%KgrT?g+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hz> zuxQJVUA!Y8Xm(&B`?rfX2E4Zy(2MtdCvPMCy(8hMigi~8bSM!eggn*!eY1@wxsEZh%ak(~0fb@5qZuR}P;o#lPAo{*;< z8J#w{9j?C^dN`}a!mNPp7G@fTEzCy4Sqrn(CvZ|=HmZ+Um>#p~y2dbTjY$hHV&z%* zF^Z=wTu$-4h1m$+l^2*jEH;b@TuE`4g&(JQ#=>kBy8foX)fCTKxQ61J7G^tC!NPSE zUpON$yUAX%@Df&@g_pAY7Op2w=OItJ@G=)(?!wNM67dQbe#(Wv5Zd=elctlp-M{!M__oWQ_aK}!l9!NM#I8S)tI0hV zUL@J$Lz3%Ajb!(~0`*$~7~k-4rqqD`R>>Z}h&vn|qJZyl;r$XD&p7k&jrFi(kM|lF z?=j97Z@4F<(l^;jF7GBxe$HWE71;L+z&ALqmY0%?fbqHUWy0+HEzd9Bfd44jo(vy2mU+fi#Os=TznraF(32(sF4?w2Eh2P`4-pLDBJVD2IoIN@?(G}WQfAeCTEy~ zgAi5Kp1u8h)V|(UOz8gvtnB{+lQaE| literal 0 HcwPel00001 diff --git a/ch2/exercises2/ex1.c b/ch2/exercises2/ex1.c new file mode 100644 index 0000000..8b5ca9e --- /dev/null +++ b/ch2/exercises2/ex1.c @@ -0,0 +1,14 @@ +#include + +int main() +{ + int year; + printf("Enter the year: "); + scanf("%d",&year); + + if((year%4==0)&&(year%100!=0)||(year%400==0)) + { + printf("The year is a leap year\n"); + } + return 0; +} diff --git a/ch2/exercises2/ex2.c b/ch2/exercises2/ex2.c new file mode 100644 index 0000000..9abcf0b --- /dev/null +++ b/ch2/exercises2/ex2.c @@ -0,0 +1,22 @@ +#include + +int main() +{ + char ch; + + printf("Enter a character: "); + scanf("%c",&ch); + + if(ch>=65 && ch<=90) + printf("It is a capital letter\n"); + else if(ch>=97 && ch<=122) + printf("It is a small letter\n"); + else if(ch>=48 && ch<=57) + printf("It is a number\n"); + else if((ch>=0 && ch<=47)||(ch>=58 && ch<=64)||(ch>=91&&ch<=96)||(ch>=123 &&ch<=127)) + printf("It is a special symbol\n"); + else + printf("Enter a correct letter\n"); + + return 0; +} diff --git a/ch2/exercises2/ex3.c b/ch2/exercises2/ex3.c new file mode 100644 index 0000000..0f1f302 --- /dev/null +++ b/ch2/exercises2/ex3.c @@ -0,0 +1,27 @@ +#include + +int main() +{ + int hard,tensile; + float carbon; + + printf("Enter hardness,carbon,Tensile strenght:"); + scanf("%d %f %d",&hard,&carbon,&tensile); + + if(hard>50 && carbon<0.7 && tensile>5600) + printf("Grade 10\n"); + else if(hard>50 && carbon<0.7 && !tensile>5600) + printf("Grade 9\n"); + else if(!hard>50 && carbon<0.7 && tensile>5600) + printf("Grade 8\n"); + else if(hard>50 && !carbon<0.7 && tensile>5600) + printf("Grade 7\n"); + else if((!hard>50 && !carbon<0.7 && tensile>5600)||(hard>50 && !carbon<0.7 && !tensile>5600)||(!hard>50 && carbon<0.7 && !tensile>5600)) + printf("Grade 6\n"); + else if(!hard>50 && !carbon<0.7 && !tensile>5600) + printf("Grade 5\n"); + + printf("End\n"); + + return 0; +} diff --git a/ch2/exercises2/ex4.c b/ch2/exercises2/ex4.c new file mode 100644 index 0000000..188fa37 --- /dev/null +++ b/ch2/exercises2/ex4.c @@ -0,0 +1,22 @@ +/*library problem */ + +#include + +int main() +{ + int days; + printf("Enter the number of late days:"); + scanf("%d",&days); + + if(days<=5) + printf("Fine is 50ps.\n"); + else if(days>=6 && days<=10) + printf("Fine is Rs.1\n"); + else if(days<=10 && days<=30) + printf("Fine is Rs.5\n"); + else if(days>30) + printf("YOUR MEMBERSHIP IS CANCELLED\n"); + + + return 0; +} diff --git a/ch2/exercises2/ex5.c b/ch2/exercises2/ex5.c new file mode 100644 index 0000000..7c9a444 --- /dev/null +++ b/ch2/exercises2/ex5.c @@ -0,0 +1,39 @@ +#include + +int main() +{ + + float s1,s2,s3; + float big; + printf("Enter s1,s2,s3:"); + scanf("%f %f %f",&s1,&s2,&s3); + big=s1; + + if(s2>big && s2>s3) + { big=s2; + if((s1+s3)>big) + printf("The triangle is valid\n"); + else + printf("The Triangle is not valid\n"); + } + else if(s3>big && s3>s2) + { big=s3; + if((s1+s2)>big) + printf("The triangle is valid\n"); + else + printf("The triangle is not valid\n"); + } + else + { + if((s2+s3)>big) + printf("The triangle is valid\n"); + else + printf("The triangle is not valid\n"); + } + + + + + + return 0; +} diff --git a/ch2/exercises2/ex6.c b/ch2/exercises2/ex6.c new file mode 100644 index 0000000..25a432d --- /dev/null +++ b/ch2/exercises2/ex6.c @@ -0,0 +1,30 @@ +/*check for isoceles,equilateral,right triangle*/ + +#include +#include + +int main() +{ + float s1,s2,s3; + float temp1,temp2,temp3; + printf("Enter the three sides of triangle: "); + scanf("%f %f %f",&s1,&s2,&s3); + + + /*checking equality*/ + if(s1==s2 && s2==s3) + printf("This is an equilateral triangle.\n"); + else if(s1==s2 || s2==s3 || s3==s1) + printf("This is an isoceles triangle.\n"); + else + printf("This is a scalene triangle\n"); + + + temp1 = sqrt(pow(s2,2)+pow(s3,2)); + temp2 = sqrt(pow(s1,2)+pow(s3,2)); + temp3 = sqrt(pow(s2,2)+pow(s1,2)); + if(s1==temp1 || s2==temp2 || s3==temp3) + printf("It is an right triangle\n"); + + return 0; +} diff --git a/ch2/exercises2/ex7.c b/ch2/exercises2/ex7.c new file mode 100644 index 0000000..93095c9 --- /dev/null +++ b/ch2/exercises2/ex7.c @@ -0,0 +1,24 @@ +/*worker efficiency problem*/ + +#include + +int main() +{ + float hours; + + printf("Enter the time required by the worker:"); + scanf("%f",&hours); + + if(hours>2 && hours<=3) + printf("Woker is highly effecient\n"); + else if(hours>3 && hours<=4) + printf("Worker is ordered \n"); + else if(hours>4 && hours<=5) + printf("Worker is given training\n"); + else if(hours > 5) + printf("Worker is fired\n"); + else + printf("Worker must be awarded\n"); + + return 0; +} diff --git a/ch2/exercises2/ex8.c b/ch2/exercises2/ex8.c new file mode 100644 index 0000000..ce5642f --- /dev/null +++ b/ch2/exercises2/ex8.c @@ -0,0 +1,21 @@ +/* Company policy*/ + +#include + +int main() +{ + int stock=500; + int qty; int credit; + + printf("Enter quantity and Credit (0- Not Ok 1- Ok):"); + scanf("%d %d",&qty,&credit); + + if(qty<=stock && credit==1) + printf("Supplying Item\n"); + else if(qty<=stock && credit==0) + printf("You have not credit\n"); + else if(qty>stock && credit==1) + printf("You have our supplies, rest will be supplied in a week\n"); + + return 0; +} diff --git a/ch2/exercises3/a.out b/ch2/exercises3/a.out new file mode 100755 index 0000000000000000000000000000000000000000..196cfbd154dc59de219fc9c1acf2d7f61a6a625f GIT binary patch literal 6611 zcwV(wYiv}<6`p(d;UzY%y>JiHi6ewMtu%OmQoxGSq5Ow&%=a z@7)_mB^4QacIKP;X3m+{nK}1FAlNTS5)nZr4uVK2I6ZzyQ>$6IpD3h?w324hMBEfZ zJP90#A449a3!)RE17ag|(s;`0!Po$}f!9eq(g1BS_CZ68*q+p}dRq1>)IqG1SbuI_ zFGF$=>JLI4#_NDFy15LDt-x;u*%%eTiluJ#^Dj8`{#oAIyJwM^gWqh5i z97I#ycJCXde3`fL5H@BvuXpf%tO2<$TV4`n3RREh-`w-pOSY!wd=WN|E}nl2D!hBZUR$JhnM}YHkYlQ1O-frBZ47hT)oj97^YZi$BZI z$HBu_=SthQLd#N%AAYe-sRbn@FnjxBXjW=LNeQgGeVt;Im_RjeU!oW#C)Ogq01z8? z{Qc<6p9?n^heHPv!&6ZEBK+)sF7Xw ztsCbtDb`Kj$lv+Eh4s?aInF;Hf^9r~$?*OPWkP1v6=yS+m97J4HrVV06-qz25A6Mg z1wT~Q!FtZ`0r|6m#hJe5n%Te-B%ay8G9*qQY(~O5AQVTJi-Dyb@4xg2%`NVD|HLwfZsHuFJH*yjO=)x7;zd4H(i7T7arI~0hG1kW-dYakwn{xNSrisv0S zcmq#ic$pBCgK8PnX%W)?)9ieF(SWvA3q4g^DAV;83UF2dIS4t|MwIl}kMP&!!28HOWGb_VDnm^M zg!V{2nToOBSbH2Vp0-ZkQ>>uPfP>k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char c; + printf("Enter a character:"); + scanf("%c",&c); + + (c>=97&&c<=122 ? printf("It is a small case letter\n"):printf("It is not a small letter\n")); + + return 0; +} diff --git a/ch2/exercises3/exA2.c b/ch2/exercises3/exA2.c new file mode 100644 index 0000000..717ff71 --- /dev/null +++ b/ch2/exercises3/exA2.c @@ -0,0 +1,15 @@ +#include + +int main() +{ + char c; + + printf("Enter a character:"); + scanf("%c",&c); + + ((c>=0 && c<=47)||(c>=58 && c<=64)||(c>=91 && c<=96)||(c>=123 && c<=127)? + printf("It is a special symbol\n"): + printf("It is not a special symbol\n")); + + return 0; +} diff --git a/ch2/exercises3/exB.c b/ch2/exercises3/exB.c new file mode 100644 index 0000000..cdf9c73 --- /dev/null +++ b/ch2/exercises3/exB.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int year; + printf("Enter a year:"); + scanf("%d",&year); + + (year%4==0 ? printf("This is a leap year\n"):printf("This is not a leap year\n")); + + return 0; +} diff --git a/ch2/exercises3/exC.c b/ch2/exercises3/exC.c new file mode 100644 index 0000000..493b205 --- /dev/null +++ b/ch2/exercises3/exC.c @@ -0,0 +1,16 @@ +/*greatest of three numbers*/ + +#include + +int main() +{ + int n1,n2,n3; + int max; + printf("Enter any three numbers:"); + scanf("%d %d %d",&n1,&n2,&n3); + + max=(n1>n2 && n1>n3 ?n1:(n2>n1 && n2>n3 ? n2 : n3)); + + printf("Maximum:%d\n",max); + return 0; +} diff --git a/ch3/examples/a.out b/ch3/examples/a.out new file mode 100755 index 0000000000000000000000000000000000000000..35bd8d6f60e3426418ea8e36f99994df9da81715 GIT binary patch literal 6420 zcwV(weQXrR6`$SPJ0G=i&L0f~NI17PH7dS~iE#`lEyf(i#KC|eg&?xr$NKJ?^WODt zj~a<2z+qL$ShX4>kt$U|MUAC85>1dw6)SRN6ok}96!ou0N?o;SO`(z_(G;~b+xO;U zcW>*cq#|>go%zlD=DjzcH*a2!^lp_TiHIN*4?#44Lh-jj`l~8d-bR9?f;5vx(m;F^ zLp%l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33% za}FNfoes(DPKCTG2k!`%k9u(549T{iBjjN)96a1R6TsW#;$eK*!9zcG9(bq4U=Z79 z8Fuh+pB{zAD_rt0j1YUh;9flo6%Q@Id&R+<0N#XR*ExAV;yj!?>f#YZJiIfHd)fTDc~>30 zN#IR-+59_s7=BG`UmE?X%M0kmaD&)u8w2uIISNGf0~c@B$M%s3Vl4ma;yn(VzR7__ z-9KHty})~Y0lnz=I(hd%QPzP)UA>F<0&JGm3&;y{p4b!PuzBBhw3B%Jx=Y^9%JTgo z`ink{^L=6rch#zs`WiGtjg`FoQ;zwQhF&AFx!ojk2p^%Tw^0Vz@)A^r_7$u7Fl3={h4Z39E zTC#!I<0Zj(bwe5y-WJRcx*hbLhSo178Ek(>@Rtz0MC^3%-TLu=<)TCXX~KPRuK!hH z&o91?z3#H-EtG%KmhbNGH5dL3vFB5gA0~excK?Z7L+-k8rDU%UNv@~oiu^z2r=Tq`z5xXap&RN;vvai@3pYr2RL86O_rqcx5ytj>#U-CF+*_J361~ z=^}WK7iH{e7{jj=QOQs9pt8`_eg#z5o)q$Lv`Yz$k+%L?VHrY?i zF7FPy=hUAlWYttuPh>QwG1PHk&(~$5RPa7TQ`$|9IwjEC_Kx;YQZv+CTs2Zf{e@6$ Kh|srgChI@6q<}C0 literal 0 HcwPel00001 diff --git a/ch3/examples/exa1.c b/ch3/examples/exa1.c new file mode 100644 index 0000000..6f371b7 --- /dev/null +++ b/ch3/examples/exa1.c @@ -0,0 +1,20 @@ +/*simple interest for 3 different persons*/ + +#include + +int main() +{ + int p,n,count; + float r,si; + + count = 1; + while(count<=3) + { + printf("Enter p, n and r:"); + scanf("%d %d %f",&p,&n,&r); + si=p*n*r/100; + printf("Simple Interest:Rs.%f\n",si); + count++; + } + return 0; +} diff --git a/ch3/examples/exa10.c b/ch3/examples/exa10.c new file mode 100644 index 0000000..7741d7c --- /dev/null +++ b/ch3/examples/exa10.c @@ -0,0 +1,10 @@ +#include + +int main() +{ + int i; + for(i=0;i++<10;) + printf("%d\n",i); + + return 0; +} diff --git a/ch3/examples/exa11.c b/ch3/examples/exa11.c new file mode 100644 index 0000000..aa9040d --- /dev/null +++ b/ch3/examples/exa11.c @@ -0,0 +1,11 @@ +#include + +int main() +{ + + int i; + for(i=0;++i<=10;) + printf("%d\n",i); + + return 0; +} diff --git a/ch3/examples/exa12.c b/ch3/examples/exa12.c new file mode 100644 index 0000000..66e1530 --- /dev/null +++ b/ch3/examples/exa12.c @@ -0,0 +1,18 @@ +#include + +int main() +{ + int r,c,sum; + + for(r=1;r<=3;r++) + { + for(c=1;c<=2;c++) + { + sum= r+c; + printf("r=%d c=%d sum=%d\n",r,c,sum); + } + } + + + return 0; +} diff --git a/ch3/examples/exa13.c b/ch3/examples/exa13.c new file mode 100644 index 0000000..a1e8d98 --- /dev/null +++ b/ch3/examples/exa13.c @@ -0,0 +1,19 @@ +/*Execution of a loop an unknown number of times*/ + +#include + +int main() +{ + char another='y'; + int num; + do{ + printf("Enter a number:"); + scanf("%d",&num); + printf("Square of %d is %d\n",num,num*num); + + printf("Want to enter another number Y/n:"); + scanf("%c",&another); + }while(another=='y'); + + return 0; +} diff --git a/ch3/examples/exa14.c b/ch3/examples/exa14.c new file mode 100644 index 0000000..c721724 --- /dev/null +++ b/ch3/examples/exa14.c @@ -0,0 +1,27 @@ +/*Break statements*/ + +#include + +int main() +{ + int num,i; + + i=2; + + printf("Enter a number:"); + scanf("%d",&num); + + while( i<= num-1) + { + if(num%i == 0 ) + { + printf("Not a prime number\n"); + break; + } + i++; + } + if(i==num) + printf("This is a prime number"); + + return 0; +} diff --git a/ch3/examples/exa15.c b/ch3/examples/exa15.c new file mode 100644 index 0000000..769052e --- /dev/null +++ b/ch3/examples/exa15.c @@ -0,0 +1,16 @@ +#include + +int main() +{ + int i=1,j=1; + while(i++<=100) + { + while(j++<=200) + { + if(j==150) + break; + else + printf("%d %d\n",i,j); + } + } +} diff --git a/ch3/examples/exa16.c b/ch3/examples/exa16.c new file mode 100644 index 0000000..c5f4562 --- /dev/null +++ b/ch3/examples/exa16.c @@ -0,0 +1,19 @@ +#include + +int main() +{ + + int i,j; + for(i=1;i<=2;i++) + { + for(j=1;j<=2;j++) + { + if(i==j) + continue; + + printf("%d %d\n",i,j); + + } + } + return 0; +} diff --git a/ch3/examples/exa2.c b/ch3/examples/exa2.c new file mode 100644 index 0000000..c7b358d --- /dev/null +++ b/ch3/examples/exa2.c @@ -0,0 +1,14 @@ +/*while loop with decrementing counter*/ + +#include + +int main() +{ + int i=5; + while(i>=1) + { + printf("I:%d\n",i); + i--; + } + return 0; +} diff --git a/ch3/examples/exa3.c b/ch3/examples/exa3.c new file mode 100644 index 0000000..c3882c4 --- /dev/null +++ b/ch3/examples/exa3.c @@ -0,0 +1,10 @@ +#include + +int main() +{ + int i=0; + while(i++<10) + printf("%d\n",i); + + return 0; +} diff --git a/ch3/examples/exa4.c b/ch3/examples/exa4.c new file mode 100644 index 0000000..3080d2c --- /dev/null +++ b/ch3/examples/exa4.c @@ -0,0 +1,9 @@ +#include + +int main() +{ + int i=0; + while(++i<=10) + printf("i:%d\n",i); + return 0; +} diff --git a/ch3/examples/exa5.c b/ch3/examples/exa5.c new file mode 100644 index 0000000..9e1a648 --- /dev/null +++ b/ch3/examples/exa5.c @@ -0,0 +1,16 @@ +#include + +int main() +{ + int p,n,count; + float r,si; + for(count=1;count<=3;count++) + { + printf("Enter values of p,n and r: "); + scanf("%d %d %f",&p,&n,&r); + + si=p*n*r/100; + printf("SI:%.2f\n",si); + } + return 0; +} diff --git a/ch3/examples/exa6.c b/ch3/examples/exa6.c new file mode 100644 index 0000000..5024806 --- /dev/null +++ b/ch3/examples/exa6.c @@ -0,0 +1,10 @@ +#include + +int main() +{ + int i; + for(i=1;i<=10;i++) + printf("%d\n",i); + + return 0; +} diff --git a/ch3/examples/exa7.c b/ch3/examples/exa7.c new file mode 100644 index 0000000..18ab4a7 --- /dev/null +++ b/ch3/examples/exa7.c @@ -0,0 +1,13 @@ +/*another way form of for loop to print the numbers*/ + +#include + +int main() +{ + int i=1; + for(;i<=10;i++) + { + printf("%d\n",i); + } + return 0; +} diff --git a/ch3/examples/exa8.c b/ch3/examples/exa8.c new file mode 100644 index 0000000..9a8ab7a --- /dev/null +++ b/ch3/examples/exa8.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int i; + for(i=1;i<=10;) + { + printf("%d\n",i); + i++; + } + return 0; +} diff --git a/ch3/examples/exa9.c b/ch3/examples/exa9.c new file mode 100644 index 0000000..f7e2dd9 --- /dev/null +++ b/ch3/examples/exa9.c @@ -0,0 +1,12 @@ +#include + +int main() +{ + int i=1; + for(;i<=10;) + { + printf("%d\n",i); + i++; + } + return 0; +} diff --git a/ch3/exercises/a.out b/ch3/exercises/a.out new file mode 100755 index 0000000000000000000000000000000000000000..8306fa24faf2251fa158c44b244b1b2d9ddd867d GIT binary patch literal 6769 zcwV(weQXrR6`$Sv@DUs1uLdWWWPzL zi2H#9@do5EIw0C1+91||keUN_7shJ9)mojPMH-+j#%s_JBeo|Mte%z~gF1+{P*4Za zsnv^+OhWx6)L|S0jM1s-z}N)*CeV%14cKj}+jLV6kZA&M-x3M?TOxtxNLWerdy+BF z0#**HscmaEY^8irYvUrU&m~%lT!%@npmDhlb6bIP-PA-{_TIX`oFkS{YRV(=X$$sf z`4JFU1!=d2-`DUu4KE=KFNb(~!0tj@E6FTEpwCh4>mnja!Dvj8lBzGEN)nM?+9h?% z!EjQQ6CDv>GASoXJhmGf^lA+{Hv&5lR-{x?4v=^vtf+k;1{s=|s4uLLHC>%6JER4k z=QLYzt>J3J9}F=aU+haoI6MRn1~ygLI)=> zg+bn$xw$!=x970UjswG2U`=M|P+%r&``z8LZg~@qs$Hn2o!ck~hXuJad z*rw2k8bX-8eFK^m8c|aS>u!%yj2c5|=IwJ7qvlX8;xhoTVe8*_X8xR>n0$FlcWCku zN`pz*^h#(7_FL{Okfx3l1+Y1tckO?13T;r!?$o8v*?%&LW?epsNw#9(a_Y{<4y+e0 z4r~0AdDs>M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Wxmcv0IX2QI##=?6Sc=M-`=hk?9&0PWKaMsjL(Bd~N@{W|T{mTRIFWzNrrt(qX zEty6yU&}n41}AyO&ivvF#PCD7$IbFyuZ4S+siD~>Ye4^tsZC=w>6i&vt7E32U&m}U zoX|1zKCXitvsJxI$Ml#@{Tjn;G|uaI2E~_j%r2yP9kUm#x-`dZ1;=$flj6ez9J7bV zQ#zhS@tBU87rJ(g<4TGrbX-MoUdQYUHL2qoiZ2}JnB8PA>G(;Cb2^?)@sy5hi8A~T+k*MQYX^O2qV=^T0_o&&&Yw;25HV`vTlM32<%UWBVWQo~HT^#%#{3E} zzwcP=`2f=I3>fmQ{k>?xzaz$c3gVOGCNcU?#7c74f@cWE`Vhn#QY9Gk?}q-(#ri|+ zO{5C+Hw(u4McihZ5I4jQ3w~8#>lt?*zPaucjP+gx>ph_H`5SIh!~6~Rh*11y`ftVDG z#QeU9L{H9=FV#=rR2+}UsvPhvT-^3NiDS}A=s8;oq@vM1T!DAPDnmX8tGnCRdv%1$ zc;3*}tLu{c7ox#yx;CzC?~*pIUcK47McUH7vdfDtuzPSSPx$sovJxmRps(LVTD5IM z`})off~R_3#-7LFCM40@f?oW&kMB}nTng + +int main() +{ + int hours; + int i; + float pay; + i=1; + + while(i<=10) + { + printf("Enter the number of hours: "); + scanf("%d",&hours); + + if((hours-40)>0) + { + printf("You get an overpay award\n"); + pay= (hours-40)*12; + printf("The overtime award: %.2f\n",pay); + } + else + { + printf("You dont get an overtime pay\n"); + } + + i++; + } + printf("Bye"); + return 0; +} diff --git a/ch3/exercises/ex2.c b/ch3/exercises/ex2.c new file mode 100644 index 0000000..fb9ee88 --- /dev/null +++ b/ch3/exercises/ex2.c @@ -0,0 +1,24 @@ +/*factorial of a given number*/ + + +#include + +int main() +{ + int num; + int i; + long fact; + printf("Enter a number:"); + scanf("%d",&num); + + i=1; + fact = 1; + while(i<=num) + { + fact = fact*i; + i++; + } + printf("The factorial is %ld\n",fact); + printf("Bye\n"); + return 0; +} diff --git a/ch3/exercises/ex3.c b/ch3/exercises/ex3.c new file mode 100644 index 0000000..2a482e2 --- /dev/null +++ b/ch3/exercises/ex3.c @@ -0,0 +1,21 @@ +/*one number power another */ + +#include + +int main() +{ + int p,q; + long ans=1; + printf("Enter numbers p and q:"); + scanf("%d %d",&p,&q); + + while(q>0) + { + + ans = ans * p; + + q--; + } + printf("The power of the number is %ld\n",ans); + return 0; +} diff --git a/ch3/exercises/ex4.c b/ch3/exercises/ex4.c new file mode 100644 index 0000000..aba870f --- /dev/null +++ b/ch3/exercises/ex4.c @@ -0,0 +1,15 @@ +/*print ascii values and their equivalent characters*/ + +#include + +int main() +{ + int ascii=0; + + while(ascii<=255) + { + printf("ASCII=%d Character = %c\n",ascii,ascii); + ascii++; + } + return 0; +} diff --git a/ch3/exercises/ex5.c b/ch3/exercises/ex5.c new file mode 100644 index 0000000..5f0df23 --- /dev/null +++ b/ch3/exercises/ex5.c @@ -0,0 +1,35 @@ +/*printf ascii numbers from 1 to 500*/ + +#include +#include +int main() +{ + int i=1; + + int temp; + int digit; + int sum; + + while(i<=500) + { + temp=i; + sum=0; + + while(temp!=0) + { + + digit = temp%10; + sum = sum + pow(digit,3); + temp=temp/10; + } + + if(sum==i) + printf("%d is an armstrong number\n",i); + + /*printf("The sum is %d\n",sum);*/ + + i++; + } + + return 0; +} -- 2.11.4.GIT