0% found this document useful (0 votes)
24 views105 pages

Suhail CP

The document contains 20 questions about writing C programs to perform various tasks like inputting and calculating values. For each question, the code for the C program is provided, along with sample input and output. Common tasks include calculating sums, products, areas, checking number properties, and more.

Uploaded by

udit mishra
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)
24 views105 pages

Suhail CP

The document contains 20 questions about writing C programs to perform various tasks like inputting and calculating values. For each question, the code for the C program is provided, along with sample input and output. Common tasks include calculating sums, products, areas, checking number properties, and more.

Uploaded by

udit mishra
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/ 105

Q1.Write a program to print Hello World.

#include <stdio.h>

int main() {
printf("Hello World!\n");
return 0;
}

[1]
OUTPUT:-

[2]
Q2.Write a program to input two number and print its
product.

#include <stdio.h>
int main() {
int num1, num2, product;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
product = num1 * num2;
printf("The product of %d and %d is %d\n", num1, num2, product);
return 0;
}

[3]
OUTPUT:-

[4]
Q3. Write a program to input two number and print its
sum.

#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("The sum of %d and %d is %d\n", num1, num2, sum);
return 0;
}

[5]
OUTPUT:-

[6]
Q4. Write a program to input a number and print its
square and cube.

#include <stdio.h>
int main() {
int num, square, cube;
printf("Enter a number: ");
scanf("%d", &num);
square = num * num;
cube = num * num * num;
printf("The square of %d is %d\n", num, square);
printf("The cube of %d is %d\n", num, cube);
return 0;
}

[7]
OUTPUT :-

[8]
Q5. Write a program to input base and height of triangle
and print area of triangle .

#include <stdio.h>
int main() {
float base, height, area;
printf("Enter the base of the triangle: ");
scanf("%f", &base);
printf("Enter the height of the triangle: ");
scanf("%f", &height);
area = 0.5 * base * height;
printf("The area of the triangle is: %f", area);
return 0;
}

[9]
OUTPUT :-

[10]
Q6. Write a program to input a number and check it is
even or odd number.

#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

if (num % 2 == 0) {
printf("%d is an even number.\n", num);
}
else {
printf("%d is an odd number.\n", num);
}

return 0;
}

[11]
OUTPUT :-

[12]
Q7. Write a program to input a number and check it is
positive or negative or zero.

#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if (num > 0) {
printf("%d is a positive number.\n", num);
}
else if (num < 0) {
printf("%d is a negative number.\n", num);
}
else {
printf("The number is zero.\n");
}
return 0;
}

[13]
OUTPUT :-

positive number :-

negative number :-

zero number :-

[14]
Q8. Write a program to input three-digit numbers and
print the sum of its digit.

#include <stdio.h>
int main() {
int num, digit1, digit2, digit3, sum;
printf("Enter a three-digit number: ");
scanf("%d", &num);
digit1 = num / 100;
digit2 = (num / 10) % 10;
digit3 = num % 10;
sum = digit1 + digit2 + digit3;
printf("The sum of the digits is %d.\n", sum);
return 0;
}

[15]
OUTPUT :-

[16]
Q9. Write a program to input three digit numbers and
print the reverse of its digit.

#include <stdio.h>
int main() {
int num, digit1, digit2, digit3, reverse;
printf("Enter a three-digit number: ");
scanf("%d", &num);
digit1 = num / 100;
digit2 = (num / 10) % 10;
digit3 = num % 10;
reverse = digit3 * 100 + digit2 * 10 + digit1;
printf("The reverse of the digits is %d.\n", reverse);
return 0;
}

[17]
OUTPUT :-

[18]
Q10. Write a program to input three-digit number and
check it is a palindrome number or not.

#include <stdio.h>
int main() {
int num, digit1, digit2, digit3, reverse;
printf("Enter a three-digit number: ");
scanf("%d", &num);
digit1 = num / 100;
digit2 = (num / 10) % 10;
digit3 = num % 10;
reverse = digit3 * 100 + digit2 * 10 + digit1;
if (num == reverse) {
printf("%d is a palindrome number.\n", num);
} else {
printf("%d is not a palindrome number.\n", num);
}
return 0;
}

[19]
OUTPUT :-

[20]
Q11. Write a program to input three-digit number and
check that is Armstrong number or not.

#include <stdio.h>
int main() {
int num, digit1, digit2, digit3, sum;
printf("Enter a three-digit number: ");
scanf("%d", &num);
digit1 = num / 100;
digit2 = (num / 10) % 10;
digit3 = num % 10;
sum = (digit1*digit1*digit1) + (digit2*digit2*digit2) +
(digit3*digit3*digit3);
if (num == sum) {
printf("%d is an Armstrong number.\n", num);
} else {
printf("%d is not an Armstrong number.\n", num);
}
return 0;
}

[21]
OUTPUT :-

[22]
Q12. Write a program to input two number and check
which one is larger.

#include <stdio.h>
int main() {
int num1, num2;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
if (num1 > num2) {
printf("%d is larger than %d.\n", num1, num2);
} else if (num1 < num2) {
printf("%d is larger than %d.\n", num2, num1);
} else {
printf("Both numbers are equal.\n");
}
return 0;
}

[23]
OUTPUT :-

[24]
Q13. Write a program to input radius of circle and print
area of a circle.

#include <stdio.h>
#define PI 3.14159
int main() {
float radius, area;
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
area = PI * radius * radius;
printf("The area of the circle is %0.2f\n", area);
return 0;
}

[25]
OUTPUT :-

[26]
Q14. Write a program to input length and breadth of
rectangle and print area of rectangle.

#include <stdio.h>
int main() {
float length, breadth, area;
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
printf("Enter the breadth of the rectangle: ");
scanf("%f", &breadth);
area = length * breadth;
printf("The area of the rectangle is %0.0f\n", area);
return 0;
}

[27]
OUTPUT :-

[28]
Q15. Write a program to input three sides of triangle and
print perimeter of triangle.

#include <stdio.h>
int main() {
float side1, side2, side3, perimeter;
printf("Enter the length of side 1: ");
scanf("%f", &side1);
printf("Enter the length of side 2: ");
scanf("%f", &side2);
printf("Enter the length of side 3: ");
scanf("%f", &side3);
perimeter = side1 + side2 + side3;
printf("The perimeter of the triangle is %0.0f\n", perimeter);
return 0;
}

[29]
OUTPUT :-

[30]
Q16. Write a program to input temperature in Celsius and
print the temperature in Fahrenheit.

#include <stdio.h>
int main() {
float celsius, fahrenheit;
printf("Enter the temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9/5) + 32;
printf("The temperature in Fahrenheit is %0.2f degrees\n",
fahrenheit);
return 0;
}

[31]
OUTPUT :-

[32]
Q17. Write a program to input temperature in Fahrenheit
and print the temperature in Celsius.

#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("Enter the temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5/9;
printf("The temperature in Celsius is %0.2f degrees\n", celsius);
return 0;
}

[33]
OUTPUT :-

[34]
Q18. Write a program to input the marks of student in five
subjects out of hundred and print the total percent of
student.

#include <stdio.h>
int main() {
int marks[5];
float total_marks = 0, percentage;
printf("Enter marks of five subjects out of 100:\n");
printf("Maths: ");
scanf("%d", &marks[0]);
printf("Science: ");
scanf("%d", &marks[1]);
printf("English: ");
scanf("%d", &marks[2]);
printf("Social Studies: ");
scanf("%d", &marks[3]);
printf("Computer Science: ");
scanf("%d", &marks[4]);
for (int i = 0; i < 5; i++) {
total_marks += marks[i];
}
percentage = (total_marks / 500) * 100;
[35]
printf("\nTotal percentage: %.2f%%\n", percentage);
return 0;
}

OUTPUT :-

[36]
Q19. Write a program to input number and print its table.

#include <stdio.h>
int main() {
int num, i, res;
printf("Enter a number: ");
scanf("%d", &num);
printf("Multiplication table of %d:\n", num);
for (i = 1; i <= 10; i++) {
res = num * i;
printf("%d x %d = %d\n", num, i, res);
}

return 0;
}

[37]
OUTPUT :-

[38]
Q20. Write a program to input age of the user and check
his age with age group and print the remark.

#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 0 && age <= 12) {
printf("You are a child\n");
} else if (age >= 13 && age <= 19) {
printf("You are a teenager\n");
} else if (age >= 20 && age <= 59) {
printf("You are an adult\n");
} else if (age >= 60 && age <= 100) {
printf("You are a senior citizen\n");
} else {
printf("Invalid age entered\n");
}
return 0;
}

[39]
OUTPUT :-

[40]
Q21. Write a program to input age of the user and check
his age with age group and print the remark using Nested-
if .

#include <stdio.h>
int main() {
int age;
printf("Please enter your age: ");
scanf("%d", &age);
if (age < 0) {
printf("Invalid age entered.\n");
}
else if (age < 18) {
printf("You are in the age group of 0-17. You are a minor.\n");
}
else if (age < 65) {
printf("You are in the age group of 18-64. You are an adult.\n");
}
else {
printf("You are in the age group of 65 and above. You are a
senior citizen.\n");
}
return 0;

[41]
}

OUTPUT :-

[42]
Q22. Write a program to any digit number and check how
many digits it can contain.

#include <stdio.h>
int main() {
int num, count = 0;
printf("Please enter a number: ");
scanf("%d", &num);
while (num != 0) {
num /= 10;
++count;
}
printf("The number you entered contains %d digits.\n", count);
return 0;
}

[43]
OUTPUT :-

[44]
Q23. Write a program to input a number and print its
factorial.

#include <stdio.h>
int main() {
int num, fact = 1, i;
printf("Please enter a number: ");
scanf("%d", &num);
for (i = 1; i <= num; ++i) {
fact *= i;
}
printf("The factorial of %d is %d.\n", num, fact);
return 0;
}

[45]
OUTPUT :-

[46]
Q24. Write a program to input one side of a square and
print the peripheral of the square.

#include <stdio.h>
int main() {
float side, perimeter;
printf("Enter the length of one side of the square: ");
scanf("%f", &side);
perimeter = 4 * side;
printf("Perimeter of the square is: %f", perimeter);
return 0;
}

[47]
OUTPUT :-

[48]
Q25. Write a program to input a number and check it is a
prime number or not.

#include <stdio.h>
int main() {
int num, i, flag = 0;
printf("Please enter a number: ");
scanf("%d", &num);
for (i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
flag = 1;
break;
}
}
if (num == 1) {
printf("%d is neither prime nor composite.\n", num);
}
else {
if (flag == 0) {
printf("%d is a prime number.\n", num);
}

[49]
else {
printf("%d is not a prime number.\n", num);
}
}
return 0;
}

[50]
OUTPUT :-

[51]
Q26. Write a program to Input two number and print all
the even number between them.

#include <stdio.h>
int main() {
int num1, num2, i;
printf("Please enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("The even numbers between %d and %d are: ", num1,
num2);
for (i = num1; i <= num2; ++i) {
if (i % 2 == 0) {
printf("%d ", i);
}
}
return 0;
}

[52]
OUTPUT :-

[53]
Q27. Write a program to input two number and print all
the odd number between them.

#include <stdio.h>
int main() {
int num1, num2, i;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("Odd numbers between %d and %d are: ", num1, num2);
for (i = num1; i <= num2; i++) {
if (i % 2 != 0) {
printf("%d ", i);
}
}
return 0;
}

[54]
OUTPUT :-

[55]
Q28. Write a program to input number of steps and print
the Fibonacci series.

#include <stdio.h>
int main() {
int n, i, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of steps: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i) {
printf("%d, ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
}
return 0;
}

[56]
OUTPUT :-

[57]
Q29 . Write a program a program to input side of square
and print the area of square.

#include <stdio.h>
int main() {
float side, area;
printf("Enter the length of a side of the square: ");
scanf("%f", &side);
area = side * side;
printf("The area of the square is: %.2f", area);
return 0;
}

[58]
OUTPUT :-

[59]
Q30. Write a program to input a number and print this
number in ‘n’ n number of rows and columns.

#include <stdio.h>
int main() {
int number, rows, cols;
printf("Enter a number: ");
scanf("%d", &number); // take input from user
printf("Enter the number of rows: ");
scanf("%d", &rows); // take number of rows as input
printf("Enter the number of columns: ");
scanf("%d", &cols); // take number of columns as input
// check if number of rows and columns are valid
if (rows * cols < number) {
printf("Error: Number of rows and columns are not enough to
print the number.");
}
else {
// initialize a 2D array of zeros
int arr[rows][cols];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
arr[i][j] = 0;
[60]
}
}
// fill the array with the digits of the number
char num_str[20];
sprintf(num_str, "%d", number);
int index = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (index < strlen(num_str)) {
arr[i][j] = num_str[index] - '0';
index++;
}
}
}
// print the array
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
printf("%d ", arr[i][j]);
}
printf("\n");
}
}

[61]
return 0;
}

[62]
OUTPUT :-

[63]
Q31. Write a program to input a number and print its
table using while loop .

#include <stdio.h>
int main() {
int num, i = 1;
printf("Enter a number: ");
scanf("%d", &num);
printf("Table of %d:\n", num);
while (i <= 10) {
printf("%d x %d = %d\n", num, i, num * i);
i++;
}
return 0;
}

[64]
OUTPUT :-

[65]
Q32. Write a program to input any digit number and print
the sum of its digit using while loop.

#include <stdio.h>
int main() {
int num, sum = 0, rem;
printf("Enter a number: ");
scanf("%d", &num);
while (num > 0) {
rem = num % 10;
sum += rem;
num /= 10;
}
printf("Sum of digits: %d\n", sum);
return 0;
}

[66]
OUTPUT :-

[67]
Q33. Write a program to input 'n' number of rows and
print the following pattern.
*
**
***

#include <stdio.h>
int main() {
int n, i, j;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

[68]
OUTPUT :-

[69]
Q34. Write a program to input 'n number of rows and
print the following pattern :
* * * *
* * *
* *
*

#include <stdio.h>
int main() {
int n, i, j;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i = n; i >= 1; i--) {
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

[70]
OUTPUT :-

[71]
Q35. Write a program to input N number of rows and
print the following pattern
1
22
3 3 two
#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (i == j || j == 2) {
printf("%d ", i);
} else {
printf("2 ");
}
}
printf("\n");
}
return 0;
}

[72]
OUTPUT :-

[73]
Q36. Write a program to input N number of rows and
print the following pattern
1
12
123

#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}

[74]
OUTPUT :-

[75]
Q37. Write a program to input N number of rows and
print the following pattern
A
AB
ABC

#include <stdio.h>
int main() {
int n, i, j;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j <= i; j++) {
printf("%c ", 'A' + j);
}
printf("\n");
}
return 0;
}

[76]
OUTPUT :-

[77]
Q38. Write a program to input N number of rows and
print the following pattern
A
B B
C C C

#include <stdio.h>
int main() {
int n, i, j;
printf("Enter the number of rows: ");
scanf("%d", &n);
for(i=1; i<=n; i++) {
for(j=1; j<=i; j++) {
printf("%c ", i+64);
}
printf("\n");
}
return 0;
}

[78]
OUTPUT :-

[79]
Q39. Write a program to input in number of rows and
print pascal triangle.

#include <stdio.h>
int main() {
int numRows, i, j, coef = 1;
printf("Enter the number of rows: ");
scanf("%d", &numRows);
for (i = 0; i < numRows; i++) {
for (j = 0; j <= i; j++) {
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%d ", coef);
}
printf("\n");
}
return 0;
}

[80]
OUTPUT :-

[81]
Q40. Write a program to input N number of rows and
print the following pattern in c and get output result
screen
* * * * * *
* *
* *
* * * * * *

#include <stdio.h>
int main() {
int n;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 6; j++) {
if ((i == 1 || i == n) && (j >= 1 && j <= 6)) {
printf("* ");
} else if ((i > 1 && i < n) && (j == 1 || j == 6)) {
printf("* ");
} else {
printf(" ");
}

[82]
}
printf("\n");
}
return 0;
}

OUTPUT :-

[83]
Q41.Write a program to input character and cheek it is
vowel or not.

#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
printf("%c is a vowel.\n", c);
} else {
printf("%c is not a vowel.\n", c);
}
return 0;
}

[84]
OUTPUT :-

[85]
Q42. Write a program to input character and cheek it is
vowel or not by using switch case.

#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
switch (ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("%c is a vowel.\n", ch);
break;

[86]
default:
printf("%c is not a vowel.\n", ch);
break;
}
return 0;
}

OUTPUT :-

[87]
Q43. Write a program to input 3*3 Matrix and print its
original and transpose form.

#include <stdio.h>
int main() {
int matrix[3][3], transpose[3][3];
int i, j;
// Input the matrix
printf("Enter the 3x3 matrix:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Print the original matrix
printf("\nOriginal Matrix:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");

[88]
}
// Calculate the transpose of the matrix
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
transpose[i][j] = matrix[j][i];
}
}
// Print the transpose of the matrix
printf("\nTranspose of Matrix:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}

[89]
OUTPUT :-

[90]
Q44. Write a program to input 3*3 matrix and print its
product.

#include <stdio.h>
int main() {
int matrix1[3][3], matrix2[3][3], result[3][3];
int i, j, k;
// Input the first matrix
printf("Enter the first 3x3 matrix:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
scanf("%d", &matrix1[i][j]);
}
}
// Input the second matrix
printf("\nEnter the second 3x3 matrix:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
scanf("%d", &matrix2[i][j]);
}
}

[91]
// Calculate the product of the two matrices
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
result[i][j] = 0;
for(k=0; k<3; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}
// Print the product of the matrices
printf("\nProduct of the two matrices:\n");
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}
return 0;
}

[92]
OUTPUT :-

[93]
Q45. Write a program to input 10 numbers into array and
print them in reverse order.

#include <stdio.h>
int main() {
int arr[10];
int i;
// Prompt the user to enter 10 numbers
printf("Enter 10 numbers:\n");
// Read the 10 numbers into the array
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Print the numbers in reverse order
printf("The numbers in reverse order are:\n");
for (i = 9; i >= 0; i--) {
printf("%d ", arr[i]);
}
return 0;
}

[94]
OUTPUT :-

[95]
Q46. Write a program to input 10 numbers and print the
largest number.

#include <stdio.h>
int main() {
int arr[10];
int i, max;
// Prompt the user to enter 10 numbers
printf("Enter 10 numbers:\n");
// Read the 10 numbers into the array
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Find the maximum number in the array
max = arr[0];
for (i = 1; i < 10; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
// Print the maximum number

[96]
printf("The largest number is: %d\n", max);
return 0;
}

OUTPUT :-

[97]
Q47. Write a program to input 10 numbers and print the
smallest number.
#include <stdio.h>
int main() {
int arr[10];
int i, min;
// Prompt the user to enter 10 numbers
printf("Enter 10 numbers:\n");
// Read the 10 numbers into the array
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Find the minimum number in the array
min = arr[0];
for (i = 1; i < 10; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
// Print the minimum number
printf("The smallest number is: %d\n", min);
return 0;}

[98]
OUTPUT :-

[99]
Q48. Write a program to input two numbers and print
their addition subtraction multiplication and division.

#include <stdio.h>
int main() {
float num1, num2;
printf("Enter two numbers: ");
scanf("%f %f", &num1, &num2);
printf("Addition: %.2f\n", num1 + num2);
printf("Subtraction: %.2f\n", num1 - num2);
printf("Multiplication: %.2f\n", num1 * num2);
printf("Division: %.2f\n", num1 / num2);
return 0;
}

[100]
OUTPUT :-

[101]
Q49. Write a program to input one side of a square and
print area of the square.

#include <stdio.h>
int main() {
float side, area;
printf("Enter the length of one side of the square: ");
scanf("%f", &side);
area = side * side;
printf("Area of the square is: %f", area);
return 0;
}

[102]
OUTPUT :-

[103]
Q50. Write a program to input one side of a square and
print the peripheral of the square.

#include <stdio.h>
int main() {
float side, perimeter;
printf("Enter the length of one side of the square: ");
scanf("%f", &side);
perimeter = 4 * side;
printf("Perimeter of the square is: %f", perimeter);
return 0;
}

[104]
OUTPUT :-

[105]

You might also like