This program calculates the area of a rectangle based on length and breadth entered by the user.
Variables:1. length : (Datatype int): to represent the length of the rectangle.
2. breadth : (Datatype int): to represent the breadth of the rectangle.
3. area : (Datatype long): to store the result of the area of the rectangle is 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 screen and %ld for long. \n is used to add a new line
scanf() : is used to fetch data inputted by the user on the console/screen using the keyboard. %d in scanf is indicated that inputted text is of type int and %ld for long.
Formula:Area of Rectangle: length x breadth
/*
* 1000+ C programs + tutorials
*
*
* 6_calculate_area_of_rectangle.c
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int length;
int breadth;
long area;
// clrscr();
printf(" Program to calculate Area of a Rectangle : \n\n");
printf(" Enter the Length of a Rectangle : ");
scanf("%d", &length);
printf("\n\n Enter the Breadth of a Rectangle : ");
scanf("%d", &breadth);
area = length*breadth;
printf("\n\n Area of Rectangle with Length as %d and Breadth as %d = %ld \n\n",length,breadth,area);
// getch();
}
Output:
Program to calculate Area of a Rectangle :
Enter the Length of a Rectangle: 20
Enter the Breadth of a Rectangle: 10
Area of Rectangle with Length as 20 and Breadth as 10 = 200
Without using variable area
/*
* 1000+ C programs + tutorials
*
*
* 6_calculate_area_of_rectangle.c
*
* Created on: Oct 20, 2014
* Author: Code2care.org
*/
#include <stdio.h>
//#include <conio.h>
void main() {
int length,breadth;
// clrscr();
printf(" Program to calculate Area of a Rectangle : \n\n");
printf(" Enter the Length of a Rectangle : ");
scanf("%d", &length);
printf("\n\n Enter the Breadth of a Rectangle : ");
scanf("%d", &breadth);
printf("\n\n Area of Rectangle with Length as %d and Breadth as %d = %ld
\n\n",length,breadth,length*breadth);
// 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 Cylinder
- Calculate Volume of Sphere
- Calculate Volume of Cube
- Calculate Volume of Ellipsoid
- Find Sum of two numbers
- Division between two numbers
- Calculate Area of Trapezoid
- Calculate Area of a Rectangle
- Calculate Volume of Pyramid
- Calculate Area of ellipse
- Find Difference of two numbers
- Calculate Volume of Cone
- Calculate Area of Square
- Calculate Area and Circumference of Circle
- Calculate Area of Parallelogram
- Force android app to run in Landscape mode programatically - Android
- Type R is already defined error : Android Error - Android
- Call PHP function on Button click using jquery ajax - PHP
- Can't Run SDK Manager find_java.bat issue - Android
- 10 FTP SFTP Clients and Alternatives - FTP
- auth_client_using_bad_version_title : Error Android Lint - Android
- Delete file using PHP code : unlink() - PHP
- Stop android adb service from command prompt or terminal - Android
- How to add Date and Time to Windows Notepad File - NotepadPlusPlus
- Mac OS X Taking Screen Capture using Terminal - Mac-OS-X
- Create SharePoint Site Collection using PowerShell New-SPSite - SharePoint
- SharePoint workflow Canceled - Coercion Failed: Unable to transform the input lookup data into the requested type - SharePoint
- Android : Prevent App for rotation landscape or portrait - Android
- MySQL 1005 Error : SQLSTATE: HY000 (ER_CANT_CREATE_TABLE) Message: Can't create table '%s' (errno: 150) - MySQL
- How to change Android EditText Cursor Color - Android