Place Your Query
C Programming
- Control flow-based C Programs
- Enjoy Conditional Programming in C using If...else and switch statement.
- Good, Now write a C program to display "Hello World" on the screen.
- Write a C program to display Your Name, Address and City in different lines.
- C program to find sum of n numbers
- Write a C program For Addition of two numbers using Function.
- Write a Program to Find Simple Interest and Compound Interest.
- Write a Program to Convert Celsius To Fahrenheit and Vice Versa.
- Write a Program to Find Area and Perimeter of Circle, Triangle, Rectangle and Square.
- Write a Program to Swap Two Numbers Using Temporary Variables and Without Using Temporary Variables
- Write a C Program to Design a Simple Menu Driven Calculator
- Simple Expression Based C Programs
- 7. Components of C language
- 1. Introduction to C Programming Language
- 10. Operator Precedence and Associativity
- 11. Comments in C Programming
- 14. Fundamental Control Structure Statements in C [Part-1]
- 15. Fundamental Control Structure Statements in C [Part-2]
- 16. Looping Statements [Fundamental Control Structure Statements in C. #Part-3]
- 17. Keyword break, continue, return and exit [Fundamental Control Structure Statements in C. #Part-4]
- 2. Computer Languages
- 3. Interpreters vs Compilers vs Assemblers in programming languages
- 4. C Program Structure
- 5. Compile and Execute C Program
- 6. Errors in C Program
- 8. C Datatypes
- 9. Operators in C
- Control flow-based C Programs
- Demystifying Bit Masking: Unlocking the Power of Bitwise Operators in C-Language with best Examples.
- 18. Fundamentals of C Functions
- Show Remaining Articles (3)Collapse Articles
Java
AI ML
FAQs
- A Program to find Tokens in C code?
- What are the Common Coding Mistakes.
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner to Pro Part-3 (String Functions)
Python Interview Questions
- Easy Learning, Python QAs for Beginner’s to Pro Part-1
- Easy Learning, Python QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-1
- Easy Learning, Python Strings QAs for Beginner’s to Pro Part-2
- Easy Learning, Python Strings QAs for Beginner to Pro Part-3 (String Functions)
Simple Expression Based C Programs
- C expressions are a combination of operators, constants, and variables.
- The simple expressions based c programs are used to compute values, assign values, and test conditions.
- An expression can perform operations like addition, subtraction, comparison, or logical operations, returning a value.
- For example, the expression
2 + 3
computes the sum of 2 and 3. - Expressions can be simple or complex, involving multiple operators and operands.
- The evaluation of expressions follows the precedence of operators, which is defined by the C standard.
Program-1: Write a simple program in C to calculate the percentage of student marks for five subjects.
Aim
Write a simple program in C to calculate the percentage of student marks for five subjects.
Procedure/ Algorithm
- Step 1: Include the standard I/O library to enable input and output operations.
- Step 2: Define the main function where the program execution begins.
Step 3: Declare integer variables to store marks of five subjects like m1, m2, m3, m4, m5; - Step 4: Prompt the user to enter marks for five subjects out of 100.
Step 5: Read the marks for five subjects from the user. - Step 6: Calculate the average of the marks entered.
Step 7: Display the average marks. - Step 8: Terminate the program.
Code: Calculating average of (given) five subject marks
//WAP in C to calculate the percentage of student marks for five subjects.
#include<stdio.h>
int main()
{
int m1,m2,m3,m4,m5;
printf("\n five sub marks of a student n 100\n ");
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
float avg= (m1+m2+m3+m4+m5)/5;
printf("\n average marks = %f",avg);
return 0;
}// end main
Output
five sub marks of a student n 100
78
98
89
90
76
average marks = 86.000000
--------------------------------
Process exited after 18.25 seconds with return value 27
Press any key to continue . . .
Run Directly on in-built C-Compiler
While using in-built C-Compiler Use Gear icon for custom Input (i.e. whenever you have to give values to read)
Program-2: Write a program in C to convert temperature in Celsius to Fahrenheit.
Aim
Write a program in C to convert temperature in Celsius to Fahrenheit
- Step 1: Include the standard I/O library to enable input and output operations.
- Step 2: Define the main function where the program execution begins.
Step 3: Declare integer variables to store temperature in Celsius as cl and Fahrenheit as fl. - Step 4: Prompt the user to enter temperature in Celsius.
Step 5: Read the temp in Celsius to cl. - Step 6: Calculate the fl using formula { (°F) = (C x 9/5) + 32 }
Step 7: Display the Temperature in Fahrenheit. - Step 8: Terminate the program.
Code
//WAP in C to convert temperature in Celsius
//to Fahrenheit. { (°F) = (C x 9/5) + 32 }
#include<stdio.h>
int main()
{
float cl, fr;
printf("\n enter temp in celsius : ");
scanf("%f", &cl);
fr= (cl*9/5) +32;
printf("\n temp in Fahrenheit is =%f", fr);
return 0;
}// end main
Output
Output:
enter temp in celsius : 37
temp in Fahrenheit is =98.599998
--------------------------------
Process exited after 4.104 seconds with return value 0
Press any key to continue . . .
Run Directly on in-built C-Compiler
While using in-built C-Compiler Use Gear icon for custom Input (i.e. whenever you have to give values to read)
Program-3: Write a simple C program to calculate the area of the triangle.
Aim
Write a simple C program to calculate the area of the triangle.
Procedure/ Algorithm
- Step 1: Include the standard I/O library to enable input and output operations.
- Step 2: Define the main function where the program execution begins.
Step 3: Declare integer variables to store height as hg, breadth as bh and area as ar; - Step 4: Prompt the user to enter height and breadth of a triangle.
Step 5: Read the height and breadth of a triangle to variables hg and bh respectively - Step 6: Calculate the area using formula { ar=(hg*bh)/2; }
Step 7: Display the area. - Step 8: Terminate the program.
Code
//WAP in C to calculate the area of the triangle
#include<stdio.h>
int main()
{
float ar, hg,bh;
printf("\nEnter height and breadth \n");
scanf("%f", &hg); //at begineer level it is always good to read one variable at a time.
scanf("%f", &bh);
ar=(hg*bh)/2;
printf("\n area of triangle = %f", ar);
return 0;
}// end main
Output
Output:
Enter height and breadth
30
120
area of triangle = 1800.000000
--------------------------------
Process exited after 11.23 seconds with return value 32
Press any key to continue . . .
Run Directly on in-built C-Compiler
While using in-built C-Compiler Use Gear icon for custom Input (i.e. whenever you have to give values to read)
Conclusion
Thus, the above simple expression based c program serves the purpose by accepting the marks of five subjects and then give the desired output in terms of average of marks of given five subjects and similarly converting the temperature from Celsius to Fahrenheit and calculating area of a tringle for given sides.
So finally, we can say that this C program provides a simple and effective way to calculate the average of five marks. By understanding the concept of average and following the step-by-step code implementation, you can easily adapt this program to suit your specific needs. Whether you’re a beginner or an experienced programmer, this guide will empower you to harness the power of average calculation in your C programming endeavors.