This C Program calculates Area of a Square based on the side of Square entered by the user.
Variables:1. side: (Datatype int) : to represent the side of square.
2. area: (Datatype int) : to store the result of the area of the square being computed.
Functions:printf() : is used to display something on the console/screen. Format specifier %d in printf function is used to display a int variable on scree. \n is used to add a newline
scanf() : is used to fetch data inputted by the user on the console/screen using keyboard. %d in scanf is indicates that inputted text is of type int.
Formula:Area of Square : (side)2
/*
* 1000+ C programs + tutorials
*
*
* 5_calculate_area_of_square.c
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int side;
int area;
// clrscr();
printf("Program to calculate Area of a Square : \n\n");
printf("Enter the side of a square : ");
scanf("%d", &side);
area = side*side;
printf("\n\nArea of square with side %d = %ld \n\n",side,area);
// getch();
}
Output:
Program to calculate Area of a Square :
Enter the side of a square: 20
Area of a square with side 20 = 400
Without using the variable area
/*
* 1000+ C programs + tutorials
*
*
* 5_calculate_area_of_square.c
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int side;
// clrscr();
printf("Program to calculate Area of a Square : \n\n");
printf("Enter the side of a square : ");
scanf("%d", &side);
printf("\n\nArea of square with side %d = %ld \n\n",side,side*side);
// getch();
}
The best way to learn C programming is to practice more and more programs. Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.
BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.
- Calculate Volume of Sphere
- Find Sum of two numbers
- Calculate Area of Parallelogram
- Calculate Area and Circumference of Circle
- Calculate Area of Square
- Calculate Volume of Pyramid
- Division between two numbers
- Calculate Volume of Cylinder
- Calculate Volume of Cube
- Calculate Volume of Ellipsoid
- Find Difference of two numbers
- Calculate Area of Trapezoid
- Calculate Area of ellipse
- Calculate Volume of Cone
- Calculate Area of a Rectangle
- Create S3 bucket using AWS CLI Command mb - AWS
- How to resolve Certificate Expired WhatsApp Error - WhatsApp
- [fix] Java Spring Boot JPA SQLSyntaxErrorException: Encountered user at line 1 column 14 - Java
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error - Java
- How to Update Device Drivers on Windows 10/11 Manually - Windows
- Location of eclipse.ini file on Mac OS X - Mac-OS-X
- hibernate.cfg.xml Configuration and Mapping xml Example - Java
- How to delete SNS Topic using AWS CLI - AWS