From f86a611449abd8037c80e13c9f7cd63684d483c0 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:04:51 +0530 Subject: [PATCH 01/10] 2: Solution for 2.9 --- Exercise_2/2.9_Sol.c | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Exercise_2/2.9_Sol.c diff --git a/Exercise_2/2.9_Sol.c b/Exercise_2/2.9_Sol.c new file mode 100644 index 0000000..792c5bf --- /dev/null +++ b/Exercise_2/2.9_Sol.c @@ -0,0 +1,8 @@ +#include + +void main() +{ + typedef int num; + num n1=4,n2=6; + printf("Numbers are %d %d",n1,n2); +} From 5459e8bd6ae4ccb474a4329aab9ab2e449199159 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:04:32 +0530 Subject: [PATCH 02/10] 2: Solution for 2.8 --- Exercise_2/2.8_Sol.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Exercise_2/2.8_Sol.c diff --git a/Exercise_2/2.8_Sol.c b/Exercise_2/2.8_Sol.c new file mode 100644 index 0000000..827b155 --- /dev/null +++ b/Exercise_2/2.8_Sol.c @@ -0,0 +1,11 @@ +#include + +void main() +{ + float x,y; + int z; + printf("Enter values of x and y: "); + scanf("%f%f",&x,&y); + z = x+y; + printf("The values of x, y and z are: %f %f %d\n",x,y,z); +} \ No newline at end of file From 0db1ed8c53f68fd54dc7cdb68b9f5b8dd3a92f7c Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:04:11 +0530 Subject: [PATCH 03/10] 2: Solution for 2.7 --- Exercise_2/2.7_Sol.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Exercise_2/2.7_Sol.c diff --git a/Exercise_2/2.7_Sol.c b/Exercise_2/2.7_Sol.c new file mode 100644 index 0000000..eb8afc7 --- /dev/null +++ b/Exercise_2/2.7_Sol.c @@ -0,0 +1,12 @@ +#include + +void main() +{ + int x,y; + short z; + x = 343534; + y = 283729; + z = x+y; + printf("The values of x, y and z are: %d %d %i\n",x,y,z); + printf("Size of an integer is 16bits and for short is 8 bits."); +} \ No newline at end of file From a36afb0d899af9de56161589e50b93fc8b59984b Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:00:58 +0530 Subject: [PATCH 04/10] 2: Solution for 2.1 --- Exercise_2/2.1_Sol.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Exercise_2/2.1_Sol.c diff --git a/Exercise_2/2.1_Sol.c b/Exercise_2/2.1_Sol.c new file mode 100644 index 0000000..2be11fb --- /dev/null +++ b/Exercise_2/2.1_Sol.c @@ -0,0 +1,13 @@ +#include + +void main() +{ + float prod=0,i,n; + printf("Enter n: "); + scanf("%f",&n); + for(i=1;i<=n;i=i+1) + { + prod = prod + (1/i); + } + printf("The sum of series 1 + 1/2 + 1/3 +....+ 1/n is: %0.2f",prod); +} \ No newline at end of file From a2283b324d454be9f5cb9be005cf4e73b6431b50 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:01:46 +0530 Subject: [PATCH 05/10] 2: Solution for 2.2 --- Exercise_2/2.2_Sol.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Exercise_2/2.2_Sol.c diff --git a/Exercise_2/2.2_Sol.c b/Exercise_2/2.2_Sol.c new file mode 100644 index 0000000..856c632 --- /dev/null +++ b/Exercise_2/2.2_Sol.c @@ -0,0 +1,10 @@ +#include +#include + +void main() +{ + double p,r; + printf("Enter r: "); + scanf("%lf",&r); + printf("You entered %0.2lf paise",(r*100)); +} \ No newline at end of file From 22f72405f27569561166106acde8a7c988082f15 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:02:08 +0530 Subject: [PATCH 06/10] 2: Solution for 2.3 --- Exercise_2/2.3_Sol.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Exercise_2/2.3_Sol.c diff --git a/Exercise_2/2.3_Sol.c b/Exercise_2/2.3_Sol.c new file mode 100644 index 0000000..04e28be --- /dev/null +++ b/Exercise_2/2.3_Sol.c @@ -0,0 +1,10 @@ +#include + +void main() +{ + int i; + for(i=2;i<101;i=i+2) + { + printf("%d ",i); + } +} \ No newline at end of file From 6ead0ed835cd508eb9a8de291ea6ac1b3eb9e334 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:02:31 +0530 Subject: [PATCH 07/10] 2: Solution for 2.4 --- Exercise_2/2.4_Sol.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Exercise_2/2.4_Sol.c diff --git a/Exercise_2/2.4_Sol.c b/Exercise_2/2.4_Sol.c new file mode 100644 index 0000000..65643f5 --- /dev/null +++ b/Exercise_2/2.4_Sol.c @@ -0,0 +1,12 @@ +#include + +void main() +{ + float x,y; + printf("Enter x and y "); + scanf("%f%f",&x,&y); + if(y == 0) + printf("Division not possible.\n"); + else + printf("Division is %f\n",(x/y)); +} \ No newline at end of file From 07db917188d4f6635affbb21bdb117255ac89df3 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:03:33 +0530 Subject: [PATCH 08/10] 2: Solution for 2.5 --- Exercise_2/2.5_Sol.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Exercise_2/2.5_Sol.c diff --git a/Exercise_2/2.5_Sol.c b/Exercise_2/2.5_Sol.c new file mode 100644 index 0000000..e6b5dbb --- /dev/null +++ b/Exercise_2/2.5_Sol.c @@ -0,0 +1,12 @@ +#include + +void main() +{ + float pr,ps; + printf("Enter the prices of rice and sugar: "); + scanf("%f%f",&pr,&ps); + printf("Item Price\n"); + printf("Rice Rs.%0.2f\n",pr); + printf("Sugar Rs.%0.2f\n",ps); +} + \ No newline at end of file From b9be41cef43c8abd7a37022bca28c60ccf687d5b Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:03:53 +0530 Subject: [PATCH 09/10] 2: Solution for 2.6 --- Exercise_2/2.6_Sol.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Exercise_2/2.6_Sol.c diff --git a/Exercise_2/2.6_Sol.c b/Exercise_2/2.6_Sol.c new file mode 100644 index 0000000..a4d6f53 --- /dev/null +++ b/Exercise_2/2.6_Sol.c @@ -0,0 +1,24 @@ +#include + +void main() +{ + int a[10],i=0,n,po=0,ne=0; + printf("Enter numbers. Enter 0 to stop."); + while(1) + { + scanf("%d",&a[i]); + if(a[i] == 0) + break; + else + i++; + } + n = i; + for(i=0;i0) + po++; + else + ne++; + } + printf("You entered %d positive and %d negative numbers\n",po,ne); +} \ No newline at end of file From 2d0b9e7be98495795413b86ee15a6bf40a7c3630 Mon Sep 17 00:00:00 2001 From: anerimehta Date: Wed, 20 Dec 2017 16:05:08 +0530 Subject: [PATCH 10/10] 2: Solution for 2.10 --- Exercise_2/2.10_Sol.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Exercise_2/2.10_Sol.c diff --git a/Exercise_2/2.10_Sol.c b/Exercise_2/2.10_Sol.c new file mode 100644 index 0000000..3403165 --- /dev/null +++ b/Exercise_2/2.10_Sol.c @@ -0,0 +1,11 @@ +#include +#include +#define PIE 3.14//Symbolic constant. + +void main() +{ + double r = 4,a,p; + a = PIE * r * r; + p = 2 * PIE * r; + printf("The area of the circle with radius = 4 is %0.2lf and perimeter is %0.2lf\n",a,p); +} \ No newline at end of file