0% found this document useful (0 votes)
4 views13 pages

Pop 3

The document provides an overview of input and output devices of computers, detailing specific examples such as keyboards, mice, scanners, monitors, and printers. It also includes programming examples in C, explaining concepts like simple and compound interest calculations, nested if statements, and the use of bitwise and ternary operators. Additionally, it covers the syntax and usage of printf and scanf functions for formatted input and output.

Uploaded by

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

Pop 3

The document provides an overview of input and output devices of computers, detailing specific examples such as keyboards, mice, scanners, monitors, and printers. It also includes programming examples in C, explaining concepts like simple and compound interest calculations, nested if statements, and the use of bitwise and ternary operators. Additionally, it covers the syntax and usage of printf and scanf functions for formatted input and output.

Uploaded by

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

IAT1-Solutions

1.Briefly explain any 5 input and 5 output devices of computer.

Input device helps the computer to receive instructions from users.

The output device helps the computer to produce or display the information to the users.

Input devices
External devices that are connected tom CPU using which data or commands can be entered into
computer.

The various input devices are,

keyboard
pointing devices
scanners

keyboard:
the primary input device used in all computers.It has group of switches associated with a character.
User can type data or the commands by using keyboard.Keyboard has around 101 keys.
Keyboard layout is called querty.

Pointing devices

It’s an input devices using which we can control the movement of pointer on nthe screen.
We can communicate with the computer by pointing any desired location, we can select the items on the
screen.
Mouse

Hand helding pointing devices.


Used to control the movement of the ppointer on the screen.
It is connected to computer using cable.
Top of the mouse has 2 buttons along with a scroll wheel.
If we move the mouse to left and right.

Scanner

Data scanning devices/optical devices

The device which ues light as source of input for detecting or recognizing variolus things.
It can read characters,marks codes,etc.
Eg:
barcode reader
optical recognition
magnetic ink character

Output Devices
Output Devices are the devices that show us the result after giving the input to a computer system. Output
can be of many different forms like image, graphic audio, video, etc. Some of the output devices are
described below.
Monitor
Monitors, also known as Visual Display Units (VDUs), are a computer’s primary output device. It creates
images by arranging small dots, known as pixels, in a rectangular pattern. The amount of pixels
determines the image’s sharpness.
The two kinds of viewing screens used for monitors are described below.
Cathode-Ray Tube (CRT) Monitor: Pixels are minuscule visual elements that make up a CRT
display. The higher the image quality or resolution, the smaller the pixels.
Flat-Panel Display Monitor: In comparison to the CRT, a flat-panel display is a type of video
display with less volume, weight, and power consumption. They can be hung on the wall or worn
on the wrist.
Flat-panel displays are currently used in calculators, video games, monitors, laptop computers, and
graphical displays.
Printers

output devices that allow you to print information on paper. There are certain types of printers which are
described below.

Impact Printers
Character Printers
Line Printers
Non-Impact Printers
Laser Printers
Inkjet Printers
Plotters
A plotter is large format inkjet printer to produce high quality color graphics using electronic charges.
A plotter is a printer that interprets commands from a computer to make line drawings on paper with one
or more automated pens. Unlike a regular printer, the plotter can draw continuous point-to-point lines
directly from vector graphics files or commands.
It is also used to print banners.
Size will be very large.
Digitizer
It's an input device which converts analog information into a digital form. Digitizer can convert a signal
from the television camera into a series of numbers that could be stored in a computer. They can be used
by the computer to create a picture of whatever the camera had been pointed at.
Digitizer is also known as Tablet or Graphics Tablet because it converts graphics and pictorial data into
binary inputs. A graphic tablet as digitizer is used for doing fine works of drawing and images
manipulation applications.

2. Write the output of the followings;


int a,b; float x; a=4; b=5; x=(float)b/a; printf(“%f”,x);

ans:1.250000
printf(“%0.3f\n”, 20/3.0); 1 M

ans:6.667
Write equivalent expressions in C: 2 M

(-b+sqrt((b*b)-((4*a*c)))/(2*a)

3.Draw the flowchart and write algorithm and write Program to compute simple and
compound interest.

#include<stdio.h>
void main()
{
int p,r,t;
float i;
printf("Enter the Principal, Rate and Time\n");
scanf("%d %d %d",&p,&r,&t);

/*Formula for calculating simple interest*/

i=p*r*t/100;

printf("simple interest is : %f",i);


/*Formula for calculating
Compound Interest
*/

CI = p*pow((1+r/100),t);
printf("Compound interest is : %f\n", CI);
return 0;
}

output

Enter the Principal, Rate and Time


1000
7
8
simple interest is : 560.00000

Compound interest is: 1718.186890

Algorithm

start.
Declaration of variable with their data type, like :- int p, r, t,CI; float I;
Input the value in variable
perform SI=(p*r*t)/100;
CI = p*pow((1+r/100),t);
printf( ) called to print value of CI
Stop
4.Explain structure of a C program with example program.

Structure of C Language program

1 ) Comment line
2) Preprocessor directive
3 ) Global variable declaration
4) main function( )
{ Local variables;
Statements;
}
User defined function
}
}
1) Preprocessor directive & header file // #include<stdio.h>
2) Global variable declaration // variable that is used throughout the program, for all the
modules/blocks of the program.
3) main function
// two ways main function can be written .
void main()/ main()/int main()
{
Local variable declaration
Statements  input , processing, output
Return statement
}

// w.r.to main function

4) User defined function // user only defines the steps of the function and also defines the name
of the function
5) Comment lines // to explain the meaning of the statement... syntax: //comment or
/*comment*/

Comment line: It indicates the purpose of the program. It is represented as


/ * ... ... ... ... ... ... ... ... ... ... ... . . * /
Comment line is used for increasing the readability of the program. It is useful in
explaining the program and generally used for documentation. It is enclosed
within the decimetres. Comment line can be single or multiple line but should not
be nested. It can be anywhere in the program except inside string constant &
character constant.

Preprocessor Directive: #include<stdio.h> tells the compiler to include information


about the standard input/output library. It is also used in symbolic constant such as
#define PI 3.14(value). The stdio.h (standard input output header file) contains
definition &declaration of system defined function such as printf( ), scanf( ) etc.
Generally printf() function used to display and scanf() function used to read value
Global Declaration: This is the section where variable are declared globally
so that it can be access by all the functions used in the program. And it is
generally declared outside the function.

main(): It is the user defined function and every function has one main()
function from where actually program is started and it is encloses within the pair
of curly braces. The main( ) function can be anywhere in the program , but in
general practice it is placed in the first position.
Syntax :
main()
{ ........ ........ ........
} int main( )
{ return 0;
}
The main( ) function return
value when it declared by data
type as:

The main function does not return any value when void (means null/empty) is
used as return type.

void main(void ) orvoid main()

{
printf (“C language”);

Output: C language

5.Write syntax for nested –if statement? Draw the flowchart and write a C
program to find largest of three numbers using nested if statements?

Syntax

if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
else
{
// Executes when condition2 is false
}

program
#include <stdio.h>

int main() {

double n1, n2, n3;

printf("Enter three numbers: ");


scanf("%lf %lf %lf", &n1, &n2, &n3);

// outer if statement
if (n1 >= n2) {

// inner if...else
if (n1 >= n3)
printf("%.2lf is the largest number.", n1);
else
printf("%.2lf is the largest number.", n3);
}

// outer else statement


else {

// inner if...else
if (n2 >= n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
}

return 0;
}

output
Enter three numbers: -4.5
3.9
5.6
5.60 is the largest number.
5.KSRTC Transport Company charges for the parcels from Kolar to Bangalore or
vice-versa as per the given tariff:

Weight charges
Upto 10kg Rs.20 per kg
For next 20 kg Rs.10 per kg
For next 20 kg Rs.8 per kg
More than 50 kg Rs.5 per kg
Write a program to calculate the charge for a parcel taking the weight of parcel as input.

#include<stdio.h>
#include<conio.h>
void main()
{

int w;
float c=0;
printf("Enter the weight of parcel");
scanf("%d",&w);
if(w<=10)

c=w*20;

if((w>10)&&(w<=30))

c=200+(w-10)*10;

if((w>30)&&(w<=50))

c=200+200+(w-30)*8;

if(w>50)

c=200+200+160+(w-50)*5;

printf("The weight of parcel %d",w);

printf("The weight of parcel %f",c);


}

output
--------

enter the weight of parcel:200


weight of parcel 200
cahrge of parcel 1310.000000

6.Draw a flowchart and write a C program to convert Fahrenheit temperature to


Centigrade.
#include<stdio.h>
int main()
{ float Fahrenheit, Celsius;
Fahrenheit = 64;
Celsius = ((Fahrenheit-32)*5)/9;
printf("\n\n Temperature in Celsius is : %f",Celsius);
return (0);
}
output
Enter Fahrenheit:

100
Celsius: 37.777779

7. Explain the following operators with example

a) Bitwise Operators.
b) Ternary Operator.

Bitwise Operators

Bitwise operator works on bits and performs bit-by-bit operation. Bitwise


operators are used in bit level programming. These operators can
operate upon int and char but not on float and double.
showbits( ) function can be used to display the binary representation of
any integer or character value.
Bit wise operators in C language are:

& (bitwise AND),


| (bitwise OR),
~ (bitwise OR),
^ (XOR),
<< (left shift)
>> (right shift).
Bitwise Operators
1.The & (bitwise AND) in C takes two numbers as operands and does AND on every bit of
two numbers. The result of AND is 1 only if both bits are 1.
2. The | (bitwise OR) in C takes two numbers as operands and does OR on every bit of two
numbers. The result of OR is 1 if any of the two bits is 1.
3. The ^ (bitwise XOR) in C takes two numbers as operands and does XOR on every bit of two
numbers. The result of XOR is 1 if the two bits are different.
4. The << (left shift) in C takes two numbers, the left shifts the bits of the first operand, and the second
operand decides the number of places to shift.
5.The >> (right shift) in C takes two numbers, right shifts the bits of the first operand, and the second
operand decides the number of places to shift.
6. The ~ (bitwise NOT) in C takes one number and inverts all bits of it.

The truth tables for &, |, and ^ are as follows:

p q p&q p|q p^q


0 0 0 0 0
01 0 1 1
10 0 1 1
11 1 1 0

Binary Right shift(>>) Operator

A=60

Binary representation: 00111100

A= A>>1

After (A>>1) Binary representation: 00011110

A=2+4+8+16=30

Ans: A=30 // (A/2)


Binary Left shift(<< ) Operator

A=60

Binary representation: 00111100


A= A<<1

After (A<<1) Binary representation: 01111000

A=8+16+32+64=120

Ans: A=120 // (A*2)

/ C Program to demonstrate use of bitwise


operators
#include <stdio.h>
intmain()
{
// a = 5(00000101), b = 9(00001001)
unsigned chara = 5, b = 9;

// The result is 00000001


printf("a = %d, b = %d\n", a, b);
printf("a&b = %d\n", a &b);

// The result is 00001101


printf("a|b = %d\n", a | b);

// The result is 00001100


printf("a^b = %d\n", a ^ b);

// The result is 11111010


printf("~a = %d\n", a = ~a);

// The result is 00010010


printf("b<<1 = %d\n", b <<1);

// The result is 00000100


printf("b>>1 = %d\n", b >>1);

return0;

}
Output

a = 5, b = 9
a & b = 1
a | b = 13
a ^ b = 12
~a = -6
b << 1 = 18
b >> 1 = 4

Conditional Operators (? :) / Ternary operator

Conditional operators are used in decision making in C programming, i.e,


executes different statements according to test condition whether it is either true or
false.

Syntax of conditional operators

(Conditional expression) ? (expression1) : (expression2)


If the conditional expression is evaluated to true , then expression1 is executed.
If the conditional expression is evaluated to false , then expression2 is executed

#include <stdio.h>

int main() {
int age;

// take input from users


printf("Enter your age: ");
scanf("%d", &age);

// ternary operator to find if a person can vote or not


(age >= 18) ? printf("You can vote") : printf("You cannot vote");

return 0;
}

Enter your age: 12


You cannot vote

In the above example, we have used a ternary operator that checks whether a user can vote or not based on
the input value. Here,
age >= 18 - test condition that checks if input value is greater or equal to 18
printf("You can vote") - expression1 that is executed if condition is true
printf("You cannot vote") - expression2 that is executed if condition is false
Here, the user inputs 12, so the condition becomes false. Hence, we get You cannot vote as output.
8. Explain syntax with examples of printf() and scanf() statements. How string
with blanks can be accepted by gets() and scanf() statements? Write syntax
with examples.

C language supports two formatting functions : printf () and scanf ().


printf() is used to convert text data stored in the program onto text stream for o/p to the
monitor.
scanf() is used to convert text stream coming from keyboard to data values and stores them in
program variables.

These are called as formatted Input and output functions because they have special format to
read and write The text from streams and then converting them into binary stream.

Syntax of printf() : printf ( “ control string” , var1, var2 .....var n).


Printf (“Hello welcome to C program”)
Printf ( “ %d %d %f ”

, a , b , c), where a and b are integer variables and c is float variable.

%d and %f are known as format specifiers.

Syntax of scanf() : scanf ( “ Control string” , & var1, & var2, ........,& var n).
Format specifiers : For integer variables------ %d
For float variables--------%f
For character variables ------- %c
Input Statements ( reading input)
scanf()
// built-in/standard /formattedinputfunction to read input
syntax: scanf(“format specifier”

, address of input variable);

//formatspecifier:int-%d,float-%f,char-%c
//& - address operator

Example: scanf(“%d”, &a);


Output Statement ( displaying output, displaying a message)
printf()

i) To display a message

Syntax: printf(“message”); //displaying any message

ii) To display a value

Syntax: printf(“format specifier”, name of variable holding the value);


//format specifier: int-%d, float-%f, char-%c
Example: printf(“%d”, a);
// displaying integer value which is stored inside variable ‘a’

Output Statement ( displaying output, displaying a message)


printf()

i) To display a message

Syntax: printf(“message”); //displaying any message

ii) To display a value

Syntax: printf(“format specifier”, name of variable holding the value);


//format specifier: int-%d, float-%f, char-%c
Example: printf(“%d”, a);
// displaying integer value which is stored inside variable ‘a’

Output Statement ( displaying output, displaying a message)


printf()

i) To display a message

Syntax: printf(“message”); //displaying any message

ii) To display a value

Syntax: printf(“format specifier”, name of variable holding the value);


//format specifier: int-%d, float-%f, char-%c
Example: printf(“%d”, a);
// displaying integer value which is stored inside variable ‘a’
scanf() function can read multiple values of different data types. However on other hand get() function
will only get character string data.

scanf() reads input until it encounters whitespace, newline or End Of File(EOF) whereas gets() reads input
until it encounters newline or End Of File(EOF),
gets() does not stop reading input when it encounters whitespace instead it takes whitespace as a string.

Eg:1
#include <stdio.h>
int main()
{
char str[20];
gets(str);
printf("%s", str);
return 0;
}
output
CMRIT UNIVERSITY
CMRIT UNIVERSITY

eg:2
#include <stdio.h>
int main()
{
char str[20];
scanf("%[^\n]%*c", str);
printf("%s", str);

return 0;
}

output
section sem
section sem

note:^\n tells to take input until newline doesn’t get encountered.


Then, with this %*c, it reads newline character and here used *
indicates that this newline character is discarded.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy