Sunday, August 15, 2021

Greater of three number in C

 Write a program to find greater of three number using nested if else



#include<stdio.h>

int main()
{
int x,y,z;

printf("enter the three number ");
scanf("%d %d %d",&x,&y,&z);
if(x>y && x>z) //Logical operator
{
printf("x is greater");
}
else if(y>x && y>z) //Logical operator
{
printf("y is greater");
}
else if(z>x && z>y) //Logical operator
{
printf("z is greater");
}
else
{
printf("all are equal");
}
return 0;

 

OUTPUT

enter the three number 8
9
15
z is greater

2nd output when u try again with equal number

enter the three number 10
10
10
all are equal

Smaller of two number, Tables in C

 Write a program to print smaller of two number in C

#include<stdio.h>

int main()
{
int x,y;
printf("enter the value of x and y");
scanf("%d %d",&x,&y);
if(x<y)//Relational operator
{
printf("x is Smaller");
}
else
{
printf("y is Smaller");
}
return 0;
}

OUTPUT

enter the value of x and y 5
5
8
x is Smaller 

Write a program to print table using while statement

#include<stdio.h>

int main()
{
int n,i=1;
printf("enter any number");
scanf("%d",&n);
while(i<=10) //Relational operator
{
printf("%d * %d = %d \n",n,i,n*i);
i++;
}
return 0;
}

OUTPUT

enter any number25
25* 1 = 25
25 * 2 = 50
25 * 3 = 75
25 * 4 = 100
25 * 5 = 125
25 * 6 = 150
25 * 7 = 175
25 * 8 = 200
25 * 9 = 225
25 * 10 = 250 

Number equal or not, greater of two numbers in C

Write a program to find equal or not

#include<stdio.h>

int main()
{
int x,y;
printf("enter the value of x and y");
scanf("%d %d",&x,&y);
if(x==y)  //Relational operator
{
printf("x and y are equal");
}
else
{
printf("x and y are not equal"); }
return 0;
}

 OUTPUT             

enter the value of x and y
8
8
x and y are equal

Write a program to find greater of two number


#include<stdio.h>

int main()
{
int x, y;
printf("enter the value of x and y");
scanf("%d %d",&x,&y);
if(x>y) //Relational operator
{
printf("x is greater");
}
else
{
printf("y is greater");
}
return 0;
}

NOTE:- // this sign is used for comment. This is not show in output

 OUTPUT

enter the value of x and y
5
8
y is greater

Sum of first and last digit in C

 Write a program find the sum of first and last digit


#include<stdio.h>

int main()
{
int n, i, sum=0, a;

printf("enter the number ");
scanf("%d",&n);
sum=sum+n%10;
while(n!=0)
{
a=n;
n=n/10;
}
sum=sum+a; //Assignment operator
printf("sum of first and last digit = %d ",sum);
return 0;
}
 OUTPUT

enter the number 54
sum of first and last digit = 9 

Sum of two numbers using increment & decrement in c

Write a program to print sum of two number using increment Operator

 #include<stdio.h>

int main()
{
int a,b,c;
printf("Enter the two number ");
scanf("%d %d",&a, &b);
c=a+b;
printf("\n Sum of two number = %d ",c);
c++; //Increment operator
printf("\n Increment of two number = %d ",c);
return 0;
}
OUTPUT
Enter the two number 8
5
 Sum of two number = 13
 Increment of two number = 14  
 
 

Write a program to print sum of two numbers using Decrement

#include<stdio.h>

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

printf("Enter the two number ");
scanf("%d %d",&a, &b);
c=a+b;
printf("\n sum of two number = %d ",c);
c--; //Decrement operator
printf("\n Decrement of two number = %d ",c);
return 0;

OUTPUT 

Enter the two number 8
4
sum of two number = 12
 Decrement of two number = 11 

Sum, subtract, divide, multiply of two numbers

 

Write a program to print sum in c

 #include<stdio.h>

int b; //Global variable
void main()
{
int a,c; //Local variable

printf("enter the two number ");
scanf("%d %d",&a, &b);
c=a+b;
printf("sum of two number = %d ",c);
return 0;
}


 OUTPUT

enter the two number
5
8
sum of two number = 13 

Write a program to print sum, subtract, multiply, Divide.

#include<stdio.h>

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

printf("Enter the two number ");
scanf("%d %d",&a, &b);
c=a+b;
printf("\n sum of two number = %d ",c);
c=a-b;
printf("\n Subtraction of two number = %d ",c);
c=a*b;
printf("\n Multiplication of two number = %d ",c);
c=a/b;
printf("\n Division of two number = %d ",c);
return 0;
}

OUTPUT

 Enter the two number 10
5

 sum of two number = 15
 Subtraction of two number = 5
 Multiplication of two number = 50
 Division of two number = 2

 

Size of variable in C

 Write a program to find the size of variable

 #include<stdio.h>
int main() {
    int intType;
    float floatType;
    double doubleType;
    char charType;

    // sizeof evaluates the size of a variable
    printf("Size of int: %zu bytes\n", sizeof(intType));
    printf("Size of float: %zu bytes\n", sizeof(floatType));
    printf("Size of double: %zu bytes\n", sizeof(doubleType));
    printf("Size of char: %zu byte\n", sizeof(charType));
    
    return 0;
}

 Fir this program to know you must know Data Type of C

Data Types in C

 #include <stdio.h>      
int main() {
  short a;
  long b;
  long long c;
  long double d;

  printf("size of short = %d bytes\n", sizeof(a));
  printf("size of long = %d bytes\n", sizeof(b));
  printf("size of long long = %d bytes\n", sizeof(c));
  printf("size of long double= %d bytes\n", sizeof(d));
  return 0;

OUTPUT 

size of short = 2 bytes
size of long = 8 bytes
size of long long = 8 bytes
size of long double= 16 bytes

First C Program, size of Integer in C

First Program of C

#include <stdio.h>

int main() {
    // Write C code here
    printf("Hello world");
    
    return 0;

OUTPUT

Hello world 

2) Write a program to find the size of integer datatype

#include<stdio.h>
int main()
{
int x;
printf("value of int = %d ",sizeof (x));
return 0;
}

 OUTPUT

value of int = 4