# Cpps

Submitted by: Submitted by

Views: 184

Words: 285

Pages: 2

Category: Science and Technology

Date Submitted: 09/18/2012 03:33 AM

Report This Essay

Lab 2 Assignment

Question: Using two functions create the following square shape:

AAAAAAAAAA

A A

A A

A A

A A

AAAAAAAAAA

#include<stdio.h>

/*Prototype for line() */

void line(void);

/*Prototype for line1() */

void line1(void);

void main(void)

{

/* Function Call */

line();

line1();

line1();

line1();

line1();

line();

getch();

}

void line(void)

/* Function Definition */

{

int j;

for(j=0;j<=10;j++)

printf("A");

printf("\n");

}

void line1(void)

{

/* Function Definition */

int i;

for(i=1;i<=1;i++)

printf("A         A");

printf("\n");

}

Output:

Q,Using 2 functions beside the main() function, calculate the Euclidean distance (i.e. distance from the

origin (0,0) ) of any coordinate (x,y) taken as input in the main() function. Furhermore, if the distance

is greater than 10, a message will appear as ‘Outside the circle’ otherwise it will prompt ‘Inside the

circle”. You need to perform these tasks and print necessary messages using 2 functions along with

the main() function. Use any variation you like in terms of code distribution.

#include<conio.h>

#include<Math.h>

float distance(int x,int y);

void test (float point);

main()

{

int x,y;

float d;

printf("Enter x1 and y1 cordinate respectively from the origin: "); /*(x2,y2) =(0,0)*/

scanf("%d %d",&x, &y);

d=distance(x,y);

printf("\nEuclidean distance is:%f",d);

test (d);

getch();

return 0;

}

float distance (int x,int y)

{

int e,f,d;

float g;

e=pow(x,2);

f=pow(y,2);

d=e+f;

g=sqrt(d);

return(g);

}

void test (float point)

{

if(point>10)

printf("\n Its Outside the circle");

else

printf("\n Its inside the circle");

}

Output: