0% found this document useful (0 votes)
11 views7 pages

C Programs

The document contains a series of C programs that perform various tasks including calculating the area of a triangle and a circle, computing student details, swapping numbers, and calculating gross and net salary. Each program includes user input prompts and outputs the results accordingly. The programs demonstrate basic C programming concepts such as variables, arithmetic operations, and control structures.

Uploaded by

talhax1679
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)
11 views7 pages

C Programs

The document contains a series of C programs that perform various tasks including calculating the area of a triangle and a circle, computing student details, swapping numbers, and calculating gross and net salary. Each program includes user input prompts and outputs the results accordingly. The programs demonstrate basic C programming concepts such as variables, arithmetic operations, and control structures.

Uploaded by

talhax1679
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/ 7

C Programs for Different Tasks

===============================

Q2: Area of Triangle

---------------------

#include <stdio.h>

int main() {

float base, height, area;

printf("Enter base of the triangle: ");

scanf("%f", &base);

printf("Enter height of the triangle: ");

scanf("%f", &height);

area = (base * height) / 2;

printf("Area of Triangle: %.2f\n", area);

return 0;

Q3: Area of Circle

---------------------

#include <stdio.h>

#define PI 3.14159

int main() {

float radius, area;

printf("Enter radius of the circle: ");

scanf("%f", &radius);
area = PI * radius * radius;

printf("Area of Circle: %.2f\n", area);

return 0;

Q4: Calculate value1

---------------------

#include <stdio.h>

int main() {

float total, value2, value1;

printf("Enter total: ");

scanf("%f", &total);

printf("Enter value2: ");

scanf("%f", &value2);

value1 = total - value2;

printf("Value1: %.2f\n", value1);

return 0;

Q5: Student Details - Total and Average

----------------------------------------

#include <stdio.h>

int main() {

int roll_no, marks[5], total = 0;

char name[50];

float average;
printf("Enter Roll No: ");

scanf("%d", &roll_no);

printf("Enter Name: ");

scanf("%s", name);

printf("Enter 5 subject marks: ");

for (int i = 0; i < 5; i++) {

scanf("%d", &marks[i]);

total += marks[i];

average = total / 5.0;

printf("Total Marks: %d\n", total);

printf("Average Marks: %.2f\n", average);

return 0;

Q6: Employee Details

----------------------

#include <stdio.h>

int main() {

int emp_id;

char name[50], department[50];

float salary;

printf("Enter Employee ID: ");

scanf("%d", &emp_id);

printf("Enter Employee Name: ");

scanf("%s", name);
printf("Enter Employee Salary: ");

scanf("%f", &salary);

printf("Enter Employee Department: ");

scanf("%s", department);

printf("\nEmployee Details:\n");

printf("ID: %d\nName: %s\nSalary: %.2f\nDepartment: %s\n", emp_id, name, salary, department);

return 0;

Q7: Cube and Square

----------------------

#include <stdio.h>

int main() {

int num, cube, square;

printf("Enter a number: ");

scanf("%d", &num);

square = num * num;

cube = num * num * num;

printf("Square: %d\n", square);

printf("Cube: %d\n", cube);

return 0;

Q8: Swap without 3rd variable

-------------------------------

#include <stdio.h>
int main() {

int a, b;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

a = a + b;

b = a - b;

a = a - b;

printf("After swapping: a = %d, b = %d\n", a, b);

return 0;

Q9: Swap using 3rd variable

-----------------------------

#include <stdio.h>

int main() {

int a, b, temp;

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

temp = a;

a = b;

b = temp;

printf("After swapping: a = %d, b = %d\n", a, b);

return 0;

Q10: Gross and Net Salary Calculation


--------------------------------------

#include <stdio.h>

int main() {

float basic_salary, hra, ta, da, gross_salary, tax, net_salary;

printf("Enter basic salary: ");

scanf("%f", &basic_salary);

hra = 0.10 * basic_salary;

ta = 0.05 * basic_salary;

da = 0.08 * basic_salary;

gross_salary = basic_salary + hra + ta + da;

tax = 0.10 * gross_salary;

net_salary = gross_salary - tax;

printf("Gross Salary: %.2f\n", gross_salary);

printf("Tax: %.2f\n", tax);

printf("Net Salary: %.2f\n", net_salary);

return 0;

Q11: Division of two numbers

------------------------------

#include <stdio.h>

int main() {

float num1, num2, result;

printf("Enter two numbers: ");

scanf("%f %f", &num1, &num2);

if (num2 == 0) {
printf("Division by zero is not possible!\n");

} else {

result = num1 / num2;

printf("Result of division: %.2f\n", result);

return 0;

You might also like