Saturday 29 April 2023

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 1


SET A

1. Accept dimensions of a cylinder and print the surface area and volume (Hint: surface area =
2pr2 + 2prh, volume = pr2h)

#include<stdio.h>
#include<conio.h>

void main()
{
 float r,h,sa,v;
 clrscr();

 printf("\nFinding Surface Area of cylinder and volume:");
 printf("\nEnter the radius of cylinder in cm:");
 scanf("%f",&r);
 printf("\nEnter the height of cylinder in cm:");
 scanf("%f",&h);

 sa=(2*3.14*r*r)+(2*3.14*r*h);
 printf("\nSurface area of cylinder:%f",sa);

 v=3.14*r*r*h;
 printf("\nvolum of Cylinder:%f",v);

 getch();
} 
/*
output:

Finding Surface Area of cylinder and volume:                                   
Enter the radius of cylinder in cm:3                                           
                                                                               
Enter the height of cylinder in cm:3                                           

Surface area of cylinder:113.040001
volum of Cylinder       :84.779999
*/ 


Exercise 1-To demonstrate the use of data types, simple operators and expressions - 7

 7. Accept a character from the keyboard and display its previous and next character in order.

Ex. If the character entered is ‘d’, display “The previous character is c”, “The next character is e”.
 

#include<stdio.h>
#include<conio.h>

void main()
{
 char m;

 clrscr();

 printf("\nFinding the first and last charcher of enter character on basis on ABC..");
 printf("\nEnter the characher:");
 scanf("%c",&m);
 printf("\nFirst character is:%c",m+1);
 printf("\nLast character is:%c",m-1);



 getch();
}

/*

Finding the first and last charcher of enter character on basis on ABC..       
Enter the characher:T                                                          
                                                                               
First character is:U                                                           
Last character is:S                                                            
 */

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 6

 6. Accept three dimensions length (l), breadth(b) and height(h) of a cuboid and print surface

area and volume (Hint : surface area=2(lb+lh+bh ), volume = lbh )
 

#include<stdio.h>
#include<conio.h>

void main()
{
 int l,b,h;
 float sa,v;
 clrscr();

 printf("\nFinding the surfacearea and volume of cubiod:");
 printf("\nEnter the lenght of cubiod:");
 scanf("%d",&l);
 printf("\nenter the  breath of cubiod:");
 scanf("%d",&b);
 printf("\nEnter the height of cubiod:");
 scanf("%d",&h);

 sa=2*(l*b+l*h+b*h);
 printf("\nSurface area of cubiod is:%f",sa);

 v=l*b*h;
 printf("\nVolume of cubiod is:%f",v);

 getch();
}

/*

Finding the surfacearea and volume of cubiod:                                  
Enter the lenght of cubiod:5                                                   
                                                                               
enter the  breath of cubiod:4                                                  
                                                                               
Enter the height of cubiod:6                                                   
                                                                               
Surface area of cubiod is:148.000000                                           
Volume of cubiod is:120.000000                                                 
*/
 

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 4

 4. Accept inner and outer radius of a ring and print the perimeter and area of the ring (Hint:

perimeter = 2 p (a+b) , area = p (a2-b2) )

#include<stdio.h>
#include<conio.h>

void main()
{
 int ir,or;
 float peri,area;
 clrscr();

 printf("\nFinding the perimeter and area of ring:");
 printf("\nEnter the inner radius of ring:");
 scanf("%d",&ir);
 printf("\nEnter the outer radius of ring:");
 scanf("%d",&or);

 peri=2*3.14*(ir*or);
 printf("\nPrimeter of ring:%f",peri);
 area=3.14*((ir*ir)-(or*or));
 printf("\nArea of ring:%f",area);

 getch();
}
/*

Finding the perimeter and area of ring:                                        
Enter the inner radius of ring:15                                              
                                                                               
Enter the outer radius of ring:16                                              
                                                                               
Primeter of ring:1507.199951                                                   
Area of ring:-97.339996                                                        
                                                                               
   */

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 5

 5. Accept two numbers and print arithmetic and harmonic mean of the two numbers (Hint: AM=

(a+b)/2 , HM = ab/(a+b) )


#include<stdio.h>
#include<conio.h>

void main()
{
 int a,b;
 float am,hm;
 clrscr();

 printf("\nFinding the arthmatic mean and harmonic mean:");
 printf("\nEnter the 2 nos:");
 printf("\nEnter the first no:");
 scanf("%d",&a);
 printf("\nEnter the second no:");
 scanf("%d",&b);

 am=(a+b)/2;
 printf("\nArthmatic mean:%f",am);

 hm=a*b/(a+b);
 printf("\nHarmonial mean:%f",hm);

 getch();
}


/*

Finding the arthmatic mean and harmonic mean:                                  
Enter the 2 nos:                                                               
Enter the first no:                                                            
4                                                                              
                                                                               
Enter the second no:                                                           
5                                                                              
                                                                               
Arthmatic mean:4.000000                                                        
Harmonial mean:2.000000                                                        
*/

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 3

 3]Accept initial velocity (u), acceleration (a) and time (t). Print the final velocity (v) and the

distance (s) travelled. (Hint: v = u + at, s = u + at2)

#include<stdio.h>
#include<conio.h>

void main()
{
 int u,a,t;
 float v,s;

 clrscr();

 printf("\nFinding Final velocity and distance travelled by body:");
 printf("\nEnter the initial velocity:");
 scanf("%d",&u);
 printf("\nEnter the acceleration:");
 scanf("%d",&a);
 printf("\nEnter the time in sec:");
 scanf("%d",&t);

 v=u+(a*t);
 printf("\nFinala velocity is :%f",v);
 s=u+(a*t*t);
 printf("\nDistance travelled is:%f",s);

 getch();
}


/*OUTPUT : 

Finding Final velocity and distance travelled by body:                         
Enter the initial velocity:55                                                  
                                                                               
Enter the acceleration:56                                                      
                                                                               
Enter the time in sec:40                                                       
                                                                               
Finala velocity is :2295.000000                                                
Distance travelled is:24119.000000                                             

*/

Exercise 1-To demonstrate the use of data types, simple operators and expressions - 2

 2. Accept temperatures in Fahrenheit (F) and print it in Celsius(C) and Kelvin (K) (Hint: C=5/9(F-

32), K = C + 273.15)

#include<stdio.h>
#include<conio.h>

void main()
{
 float f,c,k;
 clrscr();

 printf("\nFinding fahrenheit tempreture in kelvin and celsius:");
 printf("\nEnter the temp in fahrenheit:");
 scanf("%f",&f);

 c=(5/(float)9)*(f-32);
 printf("\nTemp in celsius:%f celsius",c);

 k=c+273.15;
 printf("\nTemp in Kelvin:%f k",k);

 getch();

}
/*
output:

Finding fahrenheit tempreture in kelvin and celsius:                           
Enter the temp in fahrenheit:123                                               
                                                                               
Temp in celsius:50.555557 celsius                                              
Temp in Kelvin:323.705566 k
*/ 

 


Sunday 23 April 2023

3. Accept initial velocity (u), acceleration (a) and time (t). Print the final velocity (v) and the distance (s) travelled. (Hint: v = u + at, s = u + at2)

 



#include<stdio.h>
#include<conio.h>

void main()
{
 int u,a,t;
 float v,s;

 clrscr();

 printf("\nFinding Final velocity and distance travelled by body:");
 printf("\nEnter the initial velocity:");
 scanf("%d",&u);
 printf("\nEnter the acceleration:");
 scanf("%d",&a);
 printf("\nEnter the time in sec:");
 scanf("%d",&t);

 v=u+(a*t);
 printf("\nFinala velocity is :%f",v);
 s=u+(a*t*t);
 printf("\nDistance travelled is:%f",s);

 getch();
}
/*

Finding Final velocity and distance travelled by body:                         
Enter the initial velocity:55                                                  
                                                                               
Enter the acceleration:56                                                      
                                                                               
Enter the time in sec:40                                                       
                                                                               
Finala velocity is :2295.000000                                                
Distance travelled is:24119.000000  .                      
                     

*/

Exercise 4-To demonstrate use of simple loops.

SET A

Exercise 5-To demonstrate use of nested loops

SET A

1. Write a program to display all prime numbers between x and y.

#include<stdio.h>
#include<conio.h>
void main()
{
 int x,y,i,flag,j;
 clrscr();
 printf("\nEnter two Numbers:");
 scanf("%d%d",&x,&y);
 printf("\nPrime numbers between %d and %d is  ",x,y);
 for(i=x;i<y;i++)
    {
     flag=0;
     for(j=2;j<i;j++)
    {
     if(i%j==0)
        flag=1;
    }
     if(flag==0)
       printf("\n%d",i);
    }
 getch();
}

OUTPUT:

Enter two Numbers:1                                                            
20                                                                             
                                                                               
Prime numbers between 1 and 20 is                                              
1                                                                              
2                                                                              
3                                                                              
5                                                                              
7                                                                              
11
13
17
19

Exercise 3-To demonstrate decision making statements (switch case)



SET A

1. Accept a single digit from the user and display it in words. For example, if digit entered is 9,
display Nine.


#include<stdio.h>
#include<conio.h>
void main()
{
 int n;
 clrscr();
 printf("\nEnter the number:");
 scanf("%d",&n);
 switch(n)
      {
    case 1:printf("\nOne");
           break;
    case 2:printf("\nTwo");
           break;
    case 3:printf("\nThree");
           break;
    case 4:printf("\nFour");
           break;
    case 5:printf("\nFive");
           break;
    case 6:printf("\nSix");
           break;
    case 7:printf("\nSeven");
           break;
    case 8:printf("\nEight");
           break;
    case 9:printf("\nNine");
           break;
       default:printf("\nInvalid Output");
      }
 getch();
}
/*
output:

Enter the number:9                                                             

Nine
*/
2. Write a program, which accepts two integers and an operator as a character (+ - * /),
performs the corresponding operation and displays the result.


#include<stdio.h>
#include<conio.h>
void main()
{
 int n1,n2;
 char op;
 clrscr();
 printf("\nEnter 2 numbers:");
 scanf("%d%d",&n1,&n2);
 printf("\n+.Addition\n-.Substration\n*.Multiplication\/.Division\5Exit");
 printf("\nEnter your choise");
 scanf(" %c",&op);
 switch(op)
       {
    case '+':printf("\nAddition is %d",n1+n2);
         break;
    case '-':printf("\nSubstration is %d",n1-n2);
         break;
    case '*':printf("\nMultiplication is %d",n1*n2);
         break;
    case '/':printf("\nDivision is %d",n1/n2);
         break;
       }
 getch();
}
/*
Enter 2 numbers:5                                                              
4                                                                              
                                                                               
+.Addition                                                                     
-.Substration                                                                  
*.Multiplication/.Division Exit                                                
Enter your choise  +                                                           
                                                                               
Addition is 9                                                                  
 */

3. Accept two numbers in variables x and y from the user and perform the following operations
Options Actions
1. Equality Check if x is equal to y
2. Less Than Check if x is less than y
3. Quotient and Remainder Divide x by y and display the quotient and remainder
4. Range Accept a number and check if it lies between x and y
(both inclusive)
5. Swap Interchange x and y


#include<stdio.h>
#include<conio.h>
void main()
{
 int n1,n2,ch,q,r,t;
 clrscr();
 printf("\nEnter 2 numbers:");
 scanf("%d%d",&n1,&n2);
 printf("\n1.Equality\n2.Less than\n3..Quotient and remainder\n4.Range\n5.Swap");
 printf("\nEnter your choise");
 scanf(" %d",&ch);
 switch(ch)
      {
    case 1:if(n1==n2)
          printf("\n %d equals to %d",n1,n2);
           else
          printf("\n %d not equal to %d",n1,n2);
           break;
    case 2:if(n1<n2)
          printf("\n %d less than%d",n1,n2);
           else
          printf("\n %d not less than %d",n1,n2);
           break;
    case 3:q=n1/n2;
           printf("\nQuotient is %d",q);
           r=n1%n2;
           printf("\nRemainder is %d",r);
           break;
    case 4:printf("\nEnter number :");
           scanf("%d",&t);
           if(t>n1 && t<n2)
          printf("\n %d is between %d and %d",r,n1,n2);
           else
          printf("\n %d is  not between %d and %d",r,n1,n2);
           break;
    case 5:printf("\nBefore swap no is");
           printf("First no is:%d",n1);
           printf("Second no is %d",n2);
           t=n1;
           n1=n2;
           n2=t;
           printf("\After swap no is");
           printf("First no is:%d",n1);
           printf("Second no is %d",n2);
           break;
       default:printf("\nInvalid choise:");
      }
 getch();

SET B

€ 1. Accept radius from the user and write a program having menu with the following options and
corresponding actions
Options Actions
1. Area of Circle Compute area of circle and print
2. Circumference of Circle Compute Circumference of circle and print
3. Volume of Sphere Compute Volume of Sphere and print

#include<conio.h>
#include<stdio.h>
void main()
{
 int op;
 float r,ans;
 clrscr();
 printf("\nEnter redius:");
 scanf("%f",&r);
 printf("\n1.Area of circle\n2.Circumference of circle\n3.Volume of Shere");
 printf("\nEnter your choice:");
 scanf("%d",&op);
 switch(op)
       {
     case 1:ans=3.14*r*r;
        printf("\nArea of circle is %f",ans);
        break;
     case 2:ans=2*3.14*r;
        printf("\nCircumference of circcle is %f",ans);
        break;
     case 3:ans=4/3*3.14*r*r*r;
        printf("\nVolume of Shere is %f",ans);
        break;
    default:printf("\nInvalid input:");
       }

 getch();
}
/*

Enter redius:3.2                                                               
                                                                               
1.Area of circle                                                               
2.Circumference of circle                                                      
3.Volume of Shere                                                              
Enter your choice:1                                                            
                                                                               
Area of circle is 32.153603                                                    


Enter redius:4                                                                 
                                                                               
1.Area of circle                                                               
2.Circumference of circle                                                      
3.Volume of Shere                                                              
Enter your choice:2                                                            
                                                                               
Circumference of circcle is 25.120001                                          


Enter redius:2.5                                                               
                                                                               
1.Area of circle                                                               
2.Circumference of circle                                                      
3.Volume of Shere                                                              
Enter your choice:3                                                            
                                                                               
Volume of Shere is 49.062500                                                   
*/

2. Write a program having a menu with the following options and corresponding actions
Options Actions
1. Area of square Accept length ,Compute area of square and print
2. Area of Rectangle Accept length and breadth, Compute area of rectangle
and print
3. Area of triangle Accept base and height , Compute area of triangle and
print


#include<stdio.h>
#include<conio.h>
void main()
{
 int op;
 float l,b,h,ans;
 clrscr();
 printf("\n1.Area of square\n2.Area of Rectangle\n3.Area of triangle");
 printf("\nEnter your choise:");
 scanf("%d",&op) ;
 switch(op)
       {
     case 1:printf("\nEnter length :");
        scanf("%f",&l);
        ans=l*l;
        printf("\nArea of square is %f",ans);
        break;
     case 2:printf("\nEnter length :");
        scanf("%f",&l);
        printf("\nEnter breadth:");
        scanf("%f",&b);
        ans=l*b;
        printf("\nArea of Rectangle is %f",ans);
        break;
     case 3:printf("\nEnter base:");
        scanf("%f",&b);
        printf("\nEnter height:");
        scanf("%f",&h);
        ans=1.0/2.0*b*h;
        printf("\nArea of square is %f",ans);
        break;

       }
 getch();
}
/*                                                                               
1.Area of square                                                               
2.Area of Rectangle                                                            
3.Area of triangle                                                             
Enter your choise:1                                                            
                                                                               
Enter length :4                                                                
                                                                               
Area of square is 16.000000                                                    
1.Area of square                                                               
2.Area of Rectangle                                                            
3.Area of triangle                                                             
Enter your choise:2

Enter length :6

Enter breadth:4

Area of Rectangle is 24.000000

1.Area of square                                                               
2.Area of Rectangle                                                            
3.Area of triangle                                                             
Enter your choise:3                                                            
                                                                               
Enter base:4                                                                   
                                                                               
Enter height:6                                                                 
                                                                               
Area of square is 12.000000


Set C
€ 1. Accept the three positive integers for date from the user (day, month and year) and check
whether the date is valid or invalid. Run your program for the following dates and fill the table.
(Hint: For valid date 1<=month<=12,1<= day <=no-of-days where no-of-days is 30 in case of
months 4, 6,9 and 11. 31 in case of months 1,3,5,7,8,10 and 12. In case of month 2 no-of-days is
28 or 29 depending on year is leap or not)
Date Output
12-10-1984
32-10-1920
10-13-1984
29-2-1984
29-2-2003
29-2-1900


#include<stdio.h>
#include<conio.h>
void main()
{
 int d,m,y;
 clrscr();
 printf("\nEnter date,month,year");
 scanf("%d%d%d",&d,&m,&y);
 switch(m)
       {
    case 1 :
    case 3 :
    case 5 :
    case 7 :
    case 8 :
    case 10:
    case 12:if(d>0 && d<=31)
          printf("\nValid date");
        else
          printf("\nInvalid date");
        break;
    case 4 :
    case 6 :
    case 9 :
    case 11:if(d>0 && d<31)
          printf("\nValid date");
        else
          printf("\nInvalid date");
        break;
        break;
    case 2 :if(y%4==0)
          {
           if(d>0 &&d<=29)
             printf("\nValid Date");
           else
             printf("\nInvalid date");
          }
        else
          {
           if(d>0&&d<=28)
             printf("\nValid date");
           else
             printf("\nInvalid date");
          }
        break;
    default:printf("\nInvalid month");

       }
 getch();
}
/*
Enter date,month,year29
11
1991

Valid date


Enter date,month,year31
4
2017

Invalid date

Enter date,month,year                                                          
30                                                                             
2                                                                              
1000                                                                           
                                                                               
Invalid date                                                                   
  */

2. Write a program having menu that has three options - add, subtract or multiply two fractions.
The two fractions and the options are taken as input and the result is displayed as output. Each
fraction is read as two integers, numerator and denominator
.

#include<stdio.h>
#include<conio.h>
void main()
{
 float n1,d1,n2,d2,ans;
 int op;
 clrscr();
 printf("\nEnter first fraction number:");
 printf("\nEnter numerator and denominator:");
 scanf("%f%f",&n1,&d1);
 printf("\nEnter Second fraction number:");
 printf("\nEnter numerator and denominator:");
 scanf("%f%f",&n1,&d1);
 printf("\n1.Addition\n2.Substract\n3.Multiply ")
 printf("\nEnter your choise:");
 scanf("%d",&op);
 switch(op)
       {
    case 1:
           break;
    case 1:
           break;
    case 1:
           break;
       default:printf("\nInvalid choise:");
       }
 getch();
}

Exercise 2-To demonstrate use of decision making statements such as if and if-else.


SET A
1. Write a program to accept an integer and check if it is even or odd.

#include<stdio.h>
#include<conio.h>

void main()
{
 int no;
 clrscr();

 printf("\nFinding giving no is even or odd:");
 printf("\nEnter the number:");
 scanf("%d",&no);

 if(no%2==0)
   printf("\n%d NO is even:",no);
 else
   printf("\n%d NO is odd:",no);

 getch();

}
/*

Finding giving no is even or odd:                                              
Enter the number:4                                                             
                                                                               
4 NO is even:                                                                  
Finding giving no is even or odd:                                              
Enter the number:5                                                             
                                                                               
5 NO is odd:                                                                   
*/

  2] Write a program to accept three numbers and check whether the
  first is between the other two numbers.

#include<stdio.h>
#include<conio.h>

void main()
{
 int a,b,c,mid,min,max;
 clrscr();

 printf("\nEnter first no:");
 scanf("%d",&a);
 printf("\nEnter Second no:");
 scanf("%d",&b);
 printf("\nEnter third no:");
 scanf("%d",&c);

 if(a<b&&a>c||a>b&&a<c)
   mid=a;
 if(b>a&&b<c||b<a&&b>c)
   mid=b;
 if(c>a&&c<b||c<a&&c>b)
   mid=c;

 printf("\nMid:%d",mid);
 getch();
}
/*

Enter first no:20                                                              
                                                                               
Enter Second no:10                                                             
                                                                               
Enter third no:30                                                              
                                                                               
Mid:20                                                                         
*/
 3]Accept a charcter as input and check whether the character
 is digit.

#include<stdio.h>
#include<conio.h>

void main()
{
 char ch;
 clrscr();

 printf("\nEnter the charcter:");
 scanf("%c",&ch);
 if(ch>='0' && ch<='9')
   printf("\n character is a digit between 0 to 9 charcters:");
 else
   printf("\n character is not a digit between 0 to 9:");

 getch();
}
/*

Enter the charcter:4
character is a digit between 0 to 9 charcters:

Enter the charcter:A
character is not a digit between 0 to 9:
*/

  4]Write a program to accept a number and check if it is
  divisible by 5 and 7.

#include<stdio.h>
#include<conio.h>

void main()
{
 int no;
 clrscr();

 printf("\nEnter the no:");
 scanf("%d",&no);

 if((no%5==0)&&(no%7==0))
   printf("\n%d is divisible by 5 and 7:",no);
 else
  printf("\n%d is not divisible by 5 and 7:",no);

 getch();
}
/*

Enter the no:35                                                                
                                                                               
35 is divisible by 5 and 7:                                                    
Enter the no:55                                                                
                                                                               
55 is not divisible by 5 and 7:                                                
*/

  5] Write a program,which accepts annual basic salary of an employee and calculates
  and display the income tax as per the following rules.
  Basic:<1,50,000               Tax=0
     1,50,000 to 3,00,000   tax=20%
     >300000                tax=30%

#include<stdio.h>
#include<conio.h>

void main()
{

 float tax=0,as,limit;
 clrscr();
 printf("\nEnter the Annual salary of emp: ");
 scanf("%f",&as);

 limit=150000;
 if(as<=limit)
      printf("\nfor %f NO Tax: ",as);
 else if(as>150000&&as<300000)
      tax=(as-limit*0.1)*0.1;
 else if(as>300000)
      tax=(as-limit*0.1)*0.3;
 printf("\nOn salary: %f Tax is:%f",as,tax);

 getch();
}
/*

Enter the Annual salary of emp: 7000                                           
                                                                               
for 7000.000000 NO Tax:                                                        
On salary: 7000.000000 Tax is:0.000000                                         
Enter the Annual salary of emp: 200000                                         
                                                                               
On salary: 200000.000000 Tax is:18500.000000                                   
Enter the Annual salary of emp: 500000                                         
                                                                               
On salary: 500000.000000 Tax is:145500.000000                                  
*/
6 ] Accept a lowercase character from the user and check whether
  the character is a vowel or consonant.

#include<stdio.h>
#include<conio.h>

void main()
{
 char c;
 clrscr();

 printf("\nEnter the lowercase character:");
 scanf("%c",&c);

 if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
   printf("\n%c charcter is vowel:",c);
 else
   printf("\n%c not vowel:",c);

 getch();
}
/*
Enter the lowercase character:E                                                
                                                                               
E charcter is vowel:                                                           
Enter the lowercase character:e                                                
                                                                               
e charcter is vowel:                                                           
Enter the lowercase character:d                                                
                                                                               
d not vowel:                                                                   
*/
SET B
1]Write a program to check whether gien character is a digit or character in
 lowecase or uppercase alphabet.

#include<stdio.h>
#include<conio.h>

void main()
{
 char c;
 int ch;
 clrscr();

 printf("\nEnetr the charcter:");
 scanf("%c",&c);

 ch=c;
 if(ch>=48&&ch<=58)
   printf("\n%c Character is digit:",c);
 else if(ch>=97&&ch<=122)
   printf("\n%c Charcter is lowercase Alphabet:",c);
 else
   printf("\n%c Charcter is uppercase Alphabet:",c);


 getch();
}
/*

Enetr the charcter:A                                                           
                                                                               
A Charcter is uppercase Alphabet:                                              
Enetr the charcter:a                                                           
                                                                               
a Charcter is lowercase Alphabet:
Enetr the charcter:4

4 Character is digit:


Enetr the charcter:+

Special character:
*/
 2]Accept the time as hour,minute and second and check whether the
  time is valid.

#include<stdio.h>
#include<conio.h>

void main()
{
 int h,m,s;
 clrscr();

 printf("\nEnter the time");
 printf("\nEnter hours:");
 scanf("%d",&h);
 printf("\nEnter minute:");
 scanf("%d",&m);
 printf("\nEnter second:");
 scanf("%d",&s);

 if(h<=24&&m<=60&&s<=60)
    printf("\nTime is valid:");
 else
    printf("\nTime is not valid:");

 getch();
}
/*

Enter the time                                                                 
Enter hours:22                                                                 
                                                                               
Enter minute:55                                                                
                                                                               
Enter second:33                                                                
                                                                               
Time is valid                                                                  
Enter the time                                                                 
Enter hours:26                                                                 
                                                                               
Enter minute:33                                                                
                                                                               
Enter second:33

hours is invalid:
Enter the time
Enter hours:22

Enter minute:61

Enter second:33

Minute is invalid:
*/
  3]Accept any year as input through the keyboard.write a program
  to check whether the year is a leap year or not.

#include<stdio.h>
#include<conio.h>

void main()
{
 int yr;
 clrscr();
 printf("\nEnter the year:");
 scanf("%d",&yr);

 if(yr%4==0 && !(yr%100==0))
    printf("\n%d year is leap year :",yr);
 else
    printf("\n%d year is not leap year:",yr);

 getch();
}
/*
Enter the year:2017
                                                                               
2017 year is not leap year:                                                    
Enter the year:2018                                                            
                                                                               
2018 year is not leap year:                                                    
Enter the year:2019                                                            
                                                                               
2019 year is not leap year:                                                    
Enter the year:2020                                                            
                                                                               
2020 year is leap year :                                                       
*/
  4] Accept three sides of triangle as input,and print whether
  the triangle is valid or not.(hint:the triangle id valid if the sum
  of each of the two sides is greater than the third side )

#include<stdio.h>
#include<conio.h>

void main()
{
 int a,b,c;
 clrscr();

 printf("\nEnter the sides of ABC triangle:");
 printf("\nEnter the  AB lenght in cm:");
 scanf("%d",&a);
 printf("\nEnter the BC lenght in cm:");
 scanf("%d",&b);
 printf("\nEnter the Ac lenght in cm:");
 scanf("%d",&c);

 if((a+b)>c)
   printf("\nABC is valid triangle:");
 else
   printf("\nABC is not valid triangle:");

 getch();
}
/*

Enter the sides of ABC triangle:
Enter the  AB lenght in cm:3

Enter the BC lenght in cm:5

Enter the Ac lenght in cm:6

ABC is valid triangle:

Enter the sides of ABC triangle:
Enter the  AB lenght in cm:0

Enter the BC lenght in cm:-2

Enter the Ac lenght in cm:
5

ABC is not valid triangle:
 */
 5] Accept the X and Y co-ordinate of a point and find
  the quadrant in which the point lies.

#include<stdio.h>
#include<conio.h>

void main()
{
 int x1,y1,x2,y2;
 clrscr();

 printf("\nEnter Point A co-ordinate:");
 printf("\nEnter X co-ordinate:");
 scanf("%d",&x1);
 printf("\nEnter Y co-ordinate:");
 scanf("%d",&y1);
 printf("\nEnter Point B co-ordinate:");
 printf("\nEnter X co-ordinate:");
 scanf("%d",&x2);
 printf("\nEnter the y co-ordinate:");
 scanf("%d",&y2);

 getch();
}
/*

Enter Point A co-ordinate:                                                     
Enter X co-ordinate:1                                                          
                                                                               
Enter Y co-ordinate:2                                                          
                                                                               
Quadrant I:                                                                    
Enter Point A co-ordinate:                                                     
Enter X co-ordinate:-1

Enter Y co-ordinate:2

Quadrant II:
Enter Point A co-ordinate:
Enter X co-ordinate:-1

Enter Y co-ordinate:-4

First Quadrant: III
Enter Point A co-ordinate:
Enter X co-ordinate:4

Enter Y co-ordinate:-3

First Quadrant:IV

Enter Point A co-ordinate:
Enter X co-ordinate:0

Enter Y co-ordinate:0

Origin:
*/
/*Lab Course:1 Exercise:2 Set:B
  Example:6-Write a program to roots of a quadratic equation.
  Consider all possible cases.
*/

#include<stdio.h>
#include<conio.h>
#include<math .h>
void main()
{
 double r1,r2,a,b,c,dm,img,realpart;
// clrscr();
 printf("\nEnter the cofficent a,b,c:");
 scanf("%lf%lf%lf",&a,&b,&c);
 dm=b*b-4*a*c;
 if(dm>0)
   {
    r1=-b+sqrt(dm);
    r2=-b-sqrt(dm);
    printf("\nroot1=%lf\nroot2=%lf",r1,r2);
   }
 else if(dm==0)
    {
     r1=r2=-b/2*a;
     printf("\nroot1=root2=%lf",r1);
    }
 else if(dm<0)
    {
     realpart=-b/2*a;
     img=sqrt(-dm)/2*a;
     printf("\nroot1=%lf+i%lf\nroot2=%lf-i%lf",realpart,img,realpart,img);
    }

 getch();
}
/*
Enter the cofficent a,b,c:1

1
1

root1=-0.500000+i0.866025
root2=-0.500000-i0.866025
Enter the cofficent a,b,c:1
4

1

root1=-0.535898
root2=-7.464102
Enter the cofficent a,b,c:1
2
1

root1=root2=-1.000000

*/
  Example:7-Accept the cost price and seeling price from the keyboard.
  Find out if the seller has made a profit or loss and display
  how much profit or loss has been made.

#include<stdio.h>
#include<conio.h>
void main()
{
 int cp,sp,x;
// clrscr();
 printf("\nEnter Cost prize:");
 scanf("%d",&cp);
 printf("\nEnter Seeling prize:");
 scanf("%d",&sp);
 x=sp-cp;
 if(x>0)
    printf("\nProfit is %d",x);
 else
    printf("\nLoss is %d",x);
 getch();
}
/*
Enter Cost prize:10                                                            
Enter Seeling prize:12                                                         
Profit is 2                                                                    
Enter Cost prize:20                                                            
Enter Seeling prize:15                                                         
 Loss is -5                                                                     
 */
SET C Write programs to solve the following problems
/*
1. Write a program to accept marks for three subjects and find the total marks secured ,
average and also display the class obtained. (Class I – above __%, class II – ___% to ___%,
pass class – ___% to ___% and fail otherwise)
*/

#include<stdio.h>
#include<conio.h>
void main()
{
 float m1,m2,m3,total,classs,avg ;
 clrscr();
 printf("\nEnter 3 subject marks:");
 scanf("%f%f%f",&m1,&m2,&m3);
 total=m1+m2+m3;
 printf("\nTotal marks: %f",total);
 avg=total*100/300;
 printf("\nAvg : %f%",avg);
 if(avg>=70 && avg<=100)
    printf("\nFirst Class with distinction.");
 else if(avg>=60 &&avg<70)
         printf("\n First Class");
      else if(avg>=55 && avg<60)
              printf(" Higher second class");
            else if(avg>=50 &&avg<55)
                    printf("second class");
                 else if(avg>=40 && avg<50)
                         printf("\nPass CLass");
              else
             printf("\nFail");

 getch();
}
/*

Enter 3 subject marks:40                                                       
40                                                                             
40                                                                             
                                                                               
Total marks: 120.000000                                                        
Avg : 40.000000%                                                               
Pass CLass                                                                     
Enter 3 subject marks:55                                                       
55                                                                             
55                                                                             
                                                                               
Total marks: 165.000000                                                        
Avg : 55.000000% Higher second class                                           
Enter 3 subject marks:45                                                       
89                                                                             
50                                                                             
                                                                               
Total marks: 184.000000                                                        
Avg : 61.333332%
 First Class
*/

Questions

  Exercise 1 Set A . Apply all the three program development steps for the following examples.  1. Accept dimensions of a cylinder and p...