Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Exercise_2/2.10_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include<stdio.h>
#include<math.h>
#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);
}
13 changes: 13 additions & 0 deletions Exercise_2/2.1_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>

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);
}
10 changes: 10 additions & 0 deletions Exercise_2/2.2_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<math.h>
#include <stdio.h>

void main()
{
double p,r;
printf("Enter r: ");
scanf("%lf",&r);
printf("You entered %0.2lf paise",(r*100));
}
10 changes: 10 additions & 0 deletions Exercise_2/2.3_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>

void main()
{
int i;
for(i=2;i<101;i=i+2)
{
printf("%d ",i);
}
}
12 changes: 12 additions & 0 deletions Exercise_2/2.4_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

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));
}
12 changes: 12 additions & 0 deletions Exercise_2/2.5_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

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

24 changes: 24 additions & 0 deletions Exercise_2/2.6_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>

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;i<n;i++)
{
if(a[i]>0)
po++;
else
ne++;
}
printf("You entered %d positive and %d negative numbers\n",po,ne);
}
12 changes: 12 additions & 0 deletions Exercise_2/2.7_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

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.");
}
11 changes: 11 additions & 0 deletions Exercise_2/2.8_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

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);
}
8 changes: 8 additions & 0 deletions Exercise_2/2.9_Sol.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

void main()
{
typedef int num;
num n1=4,n2=6;
printf("Numbers are %d %d",n1,n2);
}