/* Converts distance in miles to kilometers. */
#include <stdio.h> /* printf, scanf definitions */
#define KMS_PER_MILE 1.609 /* conversion constant*/
int main(void)
{
double miles, /* input - distance in miles. */
kms; /* output - distance in kilometers */
/* Get the distance in miles. */
printf("Enter the distance in miles> ");
scanf("%lf", &miles);
/* Convert the distance to kilometers. */
kms = KMS_PER_MILE * miles;
/* Display the distance in kilometers. */
printf("That equals %f kilometers.\n", kms);
return (0);
}
/* Calculates circumference and area of circle */
#include <stdio.h> /* printf, scanf definitions */
#define PI 3.14 /* conversion constant */
void main()
{
double radius; //input
double circum; //output
double area; //output
/* Get the radius */
printf("Enter the radius> ");
scanf("%lf", &radius);
/* Calculate the circumference */
circum = PI * radius * 2;
/* Calculate the area*/
area = PI * radius * radius;
/* Display the circimference */
printf("Circumference is %.4f \n", circum);
/* Display the area */
printf("Area is %.4f \n" , area);
}
/* Calculates sum, difference, product and quotient of two integer */
#include <stdio.h>
void main()
{
int x; //input
int y; //input
int result; //output
/* Get the first integer */
printf("Please enter the first integer:");
scanf("%d", &x);
/* Get the second integer */
printf("Please enter the second integer:");
scanf("%d", &y);
/*Display the sum*/
printf("%d+%d=%d\n", x,y,result=x+y);
/*Display the difference*/
printf("%d-%d=%d\n", x,y,result=x-y);
/*Display the product*/
printf("%d*%d=%d\n", x,y,result=x*y);
/*Display the quotient*/
printf("%d/%d=%d\n", x,y,result=x/y);
}
/* Displays some values */
#include <stdio.h> /* printf, scanf definitions */
void main()
{
char char1; //input
int int1; //input
double double1; //input
char char2='?'; //output
int int2=-34; //output
/* Get a character */
printf("Please enter a character:");
scanf("%c", &char1);
/* Get a integer */
printf("Please enter a integer:");
scanf("%d", &int1);
/* Get a double */
printf("Please enter a double:");
scanf("%lf", &double1);
/*Display the values*/
printf("%c %d %.2lf %c %d\n", char1, int1, double1, char2, int2);
}
Etiketler: C, CSE, programlama, programlama dili