Professional Documents
Culture Documents
Write a program using one print statement to print the pattern of asterisks as:
Ans:
#include<stdio.h>
void main()
Printf(“*\n**\n***\n****\n*****”);
Question:2
Write a program using one print statement to print the pattern of asterisks as
Ans:
#include<stdio.h>
void main()
Printf(“*****\n****\n***\n**\n*”);
Question:4.
Write a program to output the following multiplication table,
2X1=2
2X2=4
2X3=6
2X4=8
2X5=10
2X6=12
2X7=14
2X8=16
2X9=18
2X10=20
Ans:
#include<stdio.h>
void main()
{
Printf(“2X1=2\n 2X2=4\n 2X3=6\n 2X4=8\n 2X5=10\n 2X6=12\n 2X7=14\n 2X8=16\n 2X9=18\n
2X10=20 ”);
Question:5.
Write a C program for Adding two integer numbers.
Ans:
#include<stdio.h>
void main()
Int a,b,sum;
Scanf(“%d”&a);
Scanf(“%d”&b);
Sum=a+b;
Question:6.
Write a C program to convert temperature from Fahrenheit to Celsius and Celsius t
o Fahrenheit.
Ans:
#include<stdio.h>
void main()
float C,F;
scanf(“%f”&C);
F= ((1.8XC)+32);
scanf(“%f”&F);
C= ((F-32)*5/9);
Question:7.
Write a C program to find the total head of a flow through pipe which is at a 5m hei
ght from the
datum line considering 5cm diameter under a pressure of 29.43 N/cm2 with a mean
velocity of 2 m/s.
Ans:
#include<stdio.h>
void main()
float P,f,g,Hpr,v,Hv,z,Ht;
scanf(“%f”,&P);
scanf(“%f”,&f);
scanf(“%f”,&g);
Hpr=(p/(f*g));
scanf(“%f”,&v);
scanf(“%f”,&g);
Hv=(v*v)/(2*g);
Ht=Hpr+Hv+z;
Question:14.
Write a program to find out the area and perimeter of a triangle when
three vertices are given.
Ans:
#include<stdio.h>
void main()
float X1,X2,X3,Y1,Y2,Y3,a,b,c,s,area,perimeter;
scanf(“%f%f%f”,&X1,&X2,&X3);
scanf(“%f%f%f”,&Y1,&Y2,&Y3);
a=sqrt((pow((X1-X2),2)+pow((Y1-Y2),2)));
b=sqrt((pow((X2-X3),2)+pow((Y2-Y3),2)));
c=sqrt((pow((X1-X3),2)+pow((Y1-Y3),2)));
s=((a+b+c)/2);
area=sqrt(s*(s-a)*(s-b)*(s-c));
perimeter=s*2;
Question:15.
Write a program to find out the area and perimeter of a rectangle when
four vertices are given.
Ans:
#include<stdio.h>
void main()
float X1,X2,X3,X4,Y1,Y2,Y3,Y4,a,b,c,d,s,area,perimeter;
scanf(“%f%f%f%f”,&X1,&X2,&X3,&X4);
scanf(“%f%f%f%f”,&Y1,&Y2,&Y3,&Y4);
a=sqrt((pow((X1-X2),2)+pow((Y1-Y2),2)));
b=sqrt((pow((X2-X3),2)+pow((Y2-Y3),2)));
c=sqrt((pow((X3-X4),2)+pow((Y3-Y4),2)));
d==sqrt((pow((X4-X1),2)+pow((Y4-Y1),2)));
area=aXb;
perimeter=(a+b+c+d);
Question:16.
Write a C program to find the flow rate of a nozzle. The nozzle is situated at a dista
nce of y meter
above the ground level and is inclined at θ degree to the horizontal. The diameter of
the nozzle is
d meter and the jet of water from the nozzle strikes the ground at a horizontal dista
nce of x meter.
Ans:
#include<stdio.h>
void main()
float y,angle,y1,y2,d,a,x,g,U,q;
y1=cos((angle*3.1416)/180);
y2=tan((angle*3.1416)/180);
scanf(“%f”,&y);
scanf(“%f”,&x);
scanf(“%f”,&g);
a=((3.1416/4)*d*g);
U=sqrt((g*x*x)/((2*y1*y1)*((y2*x)-y)));
Q=U*a
Question:17.
Write a C program to find the diameter of an equivalent pipe system that is made u
p of three
different lengths L1, L2, L3 with corresponding three different diameters d1, d2, an
d d3. Given that, L1+L2+L3 = L
Ans:
#include<stdio.h>
void main()
float D1,D2,D3,L1,L2,L3,D,L;
scanf(“%f%f%f%f%f%f”,&D1,&D2,&D3,&L1,&L2,&L3);
L=L1+L2+L3;
D=pow((L/((L1/pow(D1,5))+(L2/pow(D2,5))+(L3/pow(D3,5))));
Question:18.
A computer manufacturing company has the following monthly compensation polic
y to their sales persons. Write a C program to compute a sales‐
person’s gross salary.
Ans:
#include<stdio.h>
void main()
int quantity;
scanf(“%d%f”,&quantity,&price);
printf(“Bonus=%f\n”,bonus);
printf(“Commission=%f\n”,commission);