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 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 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 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 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 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 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 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 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 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); +}