30.12.20

C PROGRAM TO PERFORM ALL RELATIONAL OPERATORS AVAILABLE IN C

    #include<stdio.h>

int main()

{

int m,n;

printf("Enter any two values");

scanf("%d%d",&m,&n);

if(m<n)

{

printf("%d is greater than %d",m,n);

}

else if(m<n)

{

printf("%d is less than %d",m,n);

}

else if(m==n)

{

printf("%d is equal to %d",m,n);

}


return 0;

OUTPUT:

Enter any two values 40 20

40 is greater than 20


C PROGRAM TO CHECK THE GIVEN YEAR IS LEAP YEAR OR NOT

 

#include <stdio.h>

#include <stdlib.h>

 

 

int main()

{

 

int year;

printf("enter a year");

scanf("%d",&year);

if(year%400==0)

    {

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

}

else if(year%100==0)

{

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

    }

    else if(year%4==0)

    {

 

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

    }

    else

    {

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

    }

return 0;

}

OUTPUT

Enter a year 2032

2032 is a leap year

C PROGRAM TO PERFORM ALL BITWISE OPERATORS AVAILABLE IN C

#include <stdio.h>

#include <stdlib.h>

 

 

int main()

{

 

int a,b;

int c=0;

printf("Enter a and b value ");

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

c=a&b;

printf("value of c is %d\n",c);

 

c=a|b;

printf("value of c is %d\n",c);

c=a^b;

printf("value of c is %d\n",c);

c=a<<2;

printf("value of c is %d\n",c);

c=a>>2;

printf("value of c is %d\n",c);

    return 0;

}

OUTPUT

Enter a and b value 60 13

Value of c is 12

Value of c is 61

Value of c is 49

Value of c is 240

Value of c is 15

c program to perform all increment and decrement operators available in c

 

INCREMENT OPERATOR

#include <stdio.h>

#include <stdlib.h>

 

 

int main()

{

 

int i=1;

while(i<10)

{

    printf("%d",i);

    i++;

    }

    return 0;

}

OUTPUT

123456789

DECREMENT OPERATOR

#include <stdio.h>

#include <stdlib.h>

 

 

int main()

{

 

int i=20;

while(i>10)

{

    printf("%d",i);

    i--;

    }

    return 0;

}

OUTPUT

20191817161514131211

C PROGRAM TO PERFORM ALL ASSIGNMENT OPERATORS AVAILABLE in c

#include <stdio.h>

#include <stdlib.h>

 

 

int main()

{

int a,c;

printf("enter a  value");

scanf("%d",&a);

c=a;

printf("value of c with operator = is %d\n",c);

c += a;

printf("value of c with operator += is %d\n",c);

c-=a;

printf("value of c with operator -= is %d\n",c);

c*=a;

printf("value of c with operator *= is %d\n",c);

c/=a;

printf("value of c with operator /= is %d\n",c);

c=200;

c%=a;

printf("value of c with operator %= is %d\n",c);

c<<=a;

printf("value of c with operator <<= is %d\n",c);

c>>=a;

printf("value of c with operator >>= is %d\n",c);

c&=a;

printf("value of c with operator &=  is %d\n",c);

c^=a;

printf("value of c with operator ^= is %d\n",c);

c|=a;

printf("value of c with operator |= = is %d\n",c);

 

    return 0;

}

OUTPUT

Enter a value 21

Value of c with operator = is 21

Value of c with operator += is 42

Value of c with operator -= is 21

Value of c with operator *= is 441

Value of c with operator /= is 21

Value of c with operator %= is 11

Value of c with operator <<= is 23068672

Value of c with operator >>= is 11

Value of c with operator &= is 1

Value of c with operator ^= is 20

Value of c with operator |= is 21

 


C PROGRAM TO PERFORM ALL LOGICAL OPERATORS AVAILABLE IN C

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

int a,b,c;

printf("enter a and b values");

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

if(a&&b)

{

    printf("condition 1 is true ");

}

if(a||b)

{

    printf("condition 2 is true");

}

  return 0;

}

 

OUTPUT

Enter a and b values 0 10

Condition 2 is true

 


C PROGRAM TO PRINT SIZE ,MINIMUM VALUE,MAXIMUM VALUE AND PRECISION VALUE OF THE FLOAT USING SIZEOF(),FLT_MIN,FLT_MAX AND FLT_DIG.

 

#include <stdio.h>

#include <float.h>

 

int main()

{

    float a;

printf("the min value of float is %e\n",FLT_MIN);

printf("the max value of float is %e\n",FLT_MAX);

printf("the number of digits in the number is %e\n",FLT_DIG);

printf("the size of float is %lu\n",sizeof f(a));

 

    return 0;

}

OUTPUT

the min value of float is 1.175494e-38

the max value of float is 3.402823e+38

the number of digits in the number is 3.402823e+38

the size of float is 4

c program to the largest of three numbers

#include<stdio.h>

int main()

{

 int a,b,c;

printf("Enter three numbers");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

{

if(a>b)

printf("%d is largest number",a);

else

printf("%d is largest number",c);

}

else

{

if(b>c)

printf("%d is the largest number",b);

else

printf("%d is the largest number",c);

}

return 0;

}

OUTPUT

enter three numbers 10 20 30

30 is the largest number

c program to check the given is positive or negative number

#include<stdio.h>

int main()

{

 int a;

printf("Enter a number");

scanf("%d",&a);

if(a>0)

{

printf("Positive number");

}

else 

{

printf("Negative numbers");

}

return 0;

}

OUTPUT

Enter a number -10

Negative number 

c program to print the largest of two given numbers

#include<stdio.h>

int main()

{

int a,b;

printf("Enter two values);

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

if(a>b)

{

printf("%d is largest number",a);

}

else

{

printf("%d is largest number ",b);

}

return 0;

}

OUTPUT:

Enter two value 20 60

60 is largest number 

c program of all arthmetic operators available in c

#include<stdio.h>

int main()

{

 int a,b,add,sub,mul,div,mod;

printf("Enter a and b values):

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

add=a+b;

sub=a-b;

mul=a*b;

div=a/b;

mod=a%b;

printf("Add= %d\n",add);

printf("Sub= %d\n",sub);

printf("Mul= %d\n",mul);

printf("Div= %d\n",div);

printf("Mod= %d\n",mod);

return 0;

}

OUTPUT

Enter a and b values 40 20

Add=60

Sub=20

Mul=800

Div=2

Mod=0

c program to convert fahrenheit to celsius and celsius to fahrenheit

 CELSIUS TO FAHRENHEIT:

#include<stdio.h>

int main()

{

float cen,fah;

printf("Enter temperature in centigrade scale:");

scanf("%f",&cen);

fah=9/5.0*cen+32;

printf("Equivalent fahrenheit scale value is %f",fah);

return 0;

}

OUTPUT

Enter temperature in centigrade 27.5

Equivalent fahrenheit scale value is 81.5

FAHRENHEIT TO CELSIUS 

#include<stdio.h>

int main()

{

float cen,fah;

printf("Enter temperature in fahrenheit scale:");

scanf("%f",&fah);

cen=(fah-32)/1.8;

printf("Equivalent centigrade scale value is %f",cen);

return 0;

}

OUTPUT

Enter temperature in fahrenheit scale 32

Equivalent centigrade scale value is 0

c program to print the area and perimeter of the reactangle

PROGRAM

#include<stdio.h>

int main()

{

 int l,b,area,perimeter;

printf("enter length and breadth of the rectangle");

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

area=l*b;

perimeter=2*(l+b);

printf("Area=%d,Perimeter =%d",area,perimeter");

return 0;

}

OUTPUT

enter length and breadth of the recatangle  3 2

Area=6,Perimeter=10

c program to print the size of the datatype using sizeof()

 SWAPPING WITHOUT USING THIRD VARIABLE

PROGRAM:
#include<stdio.h>
int main()
{
printf("size of char =%d\n",sizeof(char));
printf("size of short =%d\n",sizeof(short));
printf("size of int=%d\n",sizeof(int));
printf("size of long =%d\n",sizeof(long));
printf("size of float =%d\n",sizeof(float));
printf("size of double =%d\n",sizeof(double));

return 0;
}


OUTPUT:
size of char=1
size of short=2
size of int=4
size of long=4
size of float=4
size of double=8




c program to swap two numbers with and without using third variable

SWAPPING WITHOUT USING THIRD VARIABLE
PROGRAM:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter two values");
scanf("%d%d",&a,&b);
printf("Before Swap a=%d,b=%d",a,b);
{
a=a+b;
b=a-b;
a=a-b;
}
printf("After Swap a=%d,b=%d",a,b);
return 0;
}


OUTPUT:
Enter two values 30 5
Before Swap a=30, b=5
After Swap a=5,b=30



SWAPPING WITH USING THIRD VARIABLE
PROGRAM:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter two values");
scanf("%d%d",&a,&b);
printf("Before Swap a=%d,b=%d",a,b);
{
c=a;
a=b;
b=c;
}
printf("After Swap a=%d,b=%d",a,b);
return 0;
}


OUTPUT:
Enter two values 30 5
Before Swap a=30, b=5
After Swap a=5,b=30

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...