0% found this document useful (0 votes)
7 views2 pages

11

Uploaded by

Vedant Gade
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)
7 views2 pages

11

Uploaded by

Vedant Gade
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/ 2

1.

Write the structure declaration in C with suitable example

struct StructureName {
dataType member1;
dataType member2;
// ... more members
};

#include <stdio.h>

// Define a structure named 'Person' to store information about a


person
struct Person {
char name[50];
int age;
float height;
};

int main() {
// Declare a variable of the 'Person' structure
struct Person person1;

// Initialize the structure members for 'person1'


strcpy(person1.name, "John Doe");
person1.age = 30;
person1.height = 175.5;

// Access and print the information stored in the 'person1' structure


printf("Name: %s\n", person1.name);
printf("Age: %d\n", person1.age);
printf("Height: %.2f cm\n", person1.height);

return 0;
}
In this example, we've declared a structure named 'Person' with three
members: 'name' (a character array to store the name), 'age' (an
integer to store the age), and 'height' (a floating-point number to store
the height). We then declared a variable of the 'Person' structure
called 'person1' and initialized its members with data. Finally, we
accessed and printed the information stored in the 'person1' structure.

2. Write the output of following code:


main( )
{
int radius ;
float area, perimeter ;
printf ( "\nEnter radius of a circle " ) ;
scanf ( "%d", &radius ) ;
areaperi ( radius, &area, &perimeter ) ;
printf ( "Area = %f", area ) ;
printf ( "\nPerimeter = %f", perimeter ) ;
}
areaperi ( int r, float *a, float *p )
{

*a = 3.14 * r * r ;
*p = 2 * 3.14 * r ;
}
Enter radius of a circle 5
Area = 78.500000
Perimeter = 31.400000

Explanation:

1. The user is prompted to enter the radius of a circle, and the input is read using
scanf.
2. The areaperi function is called with the radius and pointers to area and perimeter
as arguments.
3. Inside the areaperi function, the area is calculated as 3.14 * r * r, and the
perimeter is calculated as 2 * 3.14 * r. These values are stored in the memory
locations pointed to by the a and p pointers.
4. The area and perimeter values are printed in the main function, resulting in the
output shown above.

You might also like