Nothing Special   »   [go: up one dir, main page]

Practical 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

PPSC C2210C1

PRACTICAL 1
PROGRAM 1
AIM: C program for addition of two numbers.
Code:
#include <stdio.h>
void main() {
int num1= 2324;
int num2= 564;
int sum=num1 + num2;
printf("Kalp \n");
printf("%d",sum);
}

OUTPUT:

PROGRAM 1-B
AIM: C program using Const keyword for addition of two numbers.
Code:
#include <stdio.h>
void main() {
const int num1= 2324;
const int num2= 564;
const int sum=num1 + num2;
printf("Kalp \n");
printf("%d",sum);
}

VEER KALP MANISH 23C23020


PPSC C2210C1

OUTPUT:

PROGRAM 2
AIM: C program using assignment operator.
Code:
#include <stdio.h>
void main()
{
int a = 10;
printf("Value of a is %d\n", a);
a += 10;
printf("Value of a is %d\n", a);
a -= 10;
printf("Value of a is %d\n", a);
a *= 10;
printf("Value of a is %d\n", a);
a /= 10;
printf("Value of a is %d\n", a);
a %= 10;
printf("Value of a is %d\n", a);
printf("Kalp \n");
}
OUTPUT:

VEER KALP MANISH 23C23020


PPSC C2210C1

PROGRAM 3
AIM: C program for increment and decrement.
Code:
#include <stdio.h>
void main()
{
int a = 100;
a++;
int b = 100;
b--;
printf("Value of a after increment is %d\n", a);
printf("Value of b after decrement is %d\n", b);
printf("Kalp \n");
}
OUTPUT:

PROGRAM 4
AIM: Write a c program using ternary operator, ask value from user and
then classify it into even or odd.
Code:
#include <stdio.h>
void main() {
int a=printf("Enter a number to check if its even or odd: ");
scanf("%d",&a);
(a%2==0)?printf("Your number is even"):printf("Your number is odd");
printf("\nKalp");
}
OUTPUT:

VEER KALP MANISH 23C23020


PPSC C2210C1

PROGRAM 5
AIM: Take input from the user and perform bitwise operation.
Code:
#include <stdio.h>
void main() {
int a,b;
printf("enter the value of the operators: ");
scanf("%d%d",&a,&b);
int c=a&b;
int d=a|b;
int e=a^b;
printf("the bitwise operator(AND) for %d and %d is %d",a,b,c);
printf("\nthe bitwise operator(OR) for %d and %d is %d",a,b,d);
printf("\nthe bitwise operator(XOR) for %d and %d is %d",a,b,e);
printf(“\nKalp”);
}
OUTPUT:

VEER KALP MANISH 23C23020


PPSC C2210C1

PROGRAM 6
AIM: Left shift right shift operation.
Code:
#include <stdio.h>
void main() {
int a,b;
printf("enter value to perform operation: ");
scanf("%d",&a);
printf("\nenter value of shift: ");
scanf("%d",&b);
int c=a<<b;
int d=a>>b;
printf("left shift bitwise operator %d << %d = %d",a,b,c);
printf("\nright shift bitwise operator %d << %d = %d",a,b,d);
printf(“\nKalp”);
}

OUTPUT:

VEER KALP MANISH 23C23020

You might also like