0% found this document useful (0 votes)
19 views4 pages

#Include : Int Char

notes

Uploaded by

bharati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

#Include : Int Char

notes

Uploaded by

bharati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Write a C program to accept temperatures in Fahrenheit (F) and print it in


Celsius(C) and
Kelvin (K).

Ans:- #include<stdio.h>

void main()

float fahrenheit,convert;

printf("\nEnter temperature in fahrenheit:");

scanf("%f",&fahrenheit);

convert=(fahrenheit - 32) * 5/9; // Formula C=5.0/9(F-32)

printf("\nTemperature in celsius: %f",convert);

2. Write a c program Accept a character from the user and display its ASCII
value.

Ans:- #include <stdio.h>


int main()
{
char ch; // variable declaration
printf("Enter a character");
scanf("%c",&ch); // user input
printf("\n The ascii value of the ch variable is : %d", ch);
return 0;
}

3. Write a C program accept dimensions of a cylinder and print the surface area
and volume.
Ans:- #include<stdio.h>
void main()
{
float r,h,v,A; //declare variables r=radius, h=height , v=volume , A=area
float p=3.14;
//accepting radius(r) and height(h)
printf("\nEnter Value of radius:");
scanf("%f",&r);
printf("\nEnter Value of height:");
scanf("%f",&h);
A=(2*p*r*h)+(2*p*r*r); //formula of surface area of cylinder
v=p*r*r*h; //formula of volume of cylinder
printf("Surface Area of Cylinder :- %f ",A);
printf("Volume of Cylinder :- %f ",v);
}

4. Write a c program accept initial velocity (u), acceleration (a) and time (t).
Print the final velocity (v) andthe distance.
Ans:- #include<stdio.h>
void main()
{
int sec;
float distance , initial_velocity,velocity, acceleration;
printf("Enter the time in seconds \n");
scanf("%d",&sec);
printf("Enter the initial velocity \n");
scanf("%f", &initial_velocity);
printf("Enter the acceleration \n");
scanf("%f", &acceleration);
velocity = (initial_velocity + (acceleration * sec));
distance = (initial_velocity + (acceleration * (sec*sec)));\
printf("Total velocity is %f",velocity);
printf("Total distance travelled is %f", distance);

5. write a c program to calculate area and perimeter of rectangle.


Ans:- #include<stdio.h>

int main()
{
/* Declaring variables */
float length, breadth, area, perimeter;

/* Reading length and breadth from user */


printf("Enter length of the rectangle = ");
scanf("%f", &length);
printf("Enter breadth of the rectangle = ");
scanf("%f", &breadth);

/* Calculating area and perimeter */


area = length * breadth;
perimeter = 2 * (length * breadth);

/* Displaying result */
printf("Area of rectangle = %f", area);
printf("\nPerimeter of rectangle = %f", perimeter);

return 0;
}

6. write a c program to Accept inner and outer radius of a ring and print the
perimeter.
Ans:- #include <stdio.h>
int main()
{
float out_radius,in_radius,area, perimeter;
printf("Enter inner radius of ring:\n ");
scanf("%f",&in_radius);
printf("Enter outer radius of ring:\n ");
scanf("%f",&out_radius);
perimeter= (2 * 3.14) * (in_radius + out_radius);
area= 3.14 * ((in_radius * in_radius) + (out_radius * out_radius));
printf("Area of circle: %f \nPerimeter of circle: %f\n",area,perimeter);
}

7. Write a c program accept two numbers and print arithmetic and harmonic
mean of the two numbers
Sol:- #include<stdio.h>
void main()
{
int a,b;
float AM, HM; // AM=Arithmetic Mean , HM=Harmonic Mean

//Accept 2 numbers
printf("Enter the 1st number: ");
scanf("%d",&a);
printf("Enter the 2nd number: ");
scanf("%d",&b);

AM=((a+b))/2; // Formula AM= (a+b)/2


HM=a*b/((a+b)); // Formula HM = ab/(a+b)

//To display Arithmetic Mean & Harmonic Mean


printf("Arithmetic Mean is: %f",AM);
printf("\nHarmonic Mean is: %f",HM);

You might also like