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

c++7 Code

The document contains multiple C programs demonstrating basic programming concepts. It includes a program to calculate the area of a triangle, compare ages of siblings, determine if a year is a leap year, and generate a Fibonacci series. Each program includes user input and output examples.

Uploaded by

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

c++7 Code

The document contains multiple C programs demonstrating basic programming concepts. It includes a program to calculate the area of a triangle, compare ages of siblings, determine if a year is a leap year, and generate a Fibonacci series. Each program includes user input and output examples.

Uploaded by

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

7.

#include <stdio.h>
int main()
{
float base, height, area;

// Input base and height of the triangle

printf("Enter the base and height of the triangle: ");


scanf("%f %f", &base, &height);

// Calculate area of the triangle


area = 0.5 * base * height;

// Display the area


printf("Area of the triangle = %.2f\n", area);
return 0;
}

Output :

Enter the base and height of the triangle: 10


54
Area of the triangle = 270.00

#include <stdio.h>
int main()
{
int age1, age2;

// Input ages of two siblings


printf("Enter the age of sibling 1: ");
scanf("%d", &age1);

printf("Enter the age of sibling 2: ");


scanf("%d", &age2);

// Compare ages and display the result


if (age1 < age2)
{
printf("Sibling 1 is younger.\n");
}
else if (age1 > age2)
{
printf("Sibling 2 is younger.\n");
}
else {
printf("Both siblings are of the same age.\n");
}
return 0;
}

Output:

Enter the age of sibling 1: 54


Enter the age of sibling 2: 56
Sibling 1 is younger.

#include <stdio.h>
int main()
{
int year;

// Input the year


printf("Enter a year: ");
scanf("%d", &year);

// Check if the year is leap or not


if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
printf("%d is a leap year.\n", year);
}
else {
printf("%d is not a leap year.\n", year);
}
return 0;
}

Output :

Enter a year: 2000


2000 is a leap year.

#include <stdio.h>
int main()
{
int n, first = 0, second = 1, next, i;

// Input the number of terms


printf("Enter the number of terms: ");
scanf("%d", &n);
// Display the Fibonacci series
printf("Fibonacci Series: ");

for (i = 0; i < n; i++)


{
printf("%d, ", first);
next = first + second;
first = second;
second = next;
}
return 0;
}

You might also like