You are on page 1of 61

PPS Lab File

Name : Harsh Verma


Roll No. : 20001016018
Branch : Computer Engineering With Specialization In
Data Science

Question 1.

Aim : Ramesh’s basic salary is input through the keyboard. His


dearness allowance is 40% of basic salary, and house rent
allowance is 20% of basic salary. Write a program to calculate
his gross salary.

Code:
#include<stdio.h>  
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    float a,b;
    scanf("%f",&a);
    b= a+ 0.6*a ;
    printf(" Gross salary is : %.2f",b);
}

Output :
Question 2.

Aim: The distance between two cities (in km.) is input through
the keyboard. Write a program to convert and print this
distance in meters, feet, inches and centimeters .

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    float a;
    scanf("%f",&a);
    printf(" in m %.2f\n",a*1000);
    printf("in feet %.2f\n",a*3281);
    printf(" in inch %.2f\n",a*39370);
    printf("in cm %.2f",a*100000);
    
    
}

Output :

Question 3.
Aim : If the marks obtained by a student in five different
subjects are input through the keyboard, find out the aggregate
marks and percentage marks obtained by the student. Assume
that the maximum marks that can be obtained by a student in
each subject is 100.

Code :
#include<stdio.h>
#include<conio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
 float a,b,c,d,e;
 printf("Enter the marks out of 100 in five subjects of the student : ");
 scanf("%f%f%f%f%f", &a,&b,&c,&d,&e);
 //his total marks
 printf("\n%f is the aggregate marks obtained by him.", a+b+c+d+e);
 //his percentage marks
 printf("\n%f is the percentage marks obtained by him.", (a+b+c+d+e)/5);
 getch();
 return 0;
}

Output :

Question 4.
Aim : Temperature of a city in Fahrenheit degrees is input
through the keyboard. Write a program to convert this
temperature into Centigrade degrees.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    float a;
    scanf("%f",&a);
    a=(a-32)*(5.0/9);
    printf("%f",a);
}

Output :

Question 5.
Aim : The length & breadth of a rectangle and radius of a circle
are input through the keyboard. Write a program to calculate
the area & perimeter of the rectangle, and the area &
circumference of the circle

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    float a,b,c;
    float k=3.14;
    scanf("%f %f %f",&a,&b,&c);
    printf(" The Area of rectangle is = %f\n The Perimeter of rectangle = %f\n 
The Circumference of circle is = %f\n The Area of circle is = %f\n",a*b,2*(a+b
),2*k*c,k*c*c);
}

Output :

Question 6.
Aim : Two numbers are input through the keyboard into two
locations C and D. Write a program to interchange the contents
of C and D.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    int c,d;
    printf("Enter the value of C & D :");
    scanf("%d %d",&c,&d);
    c=c+d;
    d=c-d;
    c=c-d;
    printf("%d %d",c,d);
}

Output :

Question 7.
Aim : If a five-digit number is input through the keyboard,
write a program to calculate the sum of its digits. (Hint: Use the
modulus operator ‘%’).

Code :
#include<stdio.h>
int main()
{
  int num,sum,a,b,c,d,e,d1,d2,d3,d4,d5;
  /*num=entered number,sum=sum of all digits,d1=1st digit,d2=2nd digit,d3=3rd 
digit,d4=4th digit,d5=5th digit*/
  printf(" Harsh Verma\n 20001016018\n -----------\n");
  printf("Enter any five digit number : ");
  scanf("%d",&num);
  a=num/10;
  d5=num%10;
  b=a/10;
  d4=a%10;
  c=b/10;
  d3=b%10;
  d=c/10;
  d2=c%10;
  e=d/10;
  d1=d%10;
  sum=d1+d2+d3+d4+d5;
  printf("\nSum of digits of given number is %d",sum);
  
}

Output :

Question 8.
Aim : If a five-digit number is input through the keyboard,
write a program to reverse the number.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    printf("Enter a five digit number\n");
    int a,r,sum=0;
    scanf("%d",&a);
    while(a>0)
    {
        r=a%10;
        sum=sum*10 + r;
        a=a/10;
    }
    printf("New reversed number is = " "%d",sum);
}

Output :

Question 9.
Aim : If a four-digit number is input through the keyboard,
write a program to obtain the sum of the first and last digit of
this number.

Code :
#include<stdio.h>

 int main()
{
  int num,sum,a,b,c,d,d1,d2,d3,d4;
  
   printf(" Harsh Verma\n 20001016018\n -----------\n");

  printf("Enter any four digit number : ");

  scanf("%d",&num);
  a=num/10;
  d4=num%10;
  b=a/10;
  d3=a%10;
  c=b/10;
  d2=b%10;
  d=c/10;
  d1=c%10;
  sum=d1+d4;
  printf("Sum of 1st and 4th digit = %d",sum);
  
}

Output :

Question 10.
Aim : In a town, the percentage of men is 52. The percentage of
total literacy is 48. If total percentage of literate men is 35 of the
total population, write a program to find the total number of
illiterate men and women if the population of the town is
80,000.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    float p=80000;
    float m,n;
    m=0.17*p;
    n=0.35*p;
    printf(" No. of Illitrate Men %f \n No. of Illitrate Women % f ",m,n);
}

Output :

Question 11.
Aim : A cashier has currency notes of denominations 10, 50
and 100. If the amount to be withdrawn is input through the
keyboard in hundreds, find the total number of currency notes
of each denomination the cashier will have to give to the
withdrawer.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    int amnt,a,b,k;
    scanf("%d",&amnt);
    a=amnt/100;
    amnt=amnt%100;
    b=amnt/50;
    amnt=amnt%50;
    k=amnt/10;
    amnt=amnt%10;
    if(amnt!=0)
    {
        printf("-1");
    }
    else
    {
        printf("No. of notes of Rs.100: %d \n  No. of notes of Rs.50: %d \n  N
o. of notes of Rs.10: %d",a,b,k);
    }
}

Output :

Question 12.
Aim : 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 of one item.

Code :
#include<stdio.h>
int main()
{
  int sp,tp,cp,cp1;
  /*sp=selling price of 15 items,tp=total profit,
  cp=cost price of 1 item,cp1=cost price of 1 item*/
   printf(" Harsh Verma\n 20001016018\n -----------\n");
    printf("Enter total selling price of 15 items : ");
  scanf("%d",&sp);
  printf("Enter profit on selling 15 items : ");
  scanf("%d",&tp);
  cp=sp-tp;
  cp1=cp/15;
  printf("Cost price of one item is %d",cp1);
 
}

Output :

Question 13.
Aim : If a five-digit number is input through the keyboard,
write a program to print a new number by adding one to each of
its digits. For example if the number that is input is 12391 then
the output should be displayed as 23402.

Code :
#include<stdio.h>
int main()
{
    printf(" Harsh Verma\n 20001016018\n -----------\n");
    int a,k,sum=0,r,temp=0;
    scanf("%d",&a);
    while(a>0)
    {
        k=a%10;
        k=k+1;
        if(k==10)
        {
            k=0;
        }
        sum=sum*10 +k;
        a=a/10;
    }
    while(sum>0)
    {
        r=sum%10;
        temp=temp*10 +r;
        sum=sum/10;
    }
    printf("%d",temp);
}

Output :

Chapter 2: The Decision Control Structure :


Question : 1
Aim : If cost price and selling price of an item is input through
the keyboard, write a program to determine whether the seller
has made profit or incurred loss. Also determine how much
profit he made or loss he incurred.
Code :
#include<stdio.h>

int main(){

    printf(" Harsh Verma\n 20001016018\n -----------\n");

    float cp , sp ;

    scanf("%f" , &cp ) ;

    scanf("%f" , &sp ) ;

    if(sp>=cp){

        printf("You have made profit of %f \n" , sp-cp ) ;

    }

    else{

        printf("You have made loss of %f \n" , cp-sp ) ;

    }

    return 0;

Output :

Question : 2
Aim : Any integer is input through the keyboard. Write a
program to find out whether it is an odd number or even
number.

Code :

#include<stdio.h>

int main(){

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int num  ;

    scanf("%d", &num);

    if(num%2==0)

        printf("%d is an even number \n", num );

    else

        printf("%d is an odd number \n", num );

 return 0;

Output :

Question : 3
Aim : Any year is input through the keyboard. Write a
program to determine whether the year is a leap year or not.
(Hint: Use the % (modulus) operator)

Code :

#include <stdio.h>

int main() {

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

   int year;

   scanf("%d",&year);

if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))

      printf("%d is a leap year", year);

   else

      printf("%d is not a leap year", year);

return 0;

Output :

Question : 4
Aim : According to the Gregorian calendar, it was Monday on
the date 01/01/1900. If any year is input through the keyboard
write a program to find out what is the day on 1st January of
this year

Code :
#include <stdio.h>

int main()

printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int year, basic_year = 1900, leap_year, remaining_year, total_days, day;

    printf("Enter the year: ");

    scanf("%d", &year);

    year = (year - 1) - basic_year;

    leap_year = year / 4;

    remaining_year = year - leap_year;

    total_days = (remaining_year * 365) + (leap_year * 366) + 1;

    day = total_days % 7;

    if (day == 0)

        printf("Monday");

    else if (day == 1)

        printf("Tuesday");

    else if (day == 2)

        printf("Wednesday");

    else if (day == 3)

        printf("Thursday");

    else if (day == 4)

        printf("Friday");

    else if (day == 5)
        printf("Saturday");

    else if (day == 6)

        printf("Sunday");

    else

        printf("Wrong Entry");

    return 0;

Output :
Question : 5
Aim : A five-digit number is entered through the keyboard.
Write a program to obtain the reversed number and to
determine whether the original and reversed numbers are equal
or not.
Code :
#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    

    int num, a, b, c, d, e, x;

    printf("Enter a five digit number : ");

scanf("%d", &num)

e = num % 10;

    d = (num / 10) % 10;

    c = (num / 100) % 10;

    b = (num / 1000) % 10;

a = (num / 10000);

x = e * 10000 + d * 1000 + c * 100 + b * 10 + a;

printf("\n%d", x);

if (x == num)

        printf("\n\nThe reverse of the number %d is same as actual number.", n
um);

    return 0;

Output :
Question : 6

Aim : If the ages of Ram, Shyam and Ajay are input through
the keyboard, write a program to determine the youngest of the
three.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int ram, shyam, ajay;

    printf("Enter the age of Ram, Shyam and Ajay respectively : \n");

scanf("%d%d%d", &ram, &shyam, &ajay);

if (ram < shyam && ram < ajay)

        printf("Ram is youngest among all.");

    else if (shyam < ram && shyam < ajay)

        printf("Shyam is youngest among all.");

    else

        printf("Ajay is youngest among all.");

    return 0;

Output :
Question : 7
Aim : Write a program to check whether a triangle is valid or
not, when the three angles of the triangle are entered through
the keyboard. A triangle is valid if the sum of all the three
angles is equal to 180 degrees.
Code :
#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int a1, a2 , a3;

    printf("Enter the angles of Triangle in Degrees.\n");

    scanf("%d %d %d", &a1, &a2, &a3);

    if (a1 + a2 + a3 == 180)

    {

        printf("Triangle is Valid.");

    }

    else

    {

        printf("Triangle is Invalid.");

    }

    return 0; 

Output :
Question : 8
Aim : Find the absolute value of a number entered through
the keyboard.
Code :
#include <stdio.h>

#include <math.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int number;

    printf("Enter number\n");

    scanf("%d", &number);

    printf("Absolute value of %d is %d.", number, abs(number));

    return 0;

Output :
Question : 9

Aim : Given the length and breadth of a rectangle, write a


program to find whether the area of the rectangle is greater
than its perimeter. For example, the area of the rectangle with
length = 5 and breadth = 4 is greater than its perimeter.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int l, b;

    printf("Enter length and breadth of rectangle\n");

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

    if ((l * b) > (2 * (l + b)))

    {

        printf("Area is Greater than perimeter\n");

    }

    else

    {

        printf("Area is not Greater than perimeter\n");

    }

    return 0; }

Output :
Question : 10
Aim : Given three points (x1, y1), (x2, y2) and (x3, y3), write a
program to check if all the three points fall on one straight line.
Code :
#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    float x1, y1, x2, y2, x3, y3;

    printf("Enter coordinates (x1,y1)\n");

    scanf("%f %f", &x1, &y1);

    printf("Enter coordinates (x2,y2)\n");

    scanf("%f %f", &x2, &y2);

    printf("Enter coordinates (x3,y3)\n");

    scanf("%f %f", &x3, &y3);

    if ((y2 - y1) / (x2 - x1) == (y3 - y1) / (x3 - x1))

    {

        printf("Point lies on straight line");

    }

    else

    {

        printf("Points don't lie on straight line");

    }

    return 0;

Output :
Question : 11
Aim : Given the coordinates (x, y) of a center of a circle and
it’s radius, write a program which will determine whether a
point lies inside the circle, on the circle or outside the circle.

Code :
#include <stdio.h>

#include <math.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    float cenx, ceny, radius, x, y, d;

    printf("Enter Center x,y coodinate and radius\n");

    scanf("%f %f %f", &cenx, &ceny, &radius);

    printf("Enter coordinates of point\n");

    scanf("%f %f", &x, &y);

    d = sqrt(pow((cenx - x), 2.0) + pow((ceny - y), 2.0));

    if (d < radius)

    {

        printf("Point is inside circle\n");

    }

    else if (d == radius)

    {

        printf("Point is on the circle\n");

    }

    else if (d > radius)

    {

        printf("Point is outside the circle\n");

    }

    return 0; }
Output :
Question : 12

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

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    float x, y;

    printf("Enter the x-y coordinates of the point : ");

scanf("%f%f", &x, &y);

if (x == 0 && y == 0)

        printf("\nThe point is on the origin.");

    if (x == 0 && y != 0)

        printf("\nThe point lie on the y-axis");

    if (x != 0 && y == 0)

        printf("\nThe points lie on the x-axis");

    if (x != 0 && y != 0)

        printf("\nThe points lie on the plane");

    return 0;

Output :
(F) Question : 1

Aim : Any year is entered through the keyboard, write a


program to determine whether the year is leap or not. Use the
logical operators && and ||.

Code :

#include <stdio.h>

int main() {

   printf(“ Harsh Verma\n 20001016018\n -----------\n”);

   int year;

   scanf("%d",&year);

   if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))

      printf("%d is a leap year", year);

   else

      printf("%d is not a leap year", year);

   return 0;

Output :
Question : 2
Aim : Any character is entered through the keyboard, write a
program to determine whether the character entered is a capital
letter, a small case letter, a digit or a special symbol.
Code :
#include<stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    char ch;

    int ascii;

    printf("Enter a character: ");

    scanf("%c", &ch);

    ascii = ch;

      

    if (ascii >= 65 && ascii <= 90)

        printf("%c is a capital letter",ch);

    else if (ascii >= 97 && ascii <=122)

        printf("%c is a small letter",ch);

    else if (ascii >=48 && ascii <= 57)

        printf("%c is a digit",ch);

    else if (ascii>=0 && ascii<=47 || ascii>=58 && ascii<=64 || ascii>=91 && a
scii<=96 || ascii>=123 && ascii<=127)

        printf("%c is a special symbols",ch);

    return 0;

Output :
Question : 3

Aim : An Insurance company follows following rules to


calculate premium.
(1) If a person’s health is excellent and the person is between 25
and 35 years of age and lives in a city and is a male then the
premium is Rs. 4 per thousand and his policy amount cannot
exceed Rs. 2 lakhs.
(2) If a person satisfies all the above conditions except that the
sex is female then the premium is Rs. 3 per thousand and her
policy amount cannot exceed Rs. 1 lakh.
(3) If a person’s health is poor and the person is between 25 and
35 years of age and lives in a village and is a male 90 Let Us C
then the premium is Rs. 6 per thousand and his policy cannot
exceed Rs. 10,000.
(4) In all other cases the person is not insured. Write a
program to output whether the person should be insured or
not, his/her premium rate and maximum amount for which
he/she can be insured
Write a program to output whether the person should be
insured or not, his/her premium rate and maximum amount
for which he/she can be insured.

Code :
#include <stdio.h>

int main()

    char h, l, g;

    int a;

    printf("Enter Heath e For Excellent And p For Poor ");
    scanf("%c", &h);

    printf("Enter Location c For City And v For Village ");

    scanf("\n%c", &l);

    printf("Enter Gender m For Male And f For Female ");

    scanf("\n%c", &g);

    printf("Enter Age ");

    scanf("\n%d", &a);

    if ((h == 'e') && (l == 'c') && (g == 'm') && (a >= 25 || a <= 35))

        printf("\nThe Premium Is Rs.4 Per Thousand And His Policy Cannot Excee
d Rs.2 Lakhs");

    else if ((h == 'e') && (l == 'c') && (g == 'f') && (a >= 25 || a <= 35))

        printf("\nThe Premium Is Rs.3 Per Thousand And Her Policy Cannot Excee
d Rs.1 Lakhs");

    else if ((h == 'p') && (l == 'v') && (g == 'm') && (a >= 25 || a <= 35))

        printf("\nThe Premium Is Rs.6 Per Thousand And Cannot Exceed Rs. 10,00
0");

    else

        printf("\n not Insured");

    return 0;

Output :
Question : 4

Aim : A certain grade of steel is graded according to the


following conditions: (i) Hardness must be greater than 50 (ii)
Carbon content must be less than 0.7 (iii) Tensile strength must
be greater than 5600 The grades are as follows: Grade is 10 if
all three conditions are met Grade is 9 if conditions (i) and (ii)
are met Grade is 8 if conditions (ii) and (iii) are met Grade is 7
if conditions (i) and (iii) are met Grade is 6 if only one condition
is met Grade is 5 if none of the conditions are met Write a
program, which will require the user to give values of hardness,
carbon content and tensile strength of the steel under
consideration and output the grade of the steel.

Code :

#include<stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    float h, c, t;

    int one = 0, two = 0, three = 0, grade;

    

    printf("\nEnter the hardness, carbon content and tensile strength : ");

    scanf("%f%f%f", &h, &c, &t);

    if(h > 50)

        one = 1;

    if(c < 0.7)

        two = 1;

    if(t > 5600)
        three = 1;

    if(one && two && three)

        grade = 10;

    else if(one && two && !three)

        grade = 9;

    else if(two && three && !one)

        grade = 8;

    else if(one && three && !two)

        grade = 7;

    else if(one && !two && !three)

        grade = 6;

    else if(!one && !two && !three)

        grade = 5;

        

    printf("\nGrade of the steel : %d", grade);

    return 0;

Output :
Question : 5

Aim : A library charges a fine for every book returned late. For
first 5 days the fine is 50 paise, for 6-10 days fine is one rupee
and above 10 days fine is 5 rupees. If you return the book after
30 days your membership will be cancelled. Write a program to
accept the number of days the member is late to return the
book and display the fine or the appropriate message.

Code :
#include<stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int days;

    float fine;

    printf("Enter the number of days: ");

    scanf("%d", &days);

    if (days > 0 && days <= 5)

        fine = 0.50 * days;

    if (days >= 6 && days <= 10)

        fine = 1 * days;

if (days > 10)

        fine = 5 * days;

if (days > 30)

        {

            printf("Your membership would be canceled.\n");

        }
    printf("You have to pay Rs. %.2f fine.", fine);

    return 0;

Output :
Question : 6

Aim : If the three sides of a triangle are entered through the


keyboard, write a program to check whether the triangle is valid
or not. The triangle is valid if the sum of two sides is greater
than the largest of the three sides.

Code :

#include<stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int x, y, z;

    int max, valid;

    printf("Enter the first side of triangle: ");

    scanf("%d", &x);

    printf("Enter the second side of triangle: ");

    scanf("%d", &y);

    printf("Enter the third side of triangle: ");

    scanf("%d", &z);

    max = x;

    if(max<y)

        max=y;

    if(max<z)

        max=z;

if(max == x && x < (y+z))
        valid = 1;

if(max == y && y < (x+z))

        valid = 1;

if(max == z && z < (x+y))

        valid = 1;

if (valid==1)

    printf("Triangle is valid");

else

    printf("Triangle is not valid");

Output :
Question : 7

Aim : If the three sides of a triangle are entered through the


keyboard, write a program to check whether the triangle is
isosceles, equilateral, scalene or right angled triangle.

Code :
#include<stdio.h>

#include<math.h>

int main()

printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int x, y, z;

    int max, flag=0;

    printf("Enter the first side: ");

    scanf("%d", &x);

    printf("Enter the second side: ");

    scanf("%d", &y);

    printf("Enter the third side: ");

    scanf("%d", &z);

    if (x==y && x==z)

    {

        printf("Triangle is equilateral.");

    }

    else if (x==y || y==z || z==x)

    {

        printf("Triangle is isosceles.");
    }

    max = x;

    if (y>max)

        max = y;

    if (z>max)

        max = z;

    if (max == x)

    {

        if(pow(max,2) == pow(y,2)+pow(z,2))

            flag=1;

    }

    if (max == y)

    {

        if(pow(max,2) == pow(x,2)+pow(z,2))

            flag=1;

    }

    if (max == z)

    {

        if(pow(max,2) == pow(x,2)+pow(y,2))

            flag=1;

    }

    if(flag==1)

    {

        printf("Triangle is right angled");

    }

    return 0;

Output :
Question : 8
Aim : In a company, worker efficiency is determined on the
basis of the time required for a worker to complete a particular
job. If the time taken by the worker is between 2 – 3 hours, then
the worker is said to be highly efficient. If the time required by
the worker is between 3 – 4 hours, then the worker is ordered
to improve speed. If the time taken is between 4 – 5 hours, the
worker is given training to improve his speed, and if the time
taken by the worker is more than 5 hours, then the worker has
to leave the company. If the time taken by the worker is input
through the keyboard, find the efficiency of the worker.

Code :
#include<stdio.h>
int main()
{
    printf(“ Harsh Verma\n 20001016018\n -----------\n”);
    float hours;
    printf("Input the time taken by worker: ");
    scanf("%f", &hours);
    if(hours>=2 && hours<=3)
        printf("Worker is highly efficient");
    if(hours>3 && hours <=4)
        printf("Worker needs to improve speed");
    if(hours>4 && hours <=5)
        printf("Give training to worker");
    if(hours>5)
        printf("Worker is terminated");
    return(0);
}

Output :
Question : 9

Aim : A university has the following rules for a student to


qualify for a degree with A as the main subject and B as the
subsidiary subject: (a) He should get 55 percent or more in A
and 45 percent or more in B. (b) If he gets than 55 percent in A
he should get 55 percent or more in B. However, he should get
at least 45 percent in A. (c) If he gets less than 45 percent in B
and 65 percent or more in A he is allowed to reappear in an
examination in B to qualify. (d) In all other cases he is declared
to have failed. Write a program to receive marks in A and B and
Output whether the student has passed, failed or is allowed to
reappear in B.

Code :
#include <stdio.h>
int main()
{
    printf(“ Harsh Verma\n 20001016018\n -----------\n”);
    int pera, perb;
    printf("Enter percentage of A and B: ");
    scanf("%d%d", &pera, &perb);
    if (pera >= 55 && perb >= 45)
        printf("\n Student is passed");

    else if (pera >= 45 && pera < 55 && perb >= 55)
        printf("\n Student is passed");
else if (perb < 45 && pera >= 65)
        printf("Student is allowed to reappear in an exam");
else
        printf("Student is failed");
    return 0;
}
Output :
Question : 10

Aim : The policy followed by a company to process customer


orders is given by the following rules: (a) If a customer order is
less than or equal to that in stock and has credit is OK, supply
has requirement. (b) If has credit is not OK do not supply. Send
him intimation. (c) If has credit is OK but the item in stock is
less than has order, supply what is in stock. Intimate to him
data the balance will be shipped. Write a C program to
implement the company policy.

Code :

#include<stdio.h>
#include<conio.h>
int main()
{
    int stock=100, order;
    char credit;
    printf("Enter the customer order: ");
    scanf("%d", &order);
    printf("Is his credit is ok? (Press y/n)\n");
    credit = getch();
    if(order<=stock && credit == 'y' || credit == 'Y')
        printf("Sir,\n\t We supplied your requirement\n\t\t Quant
ity: %d",order);
    else if(order>stock && credit == 'y' || credit == 'Y')
        printf("Sir,\n\t We supplied %d products and balance will 
be shipped later.",stock);
    else
        printf("Sir,\n\t Please first clear your credit, until we 
can't supply you any more.");
}

Output :
Chapter 3: The Loop Control Structure

Question : 1

Aim : Write a program to calculate overtime pay of 10


employees. Overtime is paid at the rate of Rs. 12.00 per hour
for every hour worked above 40 hours. Assume that employees
do not work for fractional part of an hour.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int i, hour, extra;

    for (i = 1; i <= 10; i++)

    {

        printf("\n");

        printf("Enter the working hour of the employ : ");

        scanf("%d", &hour);

        if (hour > 40)

        {

            extra = (hour - 40) * 12;

            printf("\n%d Rs. is the overtime pay of employee\n", extra);

        }
        else

            printf("\nThis employ has not done overtime.\n");

    }

    return 0;

Output :
Question : 2

Aim : Write a program to find the factorial value of any number


entered through the keyboard.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int i, fact = 1, num;

    printf("Ener a number = ");

    scanf("%d", &num);

    for (i = 0; i < num; i++)

    {

        fact *= (num-i);

    }

    printf("%d", fact);

    return 0;

Output :
Question : 3

Aim : Two numbers are entered through the keyboard. Write a


program to find the value of one number raised to the power of
another.

Code :

#include <stdio.h>

#include <math.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int base, power, d;

    printf("Enter value of base = ");

    scanf("%d", &base);

    printf("Enter value of power = ");

    scanf("%d", &power);

    d = pow(base, power);

    printf("%d", d);

    return 0;

Output :
Question : 4

Aim : Write a program to print all the ASCII values and their
equivalent characters using a while loop. The ASCII values vary
from 0 to 255.
Code :
#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int i;

    for(i = 0; i <= 255; i++)

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

    return 0;

Output :
Question : 5

Aim : Write a program to print out all Armstrong numbers


between 1 and 500. If sum of cubes of each digit of the number
is equal to the number itself, then the number is called an
Armstrong number. For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 )
+(3*3*3)

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int i, rem, num = 0, x;

    for (i = 1; i <= 500; i++)

    {

        num = 0;

        x = i;

        while (x)

        {

            rem = x % 10;

            num = num + (rem * rem * rem);

            x /= 10;

        }

        if (num == i)

            printf("%d is a armstrong number\n", i);

    }

    return 0;

}
Output :
Question : 6

Aim : Write a program for a matchstick game being played


between the computer and a user. Your program should ensure
that the computer always wins. Rules for the game are as
follows: − There are 21 matchsticks. − The computer asks the
player to pick 1, 2, 3, or 4 matchsticks. − After the person picks,
the computer does its picking. − Whoever is forced to pick up
the last matchstick loses the game.

Code :
#include <stdio.h>
int main()
{
    printf(“ Harsh Verma\n 20001016018\n -----------\n”);
    int matchsticks = 21, user, computer;
    printf("Numbers above 4 are invalid.");
    while (matchsticks >= 1)
    {
        printf("\nNumber of matchsticks available right now is %d
.", matchsticks);
        printf("\nYour Turn...");
        printf("\nPick up the matchstick(s)-- (1-4): ");
        scanf("%d", &user);
        if (user > 4)
        {
            printf("Invalid Selection");
            break;
        }
        computer = 5 - user;
        printf("\nComputer's Turn..\n");
        printf("\nComputer chooses:%d", computer);
        matchsticks = matchsticks - user - computer;
        continue;
        if (matchsticks == 1)

            break;
    }
    matchsticks--;
    printf("\nComputer Wins");
    return 0;
}

Output :
Question : 7

Aim : Write a program to enter the numbers till the user


wants and at the end it should display the count of positive,
negative and zeros entered.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int num, pos = 0, neg = 0, zero = 0, choice ,n;

    do

    {

        scanf("%d", &num);

        if (num == 0)

            zero++;

        else if (n < 0)

            neg++;

        else if (n > 0)

            pos++;

        printf("Do you want to enter another number? (Enter 1 for yes & 0 for 
no)");

        scanf("%d", &choice);

    } while (choice);

    printf("Zeroes = %d\n", zero);

    printf("Negatives = %d\n", neg);

    printf("Positives = %d\n", pos);

    return 0;

}
Output :
Question : 8
Aim : Write a program to find the octal equivalent of the
entered number
Code :
#include <stdio.h>
int main()
{
    printf(“ Harsh Verma\n 20001016018\n -----------\n”);
    int num, rem, oct = 0, rev = 0, rem1;
    scanf("%d", &num);
    while (num)
    {
        rem = num % 8;
        oct = 10 * oct + rem;
        num /= 8;
    }
    while (oct)
    {
        rem1 = oct % 10;
        rev = rev * 10 + rem1;
        oct /= 10;
    }
    printf("%d is octal equivalent", rev);
    return 0;
}

Output :
Question : 9

Aim : Write a program to find the range of a set of numbers.


Range is the difference between the smallest and biggest
number in the list.

Code :

#include <stdio.h>

int main()

    printf(“ Harsh Verma\n 20001016018\n -----------\n”);

    int i, num, max, min, N, range;

    printf("Enter how many number you want to enter : ");

scanf("%d", &N);

printf("Enter the number : ");

scanf("%d", &num);

max = min = num;

for (i = 1; i < N; i++)

    {

        printf("Enter the number : ");

        scanf("%d", &num);

        if (num > max)

            max = num;

        if (num < min)

            min = num;

    }

range = max - min;

printf("\n%d is the range of the data.", range);
    return 0;

Output :

You might also like