SlideShare a Scribd company logo
1 of 19
Download to read offline
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 1
QuestionQuestionQuestionQuestion 1111 Draw the functional block diagram of a Digital Computer and discuss its components in brief.
AnswerAnswerAnswerAnswer
Introduction to digital ComputerIntroduction to digital ComputerIntroduction to digital ComputerIntroduction to digital Computer
ComputerComputerComputerComputer
A computer is an electronic device that accepts data through input devices processes those data and gives
some meaning full information in the form of knowledge through output devices.
Digital ComputerDigital ComputerDigital ComputerDigital Computer
Those Computers, which accepts digits (like name, age, special characters etc.) as input called Digital
Computers.
Digital Computer has following units:Digital Computer has following units:Digital Computer has following units:Digital Computer has following units:
1.1.1.1. Input Unit
2.2.2.2. Central Processing Unit
3.3.3.3. Output Unit
Block diagram of Digital ComputersBlock diagram of Digital ComputersBlock diagram of Digital ComputersBlock diagram of Digital Computers
Digital computer is an electronic device. It comprises of many units. These units work in co ordination with
each other to perform the give task.
CPU
Output UnitProcessing UnitInput Unit
CU
ALU Output UnitInput Unit
Memory
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 2
Input UnitInput UnitInput UnitInput Unit
Computers need to receive data and instruction in order to solve any problem. Therefore we need to input the
data and instructions into the computers. The input unit consists of one or more input devices. Keyboard is the
one of the most commonly used input device. Other commonly used input devices are the mouse, floppy disk
drive, magnetic tape, etc. All the input devices perform the following functions.
Accept the data and instructions from the outside world.
Convert it to a form that the computer can understand.
Supply the converted data to the computer system for further processing.
Output Unit:Output Unit:Output Unit:Output Unit:
The output unit of a computer provides the information and results of a computation to outside world.
Printers, Visual Display Unit (VDU) are the commonly used output devices. Other commonly used output
devices are floppy disk drive, hard disk drive, and magnetic tape drive.
Central Processing UnitCentral Processing UnitCentral Processing UnitCentral Processing Unit
The CPU is like brain performs the following functions:
It performs all calculations.
It takes all decisions.
It controls all units of the computer.
CPU consists of following parts.
Central Processing UnitCentral Processing UnitCentral Processing UnitCentral Processing Unit
Memory UnitMemory UnitMemory UnitMemory Unit Arithmetic UnitArithmetic UnitArithmetic UnitArithmetic Unit Control UnitControl UnitControl UnitControl Unit
Memory UnitMemory UnitMemory UnitMemory Unit
The memory unit of the computer holds data and instructions that are entered through the input unit, before
they are processed. It preserves the intermediate and final results before these are sent to the output devices. It
also saves the data for the later use. The various storage devices of a computer system are divided into two
categories.
1. Primary memory:1. Primary memory:1. Primary memory:1. Primary memory: This memory is generally used to hold the program being currently executed in the
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 3
computer, the data being received from the input unit, the intermediate and final results of the program. The
primary memory is temporary in nature. The data is lost, when the computer is switched off. In order to store
the data permanently, the data has to be transferred to the secondary memory.
The cost of the primary storage is more compared to the secondary storage. Therefore most computers have
limited primary storage capacity.
Primary MemoryPrimary MemoryPrimary MemoryPrimary Memory It is further categorized into two categories:
(i)(i)(i)(i) ROM (Read Only Memory)ROM (Read Only Memory)ROM (Read Only Memory)ROM (Read Only Memory)
(ii)(ii)(ii)(ii) RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory)
(i)(i)(i)(i) ROMROMROMROM Computer cannot write data in it using special devices, instructions are written in it use
instructions are written in it. It is put inside the computer. Since data can only be read ROM it hence
it is called Read Only Memory. ROM physically exists in the form of blank electronic chip.
ROM is further divided into three categories.
(a)(a)(a)(a) PROMPROMPROMPROM
(b)(b)(b)(b) EPROMEPROMEPROMEPROM
(c)(c)(c)(c) EEPROMEEPROMEEPROMEEPROM
(a)(a)(a)(a) PROMPROMPROMPROM Those ROMs in which data once written can be programmable is called
Programmable Read Only Memory.
(b)(b)(b)(b) EPROMEPROMEPROMEPROM In this type of ROM data is written or erase, using ultraviolet rays is called Erasable
Programmable Read Only Memory.
(c)(c)(c)(c) EEPROMEEPROMEEPROMEEPROM This is Electrically Erasable Programmable Read Only Memory. In this data is
erased by electric pulses.
(ii)(ii)(ii)(ii) RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory) it provides both reading and writing facilities. As and when
required, Computer writes data or instructions in it and reads them whenever necessary. This is the
reason this is called Read/Write memory.
The data written in Random Access Memory remains there till the time computer power is on.
As soon as the power goes off data written in RAM gets erased. This is the reason why are also called
Temporary Memory.
2. Secondary memory:2. Secondary memory:2. Secondary memory:2. Secondary memory: It stores several programs, documents, data bases etc. The programs that you run on
the computer are first transferred to the primary memory before it is actually run. Whenever the results are
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 4
saved, again they get stored in the secondary memory. The secondary memory is slower and cheaper than the
primary memory. Some of the commonly used secondary memory devices are Hard disk, CD, etc.
ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit)
All calculations are performed in the Arithmetic Logic Unit (ALU) of the computer. It also does comparison
and takes decision. The ALU can perform basic operations such as addition, subtraction, multiplication,
division, etc and does logic operations viz, >, <, =, 'etc. Whenever calculations are required, the control unit
transfers the data from memory unit to ALU once the computations are done, the results are transferred to the
memory unit by the control unit and then it is send to the output unit for displaying results.
C U (ControlC U (ControlC U (ControlC U (Control Unit)Unit)Unit)Unit)
It controls all other units in the computer. The control unit instructs the input unit, where to store the data
after receiving it from the user. It controls the flow of data and instructions from the storage unit to ALU. It
also controls the flow of results from the ALU to the storage unit. The control unit is generally referred as the
central system of the computer that control and synchronizes its working.
QuestionQuestionQuestionQuestion 2222 Define Algorithm with its characteristics. Draw a flow chart of finding the greatest number
among three numbers.
AnswerAnswerAnswerAnswer
AlgorithmsAlgorithmsAlgorithmsAlgorithms
Logical sequence of steps describe complete solution to solve problem in finite amount of time
A method that can be used by a computer for the solution of a problem.
May involve alternation, iteration or recursion
More than one algorithm possible for the same task
Essential features of an algorithm:Essential features of an algorithm:Essential features of an algorithm:Essential features of an algorithm:
1.1.1.1. Input: The algorithm should take zero or more input.
2.2.2.2. Output: The algorithm should produce one or more outputs.
3.3.3.3. Definiteness: Each and every step of algorithm should be defined unambiguously.
4.4.4.4. Effectiveness: A human should be able to calculate the values involved in the procedure of the
algorithm using paper and pencil.
5.5.5.5. Termination: An algorithm must terminate after a finite number of steps.
/* A/* A/* A/* A flowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and C */*/*/*/
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 5
Question 3Question 3Question 3Question 3 Why “C” is called structured programming language? Explain.
AnswerAnswerAnswerAnswer
C language is called structured programming language because it is based on structured programming
approach.
StructuredStructuredStructuredStructured programming:programming:programming:programming: means the collection of principles and practices that are directed toward
developing correct programs which are easy to maintain and understand. A structured program is
characterized by clarity and simplicity in its logical flow.
The Three important constructs upon which structured programming is built are:
SequenceSequenceSequenceSequence Steps are performed one after the other.
SelectionSelectionSelectionSelection Logic is used to determine the execution of a sequence of steps. For example, if then else
construct.
IterationIterationIterationIteration A set of actions are repeated until a certain condition is met. For example while construct.
The various advantages of structured programmingadvantages of structured programmingadvantages of structured programmingadvantages of structured programming are:
1. Complexity of program reduces.
2. Easy maintenance.
3. Simplified understanding.
4. Reusability of code increases.
5. Testing and debugging become easier.
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 6
QuestionQuestionQuestionQuestion 4444Convert the following: (2.5)
I. (1101101.101)2 to Octal III. (357)8 to Decimal
II. (B678A) 16 to Binary IV. (125)10 to Hexadecimal
AnswerAnswerAnswerAnswer
I. (1101101.101)2 to Octal
001 101 101 . 101
1 5 5 . 5
AnswerAnswerAnswerAnswer ((((155.5155.5155.5155.5)8)8)8)8
I. (B678A) 16 to Binary
B 6 7 8 A
1011 0110 0111 1000 1110
AnswerAnswerAnswerAnswer (1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)2222
II. (357)8 to Decimal
7 * 80
=7
5 * 81
=40
3 * 82
=192
=239=239=239=239
AnswerAnswerAnswerAnswer (239)(239)(239)(239)10101010
III. (125)10 to Hexadecimal
16|125
16|7 13 >D
16|0 7
AnswerAnswerAnswerAnswer (7(7(7(7DDDD))))16161616
QuestionQuestionQuestionQuestion 5555 What are Translators? Why we need translators? Explain with reasons.
AnswerAnswerAnswerAnswer
Language TranslatorLanguage TranslatorLanguage TranslatorLanguage Translator
Translator – A translator is a program that translates our source code written in high level language (C
program) in machine code.
Source Code
Translator
Machine Code
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 7
Why do we need languageWhy do we need languageWhy do we need languageWhy do we need language translator?translator?translator?translator?
Computer can understand instructions only when they are written in their own language – the machine
language. Therefore, a program written in any other Language should be translated into machine language.
Special program called language processors or translators are available to do this job. These special programs
accept the user programs and check each statement and, if it is correct, produce a corresponding set of
machine language instructions.
Types of TranslatorTypes of TranslatorTypes of TranslatorTypes of Translator ––––
Translators are two types
1. Compiler
2. Interpreter
CompilerCompilerCompilerCompiler:::: A compiler converts the source program (user written program) into an object code (machine
language by checking the entire program before execution. If the program is error free, object program is
created and loaded into memory for execution. A compiler produces an error list of the program in one go
and all have to be taken care even before the execution of first statement begin. It takes less time for
execution.
InterpreterInterpreterInterpreterInterpreter:::: An interpreter is also a language translator that translates and executes statements in the
program one by one. It work on one statement at a time and if error free, executes the instruction before
going to second instruction. Debugging is simpler in interpreter as it is done in stages. An interpreter takes
more time for execution of a program as compared to a compiler.
QQQQuestionuestionuestionuestion 6666 What is Data Type? Define all type of data type supported by c language.
Answer:Answer:Answer:Answer:
Data Type of a variable tell to the compiler
Name of variable
Which type of value that variable can hold
How much memory space it reserve
Data types in c are –
1.1.1.1. Primary data type
2.2.2.2. Derived data type
3.3.3.3. User defined data type
1.1.1.1. PrimaPrimaPrimaPrimary data type orry data type orry data type orry data type or predefined data type orpredefined data type orpredefined data type orpredefined data type or Fundamental data typeFundamental data typeFundamental data typeFundamental data type are those data type that are defined
in c already.
Data TypeData TypeData TypeData Type Used forUsed forUsed forUsed for Size(in Byte)Size(in Byte)Size(in Byte)Size(in Byte) RangeRangeRangeRange FormatFormatFormatFormat
Int Integer 2 32768 to 32767 %d
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 8
Char Character 1 128 to 127 %c
Float Single precision floating point number 4 3.4e38 to +3.4e38 %f
Double double precision floating point number 8 1.7e308 to
+1.7e308
%lf
Void
Data Type ModifiersData Type ModifiersData Type ModifiersData Type Modifiers ––––There are four modifiers available.
Signed
Unsigned
Short
Long
Data TypeData TypeData TypeData Type Size(in Byte)Size(in Byte)Size(in Byte)Size(in Byte) RangeRangeRangeRange FormatFormatFormatFormat
signed char 1 128 to + 127 %c
unsigned char 1 0 to 255 %c
signed int 2 32768 to +32767 %d
unsigned int 2 0 to 65535 %u
short signed int 2 32768 to +32767 %d
short unsigned int 2 0 to 65535 %u
long double 10 1.7e4932 to +1.7e4932 %Lf
2.2.2.2. DerivedDerivedDerivedDerived data tydata tydata tydata typepepepe are those data type that are derived by predefined data type.
ExampleExampleExampleExample Array, pointer
3.3.3.3. User defined data typeUser defined data typeUser defined data typeUser defined data type are those data type that are defined by the user itself.
ExampleExampleExampleExample struct, union
QuestionQuestionQuestionQuestion 7777 Define operator? How many types of operators are available in c programming? Explain any four
of them with examples.
AnsweAnsweAnsweAnswerrrr
OperatorOperatorOperatorOperator
Operator is a symbol that operates on one or more operands. Operands can be a variable, a constant or an
expression.
When an operator operates on one operand, is called unary operatorunary operatorunary operatorunary operator.
When an operator operates on two operands, is called binarybinarybinarybinary operator.operator.operator.operator.
When an operator operates on three operands, is called ternary operatorternary operatorternary operatorternary operator.
Types of OperatorsTypes of OperatorsTypes of OperatorsTypes of Operators
1.1.1.1. Arithmetic operator
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 9
2.2.2.2. Relational operator
3.3.3.3. Logical operator
4.4.4.4. Ternary operator
5.5.5.5. Increment operator
6.6.6.6. Assignment operator
7.7.7.7. Bitwise operator
8.8.8.8. Sizeof() operator
1.1.1.1. AritAritAritArithmetic operatorhmetic operatorhmetic operatorhmetic operator are used to perform to arithmetic operation on two operands.
OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity
+ Addition 2 Left to Right
Subtraction 2 Left to Right
* Multiplication 1 Left to Right
/ Division 1 Left to Right
% Modulo division 1 Left to Right
2.2.2.2. Relational operatorRelational operatorRelational operatorRelational operator are used to compare two operands.
OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity
< Less Than 1 Left to Right
<= Less than or equal to 1 Left to Right
> Greater than 1 Left to Right
>= Greater than or equal to 1 Left to Right
== Equal to 2 Left to Right
!= Not equal to 2 Left to Right
3.3.3.3. Logical operatorLogical operatorLogical operatorLogical operator are used to logically relate the sub expression.
OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity
&& Logical And 2 Left to Right
|| Logical or 3 Left to Right
! Negation 1 Right to Left
Truth Table of Logical operatorTruth Table of Logical operatorTruth Table of Logical operatorTruth Table of Logical operator
OpOpOpOpnnnnd1d1d1d1 Opnd2Opnd2Opnd2Opnd2 Opnd1&&Opnd2Opnd1&&Opnd2Opnd1&&Opnd2Opnd1&&Opnd2 Opnd1||Opnd2Opnd1||Opnd2Opnd1||Opnd2Opnd1||Opnd2 !Opnd1!Opnd1!Opnd1!Opnd1
0000 0000 0000 0000 1111
0000 1111 0000 1111 1111
1111 0000 0000 1111 0000
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 10
1111 1111 1111 1111 0000
4.4.4.4. Ternary operatorTernary operatorTernary operatorTernary operator operates on three operands .It is also called conditional operatorconditional operatorconditional operatorconditional operator....
It comes with the pair “ ?“ ?“ ?“ ? : ”
General form is-
exp1? exp2:exp3
ExplanationExplanationExplanationExplanation
If expression1 is true then expression2 is executed otherwise expression3 is executed.
QuestionQuestionQuestionQuestion 8888 What are storage classes? Define all storage classes with examples.
AnswerAnswerAnswerAnswer
Storage classesStorage classesStorage classesStorage classes
All variables have a data type, also have a storage class. Storage class of a variable tell to the compiler
Where will be the variable is stored?
What will be the initial value of the variable?
What will be the scope of the variable?
What will be the life of the variable?
There are four storage classes in C:
1.1.1.1. Automatic storage classAutomatic storage classAutomatic storage classAutomatic storage class
The features of variables are as follows
StorageStorageStorageStorage Memory
Default initial valueDefault initial valueDefault initial valueDefault initial value Garbage value
ScopeScopeScopeScope Local to the block in which defined
LifeLifeLifeLife till the control remains within the block in which defined
ExamplExamplExamplExample:e:e:e:
void main()
{
auto int a=5;
{
auto int a=10;
printf(“a=%d”,a); // display a=10
}
printf(“a=%d”,a); // display a=5
}
2.2.2.2. Register storage classRegister storage classRegister storage classRegister storage class
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 11
The features of variables are as follows
StorageStorageStorageStorage CPU registers
Default initial valueDefault initial valueDefault initial valueDefault initial value Garbage value
ScoScoScoScopepepepe Local to the block in which defined
LifeLifeLifeLife till the control remains within the block in which defined
Example:Example:Example:Example:
void main()
{
register int a=5;
{
register int a=10;
printf(“a=%d”,a); // display a=10
}
printf(“a=%d”,a); // display a=5
}
The only difference between auto and register is, the execution of register variable is much faster than auto
variable.
3.3.3.3. Static storage classStatic storage classStatic storage classStatic storage class
The features of variables are as follows
StorageStorageStorageStorage Memory
Default initial valueDefault initial valueDefault initial valueDefault initial value Zero
ScopeScopeScopeScope Local to the block in which defined
LifeLifeLifeLife value of variable persists between different function calls.
ExampleExampleExampleExample
void main()
{
Increment();
Increment();
Increment();
}
void Increment()
{
static int a=1;
printf(“a=%d”,a);
a++;
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 12
}
OutputOutputOutputOutput
a=1
a=2
a=3
4.4.4.4. External storage classExternal storage classExternal storage classExternal storage class
The features of variables here are as follows
StorageStorageStorageStorage Memory
Default initial valueDefault initial valueDefault initial valueDefault initial value Zero
ScopeScopeScopeScope global
LifeLifeLifeLife As long as program execution does not come to an end.
ExampleExampleExampleExample
void main()
{
extern int a;
printf(“a=%d”,a); //display a=0;//display a=0;//display a=0;//display a=0;
}
int a;
QuestionQuestionQuestionQuestion 9999 Write a program and flowchart to print Fibonacci series up to n terms.
AnswerAnswerAnswerAnswer
The Fibonacci numbers are the numbers in the following sequence:
0,1,1,2,3,5,8,13,21,34,55,89,144
By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the
previous two.
/* A program to p/* A program to p/* A program to p/* A program to print Fibonacci series up to n terms */rint Fibonacci series up to n terms */rint Fibonacci series up to n terms */rint Fibonacci series up to n terms */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b ,c,i,n;
printf(“n Enter the terms”);
scanf(“%d”,&n);
a=0;
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 13
b=1;
printf(“n%d %d”,a,b);
for(i=1;i<=n 2;i++)
{
c=a+b;
printf(“%d”,c);
a=b;
b=c;
}
getch();
}
Fibonacci Flowchart
The following flowchart illustrates how to generate Fibonacci Series for the first N numbers.
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 14
Question 10Question 10Question 10Question 10 Write a program to read two numbers from the keyboard and swap that numbers without
using third variable.
AnswerAnswerAnswerAnswer
/*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("n Enter the value of a and b >");
scanf("%d %d",&a,&b);
printf("n Before swapping >");
printf("a=%d and b=%d",a,b);
a=a+b;
b=a b;
a=a b;
printf("n After swapping >");
printf("a=%d and b=%d",a,b);
getch();
}
Question 11Question 11Question 11Question 11 Write a program and flowchart to print factorial of a number.
AnswerAnswerAnswerAnswer /*A program to find out factorial of given number*//*A program to find out factorial of given number*//*A program to find out factorial of given number*//*A program to find out factorial of given number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact;
printf("n Enter the number >");
scanf("%d",&n);
fact=1;
for(i=1;i<=n;i++)
{
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 15
fact=fact*i;
}
printf("n The factorial is %d",fact);
getch();
}
/* A flow chart of factorial of N number */
QueQueQueQuestion 12stion 12stion 12stion 12 Write a program to print all prime number from 1 to n terms.
AnswerAnswerAnswerAnswer
/* A program to print all prime number from/* A program to print all prime number from/* A program to print all prime number from/* A program to print all prime number from 1 to n terms */1 to n terms */1 to n terms */1 to n terms */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,t;
printf(“n Enter the terms”);
scanf(“%d”,&t);
for(n=1;n<=t;n++)
{
for(i=2;i<n;i++)
{
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 16
if(n%i==0)
break;
}
if(n==i)
printf(“n %d is prime number”,n);
}
getch();
}
QuestionQuestionQuestionQuestion 11113333 Explain switch case statement with the help of example.
AnswerAnswerAnswerAnswer
Switch StatementSwitch StatementSwitch StatementSwitch Statement
The control statement that allows us to make a decision from the number of choices is called a switch, or more
correctly a switch case default statement.
General formGeneral formGeneral formGeneral form
switch ( integer expression )
{
case constant 1 :
do this ;
case constant 2 :
do this ;
case constant 3 :
do this ;
default :
do this ;
}
The integer expression following the keyword switch is any C expression that will yield an integer
value. It could be an integer constant like 1, 2 or 3, or an expression that evaluates to an integer.
The keyword case is followed by an integer or a character constant.
Each constant in each case must be different from all the others.
Consider the following program:
void main( )
{
int i = 2 ;
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 17
switch ( i )
{
case 1 :
printf ( "I am in case 1 n" ) ;
case 2 :
printf ( "I am in case 2 n" ) ;
case 3 :
printf ( "I am in case 3 n" ) ;
default :
printf ( "I am in default n" ) ;
}
}
The output of this program would be:
I am in case 2
I am in case 3
I am in default
Question 14Question 14Question 14Question 14 Differentiate between global variable and local variable with the help of an example.
AnswerAnswerAnswerAnswer
GlGlGlGlobal and Local Variablesobal and Local Variablesobal and Local Variablesobal and Local Variables
Global variables:Global variables:Global variables:Global variables:
The features are as follows
Declared outside of all functions or before main
These can be used in all the functions in the program.
It need not be declared in other functions.
A global variable is also known as an external variable.
Local variables:Local variables:Local variables:Local variables:
The features are as follows
Declared inside a function where it is to be used.
These are not known to other function in the program.
These variables are visible and meaningful inside the functions in which they are declared.
Example:Example:Example:Example:
int a; //global variable
void main()
{
int b ; //local variable
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 18
a=5;
b=10;
printf(“a=%d b=%d”,a,b);
increment();
}
void increment()
{
a=a+1;
printf(“a=%d”,a);
}
Explanation:Explanation:Explanation:Explanation:
Since a variable is global variable therefore it can be accessed anywhere in the program. And b variable is
local variable therefore is cannot be accessed outside the main (), since it’s declared inside the main () and
cannot be accessed in the increment () function.
QuestionQuestionQuestionQuestion 11115555 Define variable declaration and variable initialization with the help of an example.
AnswerAnswerAnswerAnswer
Declaration of a variableDeclaration of a variableDeclaration of a variableDeclaration of a variable tells the compiler
Data Type of variable
Which type of value that variable contained?
And size of variable.
General form of declaration of variable
DataDataDataDataTTTType variaype variaype variaype variableblebleble_name_name_name_name;;;;
ExampleExampleExampleExample
int var;int var;int var;int var;
Here we declare a variable var of int data type that contains integer value and reserve 2 byte memory space.
IIIInitializationnitializationnitializationnitialization of variableof variableof variableof variable tells the compiler That we are assigning or initialize a value to that variable.
General form of Initialization of variable is
Variable_Name=Value;Variable_Name=Value;Variable_Name=Value;Variable_Name=Value;
ExampleExampleExampleExample
var=10;var=10;var=10;var=10;
Here we assign value 10 to variable var.
Kanpur Institute of Technology
Computer Concept and C Programming (Question Bank-1)
Somnath Gupta Page 19
Question 16Question 16Question 16Question 16 Read a number from the keyboard .Write a program to check that number is Armstrong or not.
AnswerAnswerAnswerAnswer
/*A program to check given numbe/*A program to check given numbe/*A program to check given numbe/*A program to check given number is Armstrong number or not */r is Armstrong number or not */r is Armstrong number or not */r is Armstrong number or not */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,,t,r,s=0;
printf("n Enter the n digit number >");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(t==s)
printf("n The number %d is Armstrong number ",t);
else
printf("n The number %d is not Armstrong number",t);
getch();
}

More Related Content

What's hot

Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentalsmaclather
 
Computer Organization (Unit-1)
Computer Organization (Unit-1)Computer Organization (Unit-1)
Computer Organization (Unit-1)Harsh Pandya
 
Computer organization-and-architecture-questions-and-answers
Computer organization-and-architecture-questions-and-answersComputer organization-and-architecture-questions-and-answers
Computer organization-and-architecture-questions-and-answersappasami
 
The Basic Organization of Computers
The Basic Organization of ComputersThe Basic Organization of Computers
The Basic Organization of ComputersTallat Satti
 
Processor architecture
Processor architectureProcessor architecture
Processor architectureMuuluu
 
Computer Oraganisation and Architecture
Computer Oraganisation and ArchitectureComputer Oraganisation and Architecture
Computer Oraganisation and Architectureyogesh1617
 
L 2 basic computer organization
L 2 basic computer organizationL 2 basic computer organization
L 2 basic computer organizationStubborn sam
 
Overview of Computer Architecture and Organization
Overview of Computer Architecture and OrganizationOverview of Computer Architecture and Organization
Overview of Computer Architecture and OrganizationVinit Raut
 
Introduction to Computers - Hardware
Introduction to Computers - HardwareIntroduction to Computers - Hardware
Introduction to Computers - HardwareSangeetha S
 
Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pamSaumya Sahu
 
How does data flow around a computer system p3 1
How does data flow around a computer system p3 1How does data flow around a computer system p3 1
How does data flow around a computer system p3 1lukecisco1
 
Computer and it's parts
Computer and it's partsComputer and it's parts
Computer and it's partsAshokkumar Rai
 

What's hot (20)

Computer Fundamentals
Computer FundamentalsComputer Fundamentals
Computer Fundamentals
 
Computer Organization (Unit-1)
Computer Organization (Unit-1)Computer Organization (Unit-1)
Computer Organization (Unit-1)
 
Computer organization-and-architecture-questions-and-answers
Computer organization-and-architecture-questions-and-answersComputer organization-and-architecture-questions-and-answers
Computer organization-and-architecture-questions-and-answers
 
Intro to cao &store program
Intro to cao &store programIntro to cao &store program
Intro to cao &store program
 
The Basic Organization of Computers
The Basic Organization of ComputersThe Basic Organization of Computers
The Basic Organization of Computers
 
1834902155 aka asgn 313
1834902155 aka asgn 3131834902155 aka asgn 313
1834902155 aka asgn 313
 
Processor architecture
Processor architectureProcessor architecture
Processor architecture
 
computer system organization basics
computer system organization basicscomputer system organization basics
computer system organization basics
 
Computer Oraganisation and Architecture
Computer Oraganisation and ArchitectureComputer Oraganisation and Architecture
Computer Oraganisation and Architecture
 
L 2 basic computer organization
L 2 basic computer organizationL 2 basic computer organization
L 2 basic computer organization
 
Input-Output Modules
Input-Output ModulesInput-Output Modules
Input-Output Modules
 
Architecture
ArchitectureArchitecture
Architecture
 
Overview of Computer Architecture and Organization
Overview of Computer Architecture and OrganizationOverview of Computer Architecture and Organization
Overview of Computer Architecture and Organization
 
Computer
ComputerComputer
Computer
 
Computer architecture
Computer architectureComputer architecture
Computer architecture
 
Introduction to Computers - Hardware
Introduction to Computers - HardwareIntroduction to Computers - Hardware
Introduction to Computers - Hardware
 
Computer Fundamentals Chapter 07 pam
Computer Fundamentals Chapter  07 pamComputer Fundamentals Chapter  07 pam
Computer Fundamentals Chapter 07 pam
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
How does data flow around a computer system p3 1
How does data flow around a computer system p3 1How does data flow around a computer system p3 1
How does data flow around a computer system p3 1
 
Computer and it's parts
Computer and it's partsComputer and it's parts
Computer and it's parts
 

Similar to C q 1

introduction to computers
 introduction to computers introduction to computers
introduction to computersDeepak John
 
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...SaffaIbrahim1
 
Computer Fundamental
Computer FundamentalComputer Fundamental
Computer FundamentalShradha Kabra
 
Chapter 1 computer hardware and flow of information
Chapter 1 computer hardware and flow of informationChapter 1 computer hardware and flow of information
Chapter 1 computer hardware and flow of informationFrankie Jones
 
Computer application in business
Computer application in businessComputer application in business
Computer application in businessshashank singh
 
Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes newdilshad begum
 
janvichauhan110cs.pptx
janvichauhan110cs.pptxjanvichauhan110cs.pptx
janvichauhan110cs.pptxSANKETKOTAK5
 
COA-Unit-1-Basics.ppt
COA-Unit-1-Basics.pptCOA-Unit-1-Basics.ppt
COA-Unit-1-Basics.pptRuhul Amin
 
Basic of operating system
Basic of operating systemBasic of operating system
Basic of operating systempriyanka jain
 
Components of computer system and input-output devices and storage devices
Components of computer system and input-output devices and storage devicesComponents of computer system and input-output devices and storage devices
Components of computer system and input-output devices and storage devicesSaiFul IsLam
 
Cpu introduction to computer
Cpu introduction to computerCpu introduction to computer
Cpu introduction to computerBRS ENGINEERING
 
introdection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATIONintrodection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATIONreshmi30
 

Similar to C q 1 (20)

introduction to computers
 introduction to computers introduction to computers
introduction to computers
 
Lecture 2 - Introductory Concepts
Lecture 2 - Introductory ConceptsLecture 2 - Introductory Concepts
Lecture 2 - Introductory Concepts
 
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...
Computer Architecture in Organisation - COMP 3114 - LECTURE NOTES - 2023-2024...
 
Computer Fundamental
Computer FundamentalComputer Fundamental
Computer Fundamental
 
Lec 1 DPT
Lec 1 DPTLec 1 DPT
Lec 1 DPT
 
Chapter 1 computer hardware and flow of information
Chapter 1 computer hardware and flow of informationChapter 1 computer hardware and flow of information
Chapter 1 computer hardware and flow of information
 
Fundamentals
FundamentalsFundamentals
Fundamentals
 
HARDWARE
HARDWAREHARDWARE
HARDWARE
 
CP Handout#1
CP Handout#1CP Handout#1
CP Handout#1
 
Computer application in business
Computer application in businessComputer application in business
Computer application in business
 
Ise iv-computer organization [10 cs46]-notes new
Ise iv-computer  organization [10 cs46]-notes newIse iv-computer  organization [10 cs46]-notes new
Ise iv-computer organization [10 cs46]-notes new
 
janvichauhan110cs.pptx
janvichauhan110cs.pptxjanvichauhan110cs.pptx
janvichauhan110cs.pptx
 
CS14106-UNIT 2.pptx
CS14106-UNIT 2.pptxCS14106-UNIT 2.pptx
CS14106-UNIT 2.pptx
 
COA-Unit-1-Basics.ppt
COA-Unit-1-Basics.pptCOA-Unit-1-Basics.ppt
COA-Unit-1-Basics.ppt
 
Basic of operating system
Basic of operating systemBasic of operating system
Basic of operating system
 
Components of computer system and input-output devices and storage devices
Components of computer system and input-output devices and storage devicesComponents of computer system and input-output devices and storage devices
Components of computer system and input-output devices and storage devices
 
Cpu introduction to computer
Cpu introduction to computerCpu introduction to computer
Cpu introduction to computer
 
lec01.pdf
lec01.pdflec01.pdf
lec01.pdf
 
introdection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATIONintrodection BASIC OF COMPUTER EDUCATION
introdection BASIC OF COMPUTER EDUCATION
 
Basics of computer
Basics of computerBasics of computer
Basics of computer
 

Recently uploaded

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

C q 1

  • 1. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 1 QuestionQuestionQuestionQuestion 1111 Draw the functional block diagram of a Digital Computer and discuss its components in brief. AnswerAnswerAnswerAnswer Introduction to digital ComputerIntroduction to digital ComputerIntroduction to digital ComputerIntroduction to digital Computer ComputerComputerComputerComputer A computer is an electronic device that accepts data through input devices processes those data and gives some meaning full information in the form of knowledge through output devices. Digital ComputerDigital ComputerDigital ComputerDigital Computer Those Computers, which accepts digits (like name, age, special characters etc.) as input called Digital Computers. Digital Computer has following units:Digital Computer has following units:Digital Computer has following units:Digital Computer has following units: 1.1.1.1. Input Unit 2.2.2.2. Central Processing Unit 3.3.3.3. Output Unit Block diagram of Digital ComputersBlock diagram of Digital ComputersBlock diagram of Digital ComputersBlock diagram of Digital Computers Digital computer is an electronic device. It comprises of many units. These units work in co ordination with each other to perform the give task. CPU Output UnitProcessing UnitInput Unit CU ALU Output UnitInput Unit Memory
  • 2. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 2 Input UnitInput UnitInput UnitInput Unit Computers need to receive data and instruction in order to solve any problem. Therefore we need to input the data and instructions into the computers. The input unit consists of one or more input devices. Keyboard is the one of the most commonly used input device. Other commonly used input devices are the mouse, floppy disk drive, magnetic tape, etc. All the input devices perform the following functions. Accept the data and instructions from the outside world. Convert it to a form that the computer can understand. Supply the converted data to the computer system for further processing. Output Unit:Output Unit:Output Unit:Output Unit: The output unit of a computer provides the information and results of a computation to outside world. Printers, Visual Display Unit (VDU) are the commonly used output devices. Other commonly used output devices are floppy disk drive, hard disk drive, and magnetic tape drive. Central Processing UnitCentral Processing UnitCentral Processing UnitCentral Processing Unit The CPU is like brain performs the following functions: It performs all calculations. It takes all decisions. It controls all units of the computer. CPU consists of following parts. Central Processing UnitCentral Processing UnitCentral Processing UnitCentral Processing Unit Memory UnitMemory UnitMemory UnitMemory Unit Arithmetic UnitArithmetic UnitArithmetic UnitArithmetic Unit Control UnitControl UnitControl UnitControl Unit Memory UnitMemory UnitMemory UnitMemory Unit The memory unit of the computer holds data and instructions that are entered through the input unit, before they are processed. It preserves the intermediate and final results before these are sent to the output devices. It also saves the data for the later use. The various storage devices of a computer system are divided into two categories. 1. Primary memory:1. Primary memory:1. Primary memory:1. Primary memory: This memory is generally used to hold the program being currently executed in the
  • 3. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 3 computer, the data being received from the input unit, the intermediate and final results of the program. The primary memory is temporary in nature. The data is lost, when the computer is switched off. In order to store the data permanently, the data has to be transferred to the secondary memory. The cost of the primary storage is more compared to the secondary storage. Therefore most computers have limited primary storage capacity. Primary MemoryPrimary MemoryPrimary MemoryPrimary Memory It is further categorized into two categories: (i)(i)(i)(i) ROM (Read Only Memory)ROM (Read Only Memory)ROM (Read Only Memory)ROM (Read Only Memory) (ii)(ii)(ii)(ii) RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory) (i)(i)(i)(i) ROMROMROMROM Computer cannot write data in it using special devices, instructions are written in it use instructions are written in it. It is put inside the computer. Since data can only be read ROM it hence it is called Read Only Memory. ROM physically exists in the form of blank electronic chip. ROM is further divided into three categories. (a)(a)(a)(a) PROMPROMPROMPROM (b)(b)(b)(b) EPROMEPROMEPROMEPROM (c)(c)(c)(c) EEPROMEEPROMEEPROMEEPROM (a)(a)(a)(a) PROMPROMPROMPROM Those ROMs in which data once written can be programmable is called Programmable Read Only Memory. (b)(b)(b)(b) EPROMEPROMEPROMEPROM In this type of ROM data is written or erase, using ultraviolet rays is called Erasable Programmable Read Only Memory. (c)(c)(c)(c) EEPROMEEPROMEEPROMEEPROM This is Electrically Erasable Programmable Read Only Memory. In this data is erased by electric pulses. (ii)(ii)(ii)(ii) RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory)RAM (Random Access Memory) it provides both reading and writing facilities. As and when required, Computer writes data or instructions in it and reads them whenever necessary. This is the reason this is called Read/Write memory. The data written in Random Access Memory remains there till the time computer power is on. As soon as the power goes off data written in RAM gets erased. This is the reason why are also called Temporary Memory. 2. Secondary memory:2. Secondary memory:2. Secondary memory:2. Secondary memory: It stores several programs, documents, data bases etc. The programs that you run on the computer are first transferred to the primary memory before it is actually run. Whenever the results are
  • 4. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 4 saved, again they get stored in the secondary memory. The secondary memory is slower and cheaper than the primary memory. Some of the commonly used secondary memory devices are Hard disk, CD, etc. ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit)ALU (Arithmetic and Logic Unit) All calculations are performed in the Arithmetic Logic Unit (ALU) of the computer. It also does comparison and takes decision. The ALU can perform basic operations such as addition, subtraction, multiplication, division, etc and does logic operations viz, >, <, =, 'etc. Whenever calculations are required, the control unit transfers the data from memory unit to ALU once the computations are done, the results are transferred to the memory unit by the control unit and then it is send to the output unit for displaying results. C U (ControlC U (ControlC U (ControlC U (Control Unit)Unit)Unit)Unit) It controls all other units in the computer. The control unit instructs the input unit, where to store the data after receiving it from the user. It controls the flow of data and instructions from the storage unit to ALU. It also controls the flow of results from the ALU to the storage unit. The control unit is generally referred as the central system of the computer that control and synchronizes its working. QuestionQuestionQuestionQuestion 2222 Define Algorithm with its characteristics. Draw a flow chart of finding the greatest number among three numbers. AnswerAnswerAnswerAnswer AlgorithmsAlgorithmsAlgorithmsAlgorithms Logical sequence of steps describe complete solution to solve problem in finite amount of time A method that can be used by a computer for the solution of a problem. May involve alternation, iteration or recursion More than one algorithm possible for the same task Essential features of an algorithm:Essential features of an algorithm:Essential features of an algorithm:Essential features of an algorithm: 1.1.1.1. Input: The algorithm should take zero or more input. 2.2.2.2. Output: The algorithm should produce one or more outputs. 3.3.3.3. Definiteness: Each and every step of algorithm should be defined unambiguously. 4.4.4.4. Effectiveness: A human should be able to calculate the values involved in the procedure of the algorithm using paper and pencil. 5.5.5.5. Termination: An algorithm must terminate after a finite number of steps. /* A/* A/* A/* A flowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and Cflowchart to find the largest of three numbers A, B, and C */*/*/*/
  • 5. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 5 Question 3Question 3Question 3Question 3 Why “C” is called structured programming language? Explain. AnswerAnswerAnswerAnswer C language is called structured programming language because it is based on structured programming approach. StructuredStructuredStructuredStructured programming:programming:programming:programming: means the collection of principles and practices that are directed toward developing correct programs which are easy to maintain and understand. A structured program is characterized by clarity and simplicity in its logical flow. The Three important constructs upon which structured programming is built are: SequenceSequenceSequenceSequence Steps are performed one after the other. SelectionSelectionSelectionSelection Logic is used to determine the execution of a sequence of steps. For example, if then else construct. IterationIterationIterationIteration A set of actions are repeated until a certain condition is met. For example while construct. The various advantages of structured programmingadvantages of structured programmingadvantages of structured programmingadvantages of structured programming are: 1. Complexity of program reduces. 2. Easy maintenance. 3. Simplified understanding. 4. Reusability of code increases. 5. Testing and debugging become easier.
  • 6. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 6 QuestionQuestionQuestionQuestion 4444Convert the following: (2.5) I. (1101101.101)2 to Octal III. (357)8 to Decimal II. (B678A) 16 to Binary IV. (125)10 to Hexadecimal AnswerAnswerAnswerAnswer I. (1101101.101)2 to Octal 001 101 101 . 101 1 5 5 . 5 AnswerAnswerAnswerAnswer ((((155.5155.5155.5155.5)8)8)8)8 I. (B678A) 16 to Binary B 6 7 8 A 1011 0110 0111 1000 1110 AnswerAnswerAnswerAnswer (1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)(1011 0110 0111 1000 1110)2222 II. (357)8 to Decimal 7 * 80 =7 5 * 81 =40 3 * 82 =192 =239=239=239=239 AnswerAnswerAnswerAnswer (239)(239)(239)(239)10101010 III. (125)10 to Hexadecimal 16|125 16|7 13 >D 16|0 7 AnswerAnswerAnswerAnswer (7(7(7(7DDDD))))16161616 QuestionQuestionQuestionQuestion 5555 What are Translators? Why we need translators? Explain with reasons. AnswerAnswerAnswerAnswer Language TranslatorLanguage TranslatorLanguage TranslatorLanguage Translator Translator – A translator is a program that translates our source code written in high level language (C program) in machine code. Source Code Translator Machine Code
  • 7. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 7 Why do we need languageWhy do we need languageWhy do we need languageWhy do we need language translator?translator?translator?translator? Computer can understand instructions only when they are written in their own language – the machine language. Therefore, a program written in any other Language should be translated into machine language. Special program called language processors or translators are available to do this job. These special programs accept the user programs and check each statement and, if it is correct, produce a corresponding set of machine language instructions. Types of TranslatorTypes of TranslatorTypes of TranslatorTypes of Translator –––– Translators are two types 1. Compiler 2. Interpreter CompilerCompilerCompilerCompiler:::: A compiler converts the source program (user written program) into an object code (machine language by checking the entire program before execution. If the program is error free, object program is created and loaded into memory for execution. A compiler produces an error list of the program in one go and all have to be taken care even before the execution of first statement begin. It takes less time for execution. InterpreterInterpreterInterpreterInterpreter:::: An interpreter is also a language translator that translates and executes statements in the program one by one. It work on one statement at a time and if error free, executes the instruction before going to second instruction. Debugging is simpler in interpreter as it is done in stages. An interpreter takes more time for execution of a program as compared to a compiler. QQQQuestionuestionuestionuestion 6666 What is Data Type? Define all type of data type supported by c language. Answer:Answer:Answer:Answer: Data Type of a variable tell to the compiler Name of variable Which type of value that variable can hold How much memory space it reserve Data types in c are – 1.1.1.1. Primary data type 2.2.2.2. Derived data type 3.3.3.3. User defined data type 1.1.1.1. PrimaPrimaPrimaPrimary data type orry data type orry data type orry data type or predefined data type orpredefined data type orpredefined data type orpredefined data type or Fundamental data typeFundamental data typeFundamental data typeFundamental data type are those data type that are defined in c already. Data TypeData TypeData TypeData Type Used forUsed forUsed forUsed for Size(in Byte)Size(in Byte)Size(in Byte)Size(in Byte) RangeRangeRangeRange FormatFormatFormatFormat Int Integer 2 32768 to 32767 %d
  • 8. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 8 Char Character 1 128 to 127 %c Float Single precision floating point number 4 3.4e38 to +3.4e38 %f Double double precision floating point number 8 1.7e308 to +1.7e308 %lf Void Data Type ModifiersData Type ModifiersData Type ModifiersData Type Modifiers ––––There are four modifiers available. Signed Unsigned Short Long Data TypeData TypeData TypeData Type Size(in Byte)Size(in Byte)Size(in Byte)Size(in Byte) RangeRangeRangeRange FormatFormatFormatFormat signed char 1 128 to + 127 %c unsigned char 1 0 to 255 %c signed int 2 32768 to +32767 %d unsigned int 2 0 to 65535 %u short signed int 2 32768 to +32767 %d short unsigned int 2 0 to 65535 %u long double 10 1.7e4932 to +1.7e4932 %Lf 2.2.2.2. DerivedDerivedDerivedDerived data tydata tydata tydata typepepepe are those data type that are derived by predefined data type. ExampleExampleExampleExample Array, pointer 3.3.3.3. User defined data typeUser defined data typeUser defined data typeUser defined data type are those data type that are defined by the user itself. ExampleExampleExampleExample struct, union QuestionQuestionQuestionQuestion 7777 Define operator? How many types of operators are available in c programming? Explain any four of them with examples. AnsweAnsweAnsweAnswerrrr OperatorOperatorOperatorOperator Operator is a symbol that operates on one or more operands. Operands can be a variable, a constant or an expression. When an operator operates on one operand, is called unary operatorunary operatorunary operatorunary operator. When an operator operates on two operands, is called binarybinarybinarybinary operator.operator.operator.operator. When an operator operates on three operands, is called ternary operatorternary operatorternary operatorternary operator. Types of OperatorsTypes of OperatorsTypes of OperatorsTypes of Operators 1.1.1.1. Arithmetic operator
  • 9. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 9 2.2.2.2. Relational operator 3.3.3.3. Logical operator 4.4.4.4. Ternary operator 5.5.5.5. Increment operator 6.6.6.6. Assignment operator 7.7.7.7. Bitwise operator 8.8.8.8. Sizeof() operator 1.1.1.1. AritAritAritArithmetic operatorhmetic operatorhmetic operatorhmetic operator are used to perform to arithmetic operation on two operands. OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity + Addition 2 Left to Right Subtraction 2 Left to Right * Multiplication 1 Left to Right / Division 1 Left to Right % Modulo division 1 Left to Right 2.2.2.2. Relational operatorRelational operatorRelational operatorRelational operator are used to compare two operands. OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity < Less Than 1 Left to Right <= Less than or equal to 1 Left to Right > Greater than 1 Left to Right >= Greater than or equal to 1 Left to Right == Equal to 2 Left to Right != Not equal to 2 Left to Right 3.3.3.3. Logical operatorLogical operatorLogical operatorLogical operator are used to logically relate the sub expression. OperatorOperatorOperatorOperator MeaningMeaningMeaningMeaning PrecedencePrecedencePrecedencePrecedence AssociativityAssociativityAssociativityAssociativity && Logical And 2 Left to Right || Logical or 3 Left to Right ! Negation 1 Right to Left Truth Table of Logical operatorTruth Table of Logical operatorTruth Table of Logical operatorTruth Table of Logical operator OpOpOpOpnnnnd1d1d1d1 Opnd2Opnd2Opnd2Opnd2 Opnd1&&Opnd2Opnd1&&Opnd2Opnd1&&Opnd2Opnd1&&Opnd2 Opnd1||Opnd2Opnd1||Opnd2Opnd1||Opnd2Opnd1||Opnd2 !Opnd1!Opnd1!Opnd1!Opnd1 0000 0000 0000 0000 1111 0000 1111 0000 1111 1111 1111 0000 0000 1111 0000
  • 10. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 10 1111 1111 1111 1111 0000 4.4.4.4. Ternary operatorTernary operatorTernary operatorTernary operator operates on three operands .It is also called conditional operatorconditional operatorconditional operatorconditional operator.... It comes with the pair “ ?“ ?“ ?“ ? : ” General form is- exp1? exp2:exp3 ExplanationExplanationExplanationExplanation If expression1 is true then expression2 is executed otherwise expression3 is executed. QuestionQuestionQuestionQuestion 8888 What are storage classes? Define all storage classes with examples. AnswerAnswerAnswerAnswer Storage classesStorage classesStorage classesStorage classes All variables have a data type, also have a storage class. Storage class of a variable tell to the compiler Where will be the variable is stored? What will be the initial value of the variable? What will be the scope of the variable? What will be the life of the variable? There are four storage classes in C: 1.1.1.1. Automatic storage classAutomatic storage classAutomatic storage classAutomatic storage class The features of variables are as follows StorageStorageStorageStorage Memory Default initial valueDefault initial valueDefault initial valueDefault initial value Garbage value ScopeScopeScopeScope Local to the block in which defined LifeLifeLifeLife till the control remains within the block in which defined ExamplExamplExamplExample:e:e:e: void main() { auto int a=5; { auto int a=10; printf(“a=%d”,a); // display a=10 } printf(“a=%d”,a); // display a=5 } 2.2.2.2. Register storage classRegister storage classRegister storage classRegister storage class
  • 11. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 11 The features of variables are as follows StorageStorageStorageStorage CPU registers Default initial valueDefault initial valueDefault initial valueDefault initial value Garbage value ScoScoScoScopepepepe Local to the block in which defined LifeLifeLifeLife till the control remains within the block in which defined Example:Example:Example:Example: void main() { register int a=5; { register int a=10; printf(“a=%d”,a); // display a=10 } printf(“a=%d”,a); // display a=5 } The only difference between auto and register is, the execution of register variable is much faster than auto variable. 3.3.3.3. Static storage classStatic storage classStatic storage classStatic storage class The features of variables are as follows StorageStorageStorageStorage Memory Default initial valueDefault initial valueDefault initial valueDefault initial value Zero ScopeScopeScopeScope Local to the block in which defined LifeLifeLifeLife value of variable persists between different function calls. ExampleExampleExampleExample void main() { Increment(); Increment(); Increment(); } void Increment() { static int a=1; printf(“a=%d”,a); a++;
  • 12. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 12 } OutputOutputOutputOutput a=1 a=2 a=3 4.4.4.4. External storage classExternal storage classExternal storage classExternal storage class The features of variables here are as follows StorageStorageStorageStorage Memory Default initial valueDefault initial valueDefault initial valueDefault initial value Zero ScopeScopeScopeScope global LifeLifeLifeLife As long as program execution does not come to an end. ExampleExampleExampleExample void main() { extern int a; printf(“a=%d”,a); //display a=0;//display a=0;//display a=0;//display a=0; } int a; QuestionQuestionQuestionQuestion 9999 Write a program and flowchart to print Fibonacci series up to n terms. AnswerAnswerAnswerAnswer The Fibonacci numbers are the numbers in the following sequence: 0,1,1,2,3,5,8,13,21,34,55,89,144 By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. /* A program to p/* A program to p/* A program to p/* A program to print Fibonacci series up to n terms */rint Fibonacci series up to n terms */rint Fibonacci series up to n terms */rint Fibonacci series up to n terms */ #include<stdio.h> #include<conio.h> void main() { int a,b ,c,i,n; printf(“n Enter the terms”); scanf(“%d”,&n); a=0;
  • 13. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 13 b=1; printf(“n%d %d”,a,b); for(i=1;i<=n 2;i++) { c=a+b; printf(“%d”,c); a=b; b=c; } getch(); } Fibonacci Flowchart The following flowchart illustrates how to generate Fibonacci Series for the first N numbers.
  • 14. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 14 Question 10Question 10Question 10Question 10 Write a program to read two numbers from the keyboard and swap that numbers without using third variable. AnswerAnswerAnswerAnswer /*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*//*A program to swap two values without the help of third variable*/ #include<stdio.h> #include<conio.h> void main() { int a,b; printf("n Enter the value of a and b >"); scanf("%d %d",&a,&b); printf("n Before swapping >"); printf("a=%d and b=%d",a,b); a=a+b; b=a b; a=a b; printf("n After swapping >"); printf("a=%d and b=%d",a,b); getch(); } Question 11Question 11Question 11Question 11 Write a program and flowchart to print factorial of a number. AnswerAnswerAnswerAnswer /*A program to find out factorial of given number*//*A program to find out factorial of given number*//*A program to find out factorial of given number*//*A program to find out factorial of given number*/ #include<stdio.h> #include<conio.h> void main() { int n,i,fact; printf("n Enter the number >"); scanf("%d",&n); fact=1; for(i=1;i<=n;i++) {
  • 15. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 15 fact=fact*i; } printf("n The factorial is %d",fact); getch(); } /* A flow chart of factorial of N number */ QueQueQueQuestion 12stion 12stion 12stion 12 Write a program to print all prime number from 1 to n terms. AnswerAnswerAnswerAnswer /* A program to print all prime number from/* A program to print all prime number from/* A program to print all prime number from/* A program to print all prime number from 1 to n terms */1 to n terms */1 to n terms */1 to n terms */ #include<stdio.h> #include<conio.h> void main() { int n,i,t; printf(“n Enter the terms”); scanf(“%d”,&t); for(n=1;n<=t;n++) { for(i=2;i<n;i++) {
  • 16. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 16 if(n%i==0) break; } if(n==i) printf(“n %d is prime number”,n); } getch(); } QuestionQuestionQuestionQuestion 11113333 Explain switch case statement with the help of example. AnswerAnswerAnswerAnswer Switch StatementSwitch StatementSwitch StatementSwitch Statement The control statement that allows us to make a decision from the number of choices is called a switch, or more correctly a switch case default statement. General formGeneral formGeneral formGeneral form switch ( integer expression ) { case constant 1 : do this ; case constant 2 : do this ; case constant 3 : do this ; default : do this ; } The integer expression following the keyword switch is any C expression that will yield an integer value. It could be an integer constant like 1, 2 or 3, or an expression that evaluates to an integer. The keyword case is followed by an integer or a character constant. Each constant in each case must be different from all the others. Consider the following program: void main( ) { int i = 2 ;
  • 17. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 17 switch ( i ) { case 1 : printf ( "I am in case 1 n" ) ; case 2 : printf ( "I am in case 2 n" ) ; case 3 : printf ( "I am in case 3 n" ) ; default : printf ( "I am in default n" ) ; } } The output of this program would be: I am in case 2 I am in case 3 I am in default Question 14Question 14Question 14Question 14 Differentiate between global variable and local variable with the help of an example. AnswerAnswerAnswerAnswer GlGlGlGlobal and Local Variablesobal and Local Variablesobal and Local Variablesobal and Local Variables Global variables:Global variables:Global variables:Global variables: The features are as follows Declared outside of all functions or before main These can be used in all the functions in the program. It need not be declared in other functions. A global variable is also known as an external variable. Local variables:Local variables:Local variables:Local variables: The features are as follows Declared inside a function where it is to be used. These are not known to other function in the program. These variables are visible and meaningful inside the functions in which they are declared. Example:Example:Example:Example: int a; //global variable void main() { int b ; //local variable
  • 18. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 18 a=5; b=10; printf(“a=%d b=%d”,a,b); increment(); } void increment() { a=a+1; printf(“a=%d”,a); } Explanation:Explanation:Explanation:Explanation: Since a variable is global variable therefore it can be accessed anywhere in the program. And b variable is local variable therefore is cannot be accessed outside the main (), since it’s declared inside the main () and cannot be accessed in the increment () function. QuestionQuestionQuestionQuestion 11115555 Define variable declaration and variable initialization with the help of an example. AnswerAnswerAnswerAnswer Declaration of a variableDeclaration of a variableDeclaration of a variableDeclaration of a variable tells the compiler Data Type of variable Which type of value that variable contained? And size of variable. General form of declaration of variable DataDataDataDataTTTType variaype variaype variaype variableblebleble_name_name_name_name;;;; ExampleExampleExampleExample int var;int var;int var;int var; Here we declare a variable var of int data type that contains integer value and reserve 2 byte memory space. IIIInitializationnitializationnitializationnitialization of variableof variableof variableof variable tells the compiler That we are assigning or initialize a value to that variable. General form of Initialization of variable is Variable_Name=Value;Variable_Name=Value;Variable_Name=Value;Variable_Name=Value; ExampleExampleExampleExample var=10;var=10;var=10;var=10; Here we assign value 10 to variable var.
  • 19. Kanpur Institute of Technology Computer Concept and C Programming (Question Bank-1) Somnath Gupta Page 19 Question 16Question 16Question 16Question 16 Read a number from the keyboard .Write a program to check that number is Armstrong or not. AnswerAnswerAnswerAnswer /*A program to check given numbe/*A program to check given numbe/*A program to check given numbe/*A program to check given number is Armstrong number or not */r is Armstrong number or not */r is Armstrong number or not */r is Armstrong number or not */ #include<stdio.h> #include<conio.h> void main() { int n,,t,r,s=0; printf("n Enter the n digit number >"); scanf("%d",&n); t=n; while(n!=0) { r=n%10; s=s+(r*r*r); n=n/10; } if(t==s) printf("n The number %d is Armstrong number ",t); else printf("n The number %d is not Armstrong number",t); getch(); }