pe-105 practical

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

Computer Programming and Application (PE – 105)

PRACTICAL NO. 1
OBJECTIVE:

If the temperature of a city in Fahrenheit is input through keyboard, write a program to


convert this temperature into Centigrade degrees.

PROGRAM:

#include <stdio.h>

int main()

float F,C;

printf("enter temperature in Fahrenheit:");

scanf("%f",&F);

C=(F-32)*5/9;

printf("The temperature in Celsius is %f\n\n\n",C);

printf("After applying the conversion factor the fahreinheit temperature %f will be\t\t\t\t\t\t%f in
celsius temperature",F,C);

return 0;

OUTPUT:

1|Page
Computer Programming and Application (PE – 105)

PRACTICAL NO. 2
OBJECTIVE:

If a four digit number is input through keyboard, write a program to obtain the sum of the
first and last digits of this number.

PROGRAM:

#include <stdio.h>
int main()
{
int num,FN,LN;
printf("Enter four digit number:");
scanf("%d",&num);
FN=num/1000;
LN=num%10;
printf("The sum of first and last digit of the number %d is %d",num,FN+LN);
return 0;
}

OUTPUT:

PRACTICAL NO. 3
2|Page
Computer Programming and Application (PE – 105)

OBJECTIVE:

If the total selling price of 15 items and the total profit earned on them is input through the
keyboard, write a program to find the cost price per item.

PROGRAM:

#include <stdio.h>
int main()
{
float SP,PF,CP;
printf("Enter the selling price of 15 items:");
scanf("%f",&SP);
printf("Enter the profit on 15 items:");
scanf("%f",&PF);
CP=(SP-PF)/15;
printf("the cost price of one item is:%f",CP);
return 0;
}

OUTPUT:

PRACTICAL NO. 4
3|Page
Computer Programming and Application (PE – 105)

OBJECTIVE:

Find the absolute value of a number entered through the keyboard.

PROGRAM:

#include <stdio.h>
int main()
{
int A,B;
printf("Enter the value of A:");
scanf("%d",&A);
B = abs(A);
printf("THe value of B is:%d",B);
return 0;
}

OUTPUT:

PRACTICAL NO. 5
OBJECTIVE:
4|Page
Computer Programming and Application (PE – 105)

Given a point (x, y), write a program to find out if it lies on the x-axis, y-axis or the origin.

PROGRAM:

#include <stdio.h>
int main()
{
int x,y;
printf("Enter the value of x:");
scanf("%d",&x);
printf("Enter the value of y:");
scanf("%d",&y);
if(x==0&&y==0)
printf("It is at origin");
else if(x>0&&y>0)
printf("It is in first quadrant");
else if(x<0&&y>0)
printf("It is in second quadrant");
else if(x<0&&y<0)
printf("It is in third quadrant");
else if(x>0&&y<0)
printf("It is in fouth quadrant");
else if(x!=0&&y==0)
printf("It is at x axis");
}

OUTPUT:

PRACTICAL NO. 6
OBJECTIVE:

5|Page
Computer Programming and Application (PE – 105)

Write a program to check whether a reservoir is saturated or undersaturated oil reservoir


when bubble point pressure is 2331 psi.

PROGRAM:

#include<stdio.h>
int main()
{
int RES;
printf("Enter your Reservoir Pressure:");
scanf("%d",&RES);
if(RES<=2331)
printf("Reservoir is Saturated");
else
printf("Reservoir is UnderSaturated");
return 0;
}

OUTPUT:

PRACTICAL NO. 7
OBJECTIVE:

6|Page
Computer Programming and Application (PE – 105)

Write a program to calculate the Reynold’s Number and check whether the flow is Laminar,
Turbulent or Transitional.

PROGRAM:

#include<stdio.h>
int main()
{
float RN,d,l,v,dv;
printf("Enter Density:");
scanf("%f",&d);
printf("Enter Length:");
scanf("%f",&l);
printf("Enter Velocity:");
scanf("%f",&v);
printf("Enter Dynamic Velocity:");
scanf("%f",&dv);
RN=(d*l*v)/dv;
printf("The Reynolds Number is %f",RN);
if(RN<2300)
printf("\nIt is a Laminar Flow");
else if(RN>=2300&&RN<=4000)
printf("\nIt is a Transitional Flow");
else if(RN>4000)
printf("\nIt is a Turbulent Flow");
return 0;
}

OUTPUT:

7|Page
Computer Programming and Application (PE – 105)

8|Page
Computer Programming and Application (PE – 105)

PRACTICAL NO. 8
OBJECTIVE:

Write a program that will find the type of fluid on the basis of GOR in 10 reservoirs.
(Initialize loop counter from 10 with loop increment of 0.5)

PROGRAM:

#include<stdio.h>
int main()
{
float GOR,SCF,STB,z;
//GOR=Gas Oil Ratio,SCF=Standard Cubic Feet,STB=Stock Tank Barrel.
for(z=10;z<=14.5;z=z+0.5)
{
printf("\n\nEnter the value of SCF:");
scanf("%d",&SCF);
printf("\n\nEnter the value of STB:");
scanf("%d",&STB);
GOR=SCF/STB;
printf("The value of GOR is %f",GOR);
if(GOR<1750)
printf("\nThis is black oil");
else if(GOR>=1750&&GOR<3200)
printf("\nThis is volatile oil");
else if(GOR>=3200&&GOR<15000)
printf("\nThis is condensate gas");
else if(GOR>=15000&&GOR<100000)
printf("\nThis is wet gas");
else if(GOR>100000)
printf("\nThis is dry gas");
}
return 0;
}

9|Page
Computer Programming and Application (PE – 105)

OUTPUT:

10 | P a g e
Computer Programming and Application (PE – 105)

PRACTICAL NO. 9
OBJECTIVE:

Write a program that will check whether 4 reservoirs are of oil, condensate or gas on the
basis of reservoir temperature.
Critical Temperature = 200°C
Cricondentherm Temperature = 400°C
(Initialize your loop counter from 15 with loop decrement of 0.5)

PROGRAM:

#include<stdio.h>

int main()

float T,a;

for(a=15;a>=13.5;a=a-0.5)

printf("Enter the Reservoir Temperature:");

scanf("%f",&T);

if(T<200)

printf("It is an OIL RESERVOIR\n\n");

else if(T>=200&&T<=400)

printf("It is a CONDENSATE RESERVOIR\n\n");

else if(T>400)
OUTPUT:
printf("It is a GAS RESERVOIR\n\n");}

return 0;

11 | P a g e
Computer Programming and Application (PE – 105)

Output:

12 | P a g e
Computer Programming and Application (PE – 105)

PRACTICAL NO. 10
OBJECTIVE:

Write a program that first calculate the cost/ft of 6 bits and then will check the
compatibility of each bit. Compatibility criteria are:
If the value calculated is to be less than $20/ft then bit is compatible otherwise it is not.
(Initialize your loop counter from 12 with loop decrement of 0.2)

PROGRAM:

#include <stdio.h>
int main() {
// CB = cost per bit
float CPF, CB, CR, TD, TT, FD;
float i, j = 1;
for (i = 12; i >= 11; i = i - 0.2)
{
printf("\n\n\nEnter CB=");
scanf("%f", &CB);
printf("\nEnter CR=");
scanf("%f", &CR);
printf("\nEnter TD=");
scanf("%f", &TD);
printf("\nEnter TT=");
scanf("%f", &TT);
printf("\nEnter FD=");
scanf("%f", &FD);
CPF = (CB + CR * (TT + TD)) / FD;
printf("\nCPF=%f", CPF);
if (CPF >= 20)
continue;
else
printf("\nBit compatible");
}
return 0;
}

13 | P a g e
Computer Programming and Application (PE – 105)

OUTPUT:

14 | P a g e
Computer Programming and Application (PE – 105)

PRACTICAL NO. 11
OBJECTIVE:

Write a function to calculate the factorial value of any integer entered through keyboard.

PROGRAM:

#include <stdio.h>
int main()
{
int digit,num,f=1;
printf("enter any INTEGER=");
scanf("%d",&digit);
for(num=1;num<=digit;num++)
{
f=f*num;
}
printf("factorial of %d is %d",digit,f);
return 0;
}

OUTPUT:

15 | P a g e
Computer Programming and Application (PE – 105)

PRACTICAL NO. 12
OBJECTIVE:

Write a function which receives a float and an integer from main( ), find the product of
these two and return the product which is printed through main( ).

PROGRAM:

#include <stdio.h>
int main()
{
float num2, product;
int num1;
printf("Enter the two values to find the product: ");
scanf("%d,%f", &num1, &num2);
product = num1 * num2;
printf("The product is %f\n", product);
return 0;
}

OUTPUT:

16 | P a g e
Computer Programming and Application (PE – 105)

PRACTICAL NO. 13
OBJECTIVE:

Write a program that indicates odd and even elements of an array.

PROGRAM:

# #include<stdio.h>
int main() {
int n;
printf("Enter number of elements in the array: ");
scanf("%d", &n);
int arr[n];
//Take n elements as input from the user
printf("Enter %d elements in the array: ",n);
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
//Print all the even numbers
printf("Even numbers in the array are: ");
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
printf("%d ", arr[i]);
}
//print all the odd numbers
printf("\nOdd numbers in the array are: ");
for(int i=0;i<n;i++)
{
if(arr[i]%2==1)
printf("%d ", arr[i]);
}
}

17 | P a g e
Computer Programming and Application (PE – 105)

OUTPUT:

18 | P a g e
Computer Programming and Application (PE – 105)

19 | P a g e

You might also like