0% found this document useful (0 votes)
6 views4 pages

lab_structures_pointers

Uploaded by

Assia Naja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

lab_structures_pointers

Uploaded by

Assia Naja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Exercise 1:

1- Write a C program that reads an array of integers then searches and displays the max and
min values of this table.

2- Create a max_min function which receives as parameters: an array of integers, the

array size, min and max. This function must find and put the 2 values (minimum and
maximum) in the max and min parameters.

3- Test this function in a main program.


Exercise 2:

Write in two different ways, a program that checks without using a function of <string>, if a
keyed CH string is a palindrome:

1- using only the array formalism

2- using pointers instead of numeric indices

Reminder: A palindrome is a word that stays the same whether you read it from left to

right or right to left:

Exemples: PIERRE ==> is not a palindrome

OTTO ==> is a palindrome

23432 ==> is a palindrome


Exercise 3:

We define a point in a 2-dimensional space by two real numbers x and y.

a. Define the point data structure in a program.

b. Then write the circle structure, consisting of the center of the circle (which is a point) and
its radius which is an integer.

c. Enter the data of a circle on the keyboard and calculate its perimeter and area

d. Then enter a point on the keyboard and test if this point belongs to the circle

Solution

#include <stdio.h>

#include <math.h>

#define PI 3.14

typedef struct{float X,Y;}Point;

typedef struct{Point Centre;int Rayon;}Cercle;

int main()

Cercle C;

printf("Donner les coordonneés du centre: ");

scanf("%f %f",&C.Centre.X,&C.Centre.Y);

printf("Donner la valeur du rayon R: ");

scanf("%d",&C.Rayon);

printf("le perimetre est: %f\n",2*PI*C.Rayon);


printf("la surface du cercle est: %f\n",PI*C.Rayon*C.Rayon);

Point P;

printf("Entrer les coordonner de point P: ");

scanf("%f %f",&P.X,&P.Y);

float d= sqrt(pow(P.X-C.Centre.X,2)+pow(P.Y-C.Centre.Y,2));

d<=C.Rayon ? printf("Le point P est dans le cercle") : printf("le point P est en dehors
du cercle");

return 0;

You might also like