Introduction
Readable code is easier to understand and fix. It helps you and others work better together.
Readable code is easier to understand and fix. It helps you and others work better together.
/* Use clear variable names */ int totalScore; /* Add comments to explain tricky parts */ // Calculate average score float average = (float)totalScore / count; /* Use consistent indentation and spacing */ if (average > 50) { printf("Passed\n"); } else { printf("Failed\n"); }
age instead of a to make the purpose clear.int a; // bad name int age; // good name
// Calculate area of circle float area = 3.14 * radius * radius;
if(score>60){printf("Pass");}else{printf("Fail");} // Better formatting: if (score > 60) { printf("Pass\n"); } else { printf("Fail\n"); }
This program uses clear variable names, comments, and good formatting to make it easy to read.
#include <stdio.h> int main() { int score = 75; // Student's score // Check if the student passed if (score >= 60) { printf("Passed\n"); } else { printf("Failed\n"); } return 0; }
Keep lines short to avoid scrolling sideways.
Use blank lines to separate different parts of code.
Review your code by reading it out loud to check clarity.
Use clear names and comments to explain your code.
Keep formatting consistent with spaces and indentation.
Readable code saves time and helps teamwork.
int main() {
int a = 5, b = 10;
int sum = a + b;
printf("Sum is %d\n", sum);
return 0;
}int main(){int x=10;int y=20;if(x>y){printf("x is greater\n");}else{printf("y is greater\n");}return 0;}float area(float w, float h){return w*h;}Pass the test and this pattern moves unknown