Uploaded by kumarkaushal2303

koushal pic

advertisement
Gateway Institute of Engineering & Technology (GIET)
GATEWAY INSTITUTE OF ENGINEERING
& TECHNOLOGY (GIET), SONEPAT
BACHELOR OF COMPUTER APPLICATION
PIC lab
B.C.A. 1st YEAR (1st SEM)
Submitted by:
Submitted To:
Name: Aditya
Name: Ms.Namrata
Rollno:
Asst. Prof. CSE, GIET
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
INDEX
S. NO.
Program List
1.
Write a program to find the largest of three numbers. (if-then-else)
2.
Write a program to find the largest number out of n numbers (for statement).
Calculate the salary of an employee given his basic pay, HRA = 10%
of his basic pay, TA = 5% of his basic pay and deduction IT =2.5%
of his basic pay.
3.
4.
Write a program to find the average mail height & average female
heights in the class (input is in form of sex code, height).
5.
Write a program to find of quadratic equation using switch
statements.
Student Name
Page no
Signature
Rollno
Gateway Institute of Engineering & Technology (GIET)
Program-1
Write a program to find the largest of three numbers. (if-then-else)
Source Code:
#include<stdio.h>
int main ()
{
int num1, num2, num3;
printf("enter 1number:");
scanf("%d", &num1);
printf("\n enter 2 number :");
scanf("%d", &num2);
printf("\n enter 3 number:");
scanf("%d",&num3);
if(num1>=num2)
{
if(num1 >=num3)
{
printf("\n%d is largest number",num1);
}
else
{
printf("\n%d is largest number",num3);
}
}
else
{
if(num2>=num3)
{
printf("\n%d is largest number",num2);
}
else
{
printf("\n%d is largest number", num3);
}
}
return 0;
}
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Output
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Program -2
Write a program to find the largest number out of n numbers (for -statement).
Source Code:
#include <stdio.h>
#include<conio.h>
void main( ) {
int i,num,n,large=0;
printf("How many numbers: ");
scanf("%d",&n);
for(i=0; i<n; i++) {
printf("\nEnter number %d: ",i+1);
scanf("%d",&num);
if(num>large)
large=num;
}
printf("\n\nThe Largest Number is %d",large);
getch();
}
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Output
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Program -3
Calculate the salary of an employee given his basic pay, HRA = 10% of his
basic pay, TA = 5% of his basic pay and deduction IT =2.5% of his basic pay.
Source Code:
#include <stdio.h>
#include<conio.h>
void main( )
{
float gross_salary, basic_pay, TA, HRA, IT;
printf("Enter the basic salary");
scanf("%f", &basic_pay);
HRA = ( 10 * basic_pay) / 100;
TA = (5 * basic_pay) / 100;
IT = ( 2.5 * basic_pay) / 100;
gross_salary = basic_pay + HRA + TA- IT;
printf("\n Gross Salary: %f", gross_salary);
getch( );
}
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Output
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Program -4
Write a program to find the average mail height & average female heights in
the class (input is in form of sex code, height).
Source Code
#include <stdio.h>
void main()
{
float mavg=0, favg=0;
int mh[5], fh[5], count;
float mtot, ftot;
for(count=0;count<5;count++)
{
printf("\nEnter the height of male %d ",count+1);
scanf("%d",&mh[count]);
mtot+=mh[count];
}
mavg=mtot/5;
printf("\n");
for(count=0;count<5;count++)
{
printf("\n\nEnter the height of female %d ",count+1);
scanf("%d",&fh[count]);
ftot+=fh[count];
}
favg+=ftot/5;
printf("\nThe average male height is %f",mavg);
printf("\nThe average female height is %f",favg);
}
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Output
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Program - 5
Write a program to find of quadratic equation using switch statements.
Source Code:
#include <stdio.h>
#include <math.h>
int main()
{
float a, b, c;
float root1, root2, imaginary, discriminant;
printf("Enter value of 'a' of quadratic equation (aX^2 + bX + c): ");
scanf("%f", &a);
printf("Enter value of 'b' of quadratic equation (aX^2 + bX + c): ");
scanf("%f",&b);
printf("Enter values of 'c' of quadratic equation (aX^2 + bX + c): ");
scanf("%f",&c);
discriminant = (b * b) - (4 * a * c);
switch(discriminant > 0)
{
case 1:
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Two distinct and real roots exists: %.2f and %.2f", root1, root2);
break;
case 0:
switch(discriminant < 0)
{
case 1:
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
root1 = root2 = -b / (2 * a);
imaginary = sqrt(-discriminant) / (2 * a);
printf("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f", root1, imaginary,
root2, imaginary);
break;
case 0:
root1 = root2 = -b / (2 * a);
printf("Two equal and real roots exists: %.2f and %.2f", root1, root2);
break;
}
}
return 0;
}
Student Name
Page no
Rollno
Gateway Institute of Engineering & Technology (GIET)
Output
Student Name
Page no
Rollno
Download