0% found this document useful (0 votes)
11 views

EXP1 Writeup-1

Cp 1

Uploaded by

chiragmore0077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

EXP1 Writeup-1

Cp 1

Uploaded by

chiragmore0077
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT NUMBER: 1

Date of Performance :

Date of Submission :
AIM: Write programs to demonstrate different operators and Input Output operations in C.
1a. Write a C program to print student details.
1b. Write a C program to perform Arithmetic Operations.
1c. Write a C program to demonstrate unary, binary, bitwise, relational and logical operators.
SOFTWARE REQUIREMENT: Turbo C
THEORY:
In C, data input and output are typically handled using standard library functions provided in <stdio.h>. These functions allow you to read data from the user (input) and display

data to the user (output). Below are some of the most commonly used functions for input and output in C:
1.
Standard Input and Output:

o C provides standard functions to perform input and output operations.

o These operations are typically done via the console.

2.
Header File:

o The <stdio.h> header file must be included to use standard input/output functions.

3.
Common Functions:

o printf: For formatted output.

o scanf: For formatted input.

o getchar: For reading a single character.

o putchar: For writing a single character.

o gets: For reading a string

o puts: For writing a string.

4.
Format Specifiers:

o Used in printf and scanf to define the type of data being handled.

o Examples: %d (integer), %f (float), %c (character), %s (string).

Syntax

1.
printf: For formatted output.

printf("format string", argument_list);

Example:

printf("Value of x is %d\n", x);

2.
scanf: For formatted input.

scanf("format string", &variable);

Example:

scanf("%d", &x);

3.
getchar: To read a single character.

char c = getchar();
Example:

char c = getchar();

4.
putchar: To write a single character.

putchar(character);

Example:

putchar('A');

5.
gets: To read a string.

char[] gets(char[]);

Example:

char s[30];

gets(s);

6.
puts: To write a string.

puts(string);

Example:

puts("Hello, World!");

7. getch() also reads a single character from the keyboard

getch() method pauses the Output Console until a key is pressed.

Format Specifiers

● %d: Integer

● %f: Float

● %c: Character

● %s: String

Operators:
1.
Arithmetic Operators

Operator Description Example


+ Addition a + b

- Subtraction a - b

* Multiplication a * b

/ Division a / b

% Modulus (remainder) a % b

2. Relational Operators

Operator Description Example


== Equal to a == b

!= Not equal to a != b

> Greater than a > b

< Less than a < b

>= Greater than or equal to a >= b

<= Less than or equal to a <= b


3. Logical Operators

Operator Description Example


&& Logical AND (a > 0) && (b > 0)

|| Logical OR (a > 0) || (b > 0)

! Logical NOT !(a > 0)

4. Bitwise Operators

Operator Description Example


& Bitwise AND a & b

| Bitwise OR ` a|b
^ Bitwise XOR a ^ b

~ Bitwise NOT ~a

<< Left shift a << 2

>> Right shift a >> 2

5. Assignment Operators

Operator Description Example


= Assign a = b

+= Add and assign a += b

-= Subtract and assign a -= b

*= Multiply and assign a *= b

/= Divide and assign a /= b

%= Modulus and assign a %= b

6. Unary Operators

Operator Description Example


++ Increment ++a or a++
-- Decrement --a or a--
+ Unary plus (indicates positive value) +a

- Unary minus (negation) -a

Experiment 1
AIM: Write program to demonstrate different operators and Input Output operations in C.
1a. Write a C program to print student details.
1b. Write a C program to perform Arithmetic Operations.
1c. Write a C program to demonstrate unary, binary, bitwise, relational and logical operators.
1a. Write a C program to print student details.
#include<stdio.h>
void main ()
{
char name[30];
int rno;
char div[10];
printf("Enter your name: ");
scanf("%s",name);
printf("enter your division (A/B/C): ");
scanf("%s",div);
printf("Enter your roll number:" );
scanf("%d", &rno);
puts("\nStudent Information");
printf("Entered Name: %s\n",name);
printf("Entered division: %s\n",div);
printf("Entered RollNo: %d",rno);
}
Output:

1b. Write a C program to perform Arithmetic Operations.


#include <stdio.h>
void main()
{
int num1,num2;
int add,diff,prod,rem;
float division;
printf("Enter first number:");
scanf("%d",&num1);
printf("Enter second number:");
scanf("%d",&num2);
add=num1+num2;
diff=num1-num2;
prod=num1*num2;
division=(float)num1/num2;
rem=num1%num2;
printf("Addition = %d",add);
printf("\nSubtraction = %d",diff);
printf("\nMultiplication = %d",prod);
printf("\nDivision = %.2f",division);
printf("\nRemainder = %d",rem);
}
Output:
1c. Write a C program to demonstrate unary, binary, bitwise, relational and logical operators.
#include <stdio.h>
void main()
{
int a = 10, b = 5;
puts("unary operation");
printf("-a = %d",-a);
printf("\nIncrement operator a++ : %d",a++);
printf("\nIncrement operator ++a : %d",++a);
printf("\nDecrement operator a-- : %d",a--);
printf("\nDecrement operator --a : %d",--a);
printf("\nAssignment operator");
a+=b;
printf("\nvalue of a+= :%d",a );
b*=b;
printf("\nvalue of b :%d",b );
puts("\n Relational operators");
printf("a<b returns %d", a<b);
printf("\na>b returns %d", a>b);
// Similarly try other relational operator
puts("\n Logical operators");
printf("Result of logical AND: %d", a<b && b<0 );
printf("\nResult of logical OR: %d", a<b || b<0 );
printf("\nResult of logical NOT: %d", !(a<b || b<0));
puts("Bitwise operator");
printf("Result of Bitwise & :%d ",a&b);
printf("Result of Bitwise | :%d ",a|b);
// Similarly try other bitwise operator
}
Output:

CONCLUSION: The programs has been successfully executed.


Sign & Remark
R1 R2 R3 R4 R5 Total Signature

(3 Marks) (3 Marks) (3 Marks) (3 Mark) (3 Mark) (15 Marks)

You might also like