-->

Lab work one(input and output)

 Questions are:

  1. Find out square root of a number using C Program.
  2. Write a program to calculate volume of a cube where volume v=l3.
  3. Write a program to display area and perimeter of a rectangle.
  4. Write a program to calculate distance using s=ut+1/2at2.
  5. Write a program to calculate area and circumference of a circle.
  6. Write a program to convert temperature in centigrade (C) into Fahrenheit (F). Hint : f=1.8c+32
  7. Write a program to calculate sum of two distances and the distance is measured in terms of feet and inch.
  8. Write a program to enter number of days and convert to into years , months and days.
  9. complete the following program and discuss the outputs.
program 1 program 2
      -------------------------------------------------------
  1. float x; float x;

    int x1=7; int x1=7;

    int x2=2; int x2=2;

    x=(float)x1/x2; x=(float)(x1/x2);

    printf("%f",x); printf("%f",x);

10)complete the following program and discuss the outputs.

program 1 program 2

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

int j; int j;

int i=5; int i=5; ; j=++i; j=i++;

printf("i=%d,j=%d",i,j); printf("i=%d,j=%d",i,j);

Ans:
  1. Find out the square root of a number using the C program.

ANSWER: 

Algorithm to find square root of a number

Step1: Start

Step 2: Input  number as n

Step 3: Use sqrt function to find square root and store it in a

Step 4: Display a

Step 5: Stop


C Code to find square root of a number

/*C Code to find square root of a number*/

#include<stdio.h>

#include<math.h>

int main()

{

int n,a;

printf("Enter a number : ");

scanf("%d",&n);

a=sqrt(n);

printf("Square root of %d is %d",n,a);

return 0;

}


  1. Write a program in C to calculate the volume of a cube where volume v=l3.

ANSWER: 

Algorithm to find volume of cube

Step1: Start

Step 2: Input  length as l

Step 3: Use pow function to find cube and store it in v

Step 4: Display v

Step 5: Stop


C Code to find volume of cube

/*C Code to find volume of cube*/

#include<stdio.h>

#include<math.h>

int main()

{

int l,v;

printf("Enter length : ");

scanf("%d",&l);

v=pow(l,3);

printf("Volume of cube is %d ",v);

return 0;

}


  1. Write a program in C to display the area and perimeter of a rectangle.

ANSWER: 

Algorithm to display area and perimeter of a rectangle 

Step1: Start

Step 2: Input length as l and breadth as b

Step 3: Use a=l*b and p=2(l+b)

Step 4: Display a and p

Step 5: Stop

C Code to display area and perimeter of a rectangle 

/*C Code to display area and perimeter of a rectangle */

#include<stdio.h>

int main()

{

int l,b,a,p;

printf("Enter length and breadth : ");

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

a=l*b;

p=2*(l+b);

printf("Area = %d \n Perimeter= %d ",a,p);

return 0;

}


  1. Write a program in C to calculate distance using s=ut+1/2at2.

ANSWER: 

Algorithm to calculate distance

Step1: Start

Step 2: Input initial velocity , time and acceleration as  u,t,a

Step 3: Use s=u*t+0.5*a*t*t

Step 4: Display s

Step 5: Stop


C Code to calculate distance covered

/*C Code to calculate distance covered*/

#include<stdio.h>

#include<math.h>

int main()

{

float u,t,a,s;

printf("Enter initial velocity , time and acceleration : ");

scanf("%f%f%f",&u,&t,&a);

s=u*t+0.5*a*pow(t,2);

printf("Distance covered  is %f ",s);

return 0;

}


  1. Write a program in C to calculate the area and circumference of a circle.

ANSWER: 

Algorithm to Calculate area and circumference of a circle

Step1: Start

Step 2: Input radius as r

Step 3: Use a=3.14*r*r  and c=2*3.14*r

Step 4: Display a and c

Step 5: Stop


C Code to Calculate area and circumference of a circle

/*C Code to Calculate area and circumference of a circle*/

#include<stdio.h>

int main()

{

float r,a,c;

printf("Enter radius :");

scanf("%f",&r);

a=3.14*r*r;

c=2*3.14*r;

printf("Area = %0.2f \n Circumference= %0.2f ",a,c);

return 0;

}


  1. Write a program in C to convert temperature in Centigrade (C) into Fahrenheit (F). HInt: F=1.8C+32

ANSWER: 

Algorithm to convert temperature from Centigrade into Fahrenheit 

Step1: Start

Step 2: Input temperature in centigrade as c

Step 3: Use f=1.8*c+32

Step 4: Display f

Step 5: Stop


C Code to convert temperature from Centigrade into Fahrenheit 

/*C Code to convert temperature from Centigrade into Fahrenheit */

#include<stdio.h>

int main()

{

float c,f;

printf("Enter temperature in centrigrade ");

scanf("%f",&c);

f=1.8*c+32;

printf("Temperature in Fahrenheit = %0.2f ",f);

return 0;

}


  1. Write a program in C to calculate the sum of two distances and the distance is measured in terms of feet and inches.

ANSWER: 

Algorithm to calculate sum of two distances and the distance is measured in terms of feet and inches

Step1: Start

Step 2: Input feet1,feet2,inch1,inch2

Step 3: Use feet3=feet1+feet2 and inch3=inch1+inch2

Step 4: newfeet=inch3/12+feet3  and newinch=inch3 % 12

Step 5: Display newfeet and newinch

Step6: Stop


C Code to calculate the sum of two distances and the distance is measured in terms of feet and inches

/*C Code to calculate the sum of two distances and the distance is measured in terms of feet and inches.

*/

#include<stdio.h>

int main()

{

int feet1,feet2,feet3,newfeet,inch1,inch2,inch3,newinch;

printf("Enter feet1,feet2,inch1 and inch2: ");

scanf("%d%d%d%d",&feet1,&feet2,&inch1,&inch2);

feet3=feet1+feet2;

inch3=inch1+inch2;

newfeet=inch3/12+feet3;

newinch=inch3%12;

printf("Feet=%d  Inch=%d",newfeet,newinch);

return 0;

}


  1. Write a program in C to enter a number of days and convert it into years, months and days.

ANSWER: 

Algorithm to enter number of days and convert it into years, months and days


Step1: Start

Step 2: Input days

Step 3: Divide days by 365 and store it as year(y)

Step 4: Remaining days(rd)  by finding remainder of days divide by 365

Step 5: For month(m) divide remaining days (rd) by 30 and take integer part.

Step 6: For days(d) divide  rd by 30 and find remainder.

Step 6: Display y , m , d 

Step 7 : Stop


C Code to enter number of days and convert it into years, months and days

/*C Code to enter number of days and convert it into years, months and days

*/

#include<stdio.h>

int main()

{

int days,y,m,d,rd;

printf("Enter the days : ");

scanf("%d",&days);

y=days/365;

rd=days%365;

m=rd/30;

d=rd%30;

printf("Year=%d Month=%d Day=%d",y,m,d);

return 0;

}

9)complete the following program and discuss the outputs.

program 1 program 2

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

float x; float x;

int x1=7; int x1=7;

int x2=2; int x2=2;

x=(float)x1/x2; x=(float)(x1/x2);

printf("%f",x); printf("%f",x);

Ans:-


for program 1:

For first programm we will get output

3.5.Here, we have used type conversion.

It causes the x1 and x2 to be converted into float before division.

for program 2:

Whereas for second program we will get output

3.0.Here the type conversion works after dividing the value of x1 by x2.


10)complete the following program and discuss the outputs.

program 1 program 2

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

int j; int j;

int i=5; int i=5; ; j=++i; j=i++;

printf("i=%d,j=%d",i,j); printf("i=%d,j=%d",i,j);

Ans:-

For program 1:

The output is i=6,j=6.

For program 2:

The output is i=6,j=5.

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


Credit goes to PLK sir😄+

(https://plkcomputersir.blogspot.com/p/welcome.html)

2 comments:

  1. HI This website is helpful! Thanks Sir!

    ReplyDelete
  2. Thanks for giving me credit LKM sir!!!

    ReplyDelete