Simple and basic C program code

Convert given value in Meter to centimeter.

#include <stdio.h>
int main (void)
{
float length;
printf("Enter Value for length in meter : ");
scanf("%f",&length);
printf("%.2fm equal to %.2fcm\n", length, length*100);
return 0;
} 







Calculate the volume of a cylinder. PI * r2 h

#include <stdio.h>
#define PI 3.1412
int main (void)
{
float radius, height, volume;

/* Get value for radius */
printf("Enter the radius : ");
scanf("%f",&radius);

/* Get the value for height in Cylinder */
printf("Enter the height : ");
scanf("%f", &height);

/* Calculate the Volume */
volume = PI * radius * radius * height;
printf("Volume of a cylinder %.2f\n", volume);
return 0;








Calculate average marks of 4 subjects which, entered separately.  

#include <stdio.h>
int main (void)
{
int sub1, sub2, sub3, sub4;
double average;
/* Get values */
printf("Enter the Subject 1 marks : ");
scanf("%i",&sub1);
printf("Enter the Subject 2 marks : ");
scanf("%i",&sub2);
printf("Enter the Subject 3 marks : ");
scanf("%i",&sub3);
printf("Enter the Subject 4 marks : ");
scanf("%i",&sub4);
/* Calculate the average */
average = (sub1 + sub2 + sub3 + sub4)/4.0;
printf("Average marks %.2f\n", average);
return 0;










Convert the given temperature in Celsius to Fahrenheit. T(°F) = T(°C) × 1.8 + 32

#include <stdio.h>

/*

Convert the given temperature in Celsius to Fahrenheit. 
T(°F) = T(°C) × 1.8 + 32

*/

int main (void)
{
float temp;
printf("Enter the temperature in Celsius : ");
scanf("%f", &temp);
printf("Temperature after converted to the Fahrenheit : %.2f\n", (temp * 1.8 + 32));
return 0;
}



Find the value of y using y = 3.5x+5 at x = 5.23

#include <stdio.h>

/*

Find the value of y using y = 3.5x+5 at x = 5.23

*/

int main (void)
{
float y, x = 5.23;
y = 3.5 * x + 5;
printf("Value of y = %f\n", y);
return 0;

Find the cost of 5 items if the unit price is 10.50 Rupees.

#include <stdio.h>

/*

Find the cost of 5 items if the unit price is 10.50 Rupees

*/

int main (void)
{
int items = 5;
float unitPrice = 10.5, total;
/* Calculate total */
total = items * unitPrice;
printf("Cost of % Items %.2f\n", total);
return 0;
} 

Enter the name, height, weight and gender of a person and calculate his/her BMI in Kg.

BMI = weight/ height2

#include <stdio.h>

/*

Enter the name, height, weight and gender of a person and calculate his/her BMI in Kg.
BMI = weight/ height2


*/

int main (void)
{
float weight, height, bmi;
char name[30], gender[30];
/* Get values for height, weight, gender and name */
printf("\nEnter your name here : ");
scanf("%s", &name);
printf("Gender : ");
scanf("%s", &gender);
printf("Enter your Height in cm : ");
scanf("%f", &height);
printf("Enter your Weight in Kg : ");
scanf("%f", &weight);
/* Calculate BMI value */
height/=100;
bmi = weight/(height * height);
printf("\nName : %s\nGender : %s\nBMI = %.3f\n", name, gender, bmi);
return 0;
}

A program that converts inches to centimeters.

#include <stdio.h>

/*

A program that converts inches to centimeters.

*/

int main (void)
{
float inches, cm;
/* Get the values */
printf("Inches     : ");
scanf("%f", &inches);
/* Convert inches to cm */
cm = inches * 2.54;
printf("Centimeter : %.3fcm\n", cm);
return 0;
}

The figure gives a rough sketch of a running track. It includes a rectangular shape and two semi-circles. The length of the rectangular part is 67m and breadth is 21m.Calculate the distance of the running track.


#include <stdio.h>
#define PI 3.1415

int main (void)
{
float distance;
distance = (67 * 2) + (PI * 21);
printf("Distance of the running track %.2fcm\n", distance);
return 0;
}

Comments

Popular posts from this blog

Programming Errors in C

printf() Function