0% found this document useful (0 votes)
57 views14 pages

Comment "C Is Middle Level Language"? 2. What Is Problem Solving?

The document discusses problem solving and programming concepts. It defines problem solving as a creative process involving defining a problem, determining the cause, identifying alternatives, selecting a solution, and implementing it. It lists common problem solving strategies and the six steps of problem solving. It also defines key programming concepts like algorithms, programs, programming languages, variables, constants, and data types in C.
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)
57 views14 pages

Comment "C Is Middle Level Language"? 2. What Is Problem Solving?

The document discusses problem solving and programming concepts. It defines problem solving as a creative process involving defining a problem, determining the cause, identifying alternatives, selecting a solution, and implementing it. It lists common problem solving strategies and the six steps of problem solving. It also defines key programming concepts like algorithms, programs, programming languages, variables, constants, and data types in C.
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/ 14

1. Comment “C is middle level language”?

2. What is problem solving?

Problem solving is a creative process. It is an act of defining a problem,


determining the cause of the problem, identifying, prioritizing, and selecting
alternatives for a solution and implementing a solution.
There is no universal method for solving a given problem. Different strategies
appear to be good for different problems. Some of the well known strategies are:
➢ Divide and Conquer
➢ Greedy Method
➢ Dynamic Programming
➢ Backtracking
➢ Branch and Bound
Six steps of problem solving is
1. Planning
2. Analysis
3. Design
4. Implementaion
5. Testing and Integration
6. Maintanance

3. What are the six steps of problem solving?

Six steps of problem solving is


7. Planning
8. Analysis
9. Design
10. Implementation
11. Testing and Integration
12. Maintanance

4. Define Algorithm and state the rules for writing an algorithm.

Algorithm
An algorithm is a step-by-step description of the solution to a problem. It is
defined as an ordered sequence of well-defined and effective operations which,
when carried out for a given set of initial conditions, produce output, and terminate
in a finite time. The term “ordered sequence” specifies, after the completion of each
step in the algorithm, the next step must be unambiguously defined.
An algorithm must be:
• Definite
• Finite
• Precise and Effective
• Implementation independent ( only for problem not for programming
languages)
5. Discuss about how the problem can be solved with computers?
6. What is a program?

A program is a set of instructions that a computer follows in order to perform a


particular task.Computer Programming is an art of making a computer to do the required
operations, by means of issuing sequence of commands to it.

A programming language can be defined as a vocabulary and set of


grammatical rules for instructing the computer to perform specific tasks. Each
programming language has a unique set of characters, keywords and the syntax for
organizing programming instructions.
The term programming languages usually refers to high-level languages, such as
BASIC, C, C++, COBOL, FORTRAN, Ada, and Pascal.

7. Why is problem analysis important?

Analyzing or Defining the Problem


The problem is defined by doing a preliminary investigation. Defining a
problem helps us to understand the problem clear. It is also known as
Program Analysis.

➢ Tasks in defining a problem: ▪ Obtained by


answering these
questions
➢ Specifying the input requirements ➢ What specific values will be
provided as input to the program?
➢ What format will the values be?
➢ For each input item, what is the
valid range of values that it may
assume?
➢ What restrictions are placed on the
use of these values?
➢ Specifying the output requirements ➢ What values will be produced?
➢ What is the format of these values?
➢ What specific annotation, headings,
or titles are required in the report?
➢ What is the amount of output that
will be produced?

➢ Specifying the processing ➢ What is the method (technique)


requirements required in producing the desired
output?
➢ What calculations are needed?
➢ What are the validation checks that
need to be applied to the input data?

8. What are the tools of problem solving available?


9. How do problem-solving tools help in leading to a solution?
10. Why it is important to test a solution before coding it?
11. What is an algorithm? Give the characteristics of the algorithm.
A finite sequence of unambiguous, executable steps or instructions, which if
followed would ultimately terminate and give the solution of the problem.

Properties of an algorithm:

Finite – The algorithm must eventually terminate

Complete – Always give a solution when one exists.

Correct – Always give a correct solution.

12. What is flowchart? Give the symbols/shapes used in the flowchart.


13. Define pseudo code and gives its importance with an example.
14. Discuss the difficulties with problem solving in detail.
15. Differentiate between constants and variables, Write down the rules for
naming variables.

Constants Variables
A value that can not be altered throughout A storage location paired with an
the program associated symbolic name which has a
value
It is similar to a variable but it cannot be A storage area holds data
modified by the program once defined
Can not be changed Can be changed according to the need of
the programmer
Value is fixed Value is varying

Rules for Naming Variables

➢ The first letter of a variable name must be alphabet (underscore is also allowed).
➢ Variable can only contain letters, digits, and underscores.
➢ White space is not allowed.
➢ Keywords cannot be used as an identifier to name variables.
➢ C is case sensitive language variable name written in uppercase will differ from
lowercase

16. State the use of %d and %f. write a print statement in C using above mentioned
symbol?

Code Output
#include<stdio.h> Enter the value of a and b:10 10.5
void main() a=10
{ b=10.5
int a;
float b;
printf(“Enter the value of a and b:”);
scanf(“%d%f”,&a,&b);
printf(“a= %d\nb= %f”,a,b);
}
17. What is main difference between variable and constant?

Constants Variables
A value that can not be altered throughout A storage location paired with an
the program associated symbolic name which has a
value
It is similar to a variable but it cannot be A storage area holds data
modified by the program once defined
Can not be changed Can be changed according to the need of
the programmer
Value is fixed Value is varying

18. Explain bitwise left shift operator?

The bitwise shift operators move the bit values of a binary object. The left operand
specifies the value to be shifted. The right operand specifies the number of positions that the bits
in the value are to be shifted.

<< (left shift) Takes two numbers, left shifts the bits of the first operand, the second
operand decides the number of places to shift. Or in other words left shifting an integer “x” with
an integer “y” (x<<y) is equivalent to multiplying x with 2^y (2 raise to power y).

code output
#include<stdio.h> the value
int main()
{
int a=5; int b,c;
b=a<<1;
c=a<<2;
printf("after 1 bit left shift of a is: %d\n", b);
printf("after 2 bit left shift of a is: %d\n", c);

return 0;
}
19. Explain the different data types supported in C.
Data Types
Data types are used to indicate the type of value represented or stored in a variable, the
number of bytes to be reserved in memory, the range of values that can be represented in
memory, and the type of operation that can be performed on a particular data item.

ANSI C supports two classes of data types:


❑ Primary / Fundamental / Basic / Primitive data types

❑ Derived / Compound data types

C uses the following basic data types:


❑ int - integer quantity
❑ char - character (stores a single character)

❑ float - single precision real (floating point) number

❑ double - double precision real (floating point) number

Date type Types Size (bytes) Range


Integer signed int 2 byte -32,768 to 32767
shot int 1byte -128 to 127
long int 4byte -2,147,483,648 to 2,147,483,647
unsigned int 2byte 0 to 65535
short int 1byte 0 to 255
long int 4byte 0 to 4,294,967,295
Floating point float 4 byte 3.4E-38 to 3.4E+38
double 8byte 1.7E-308 to 1.7E+308
long double 10 byte 3.4E-4932 to 1.1E+4932
character char or signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
void “void” type means no value. This is usually used to specify the type of
functions which returns nothing.

Derived Data Types


Derived data types are a combination of primitive data types. They are used to represent
a collection of data. They are:
❑ Arrays
❑ Structures
❑ Unions
❑ Enumerated
❑ Pointers

20. Explain the primary data types used in c


Primary data types:

The fundamental data types in C are


Date type Types Size (bytes) Range
Integer signed int 2 byte -32,768 to 32767
shot int 1byte -128 to 127
long int 4byte -2,147,483,648 to 2,147,483,647
unsigned int 2byte 0 to 65535
short int 1byte 0 to 255
long int 4byte 0 to 4,294,967,295
Floating point float 4 byte 3.4E-38 to 3.4E+38
double 8byte 1.7E-308 to 1.7E+308
long double 10 byte 3.4E-4932 to 1.1E+4932
character char or signed char 1 byte -128 to 127
unsigned char 1 byte 0 to 255
void “void” type means no value. This is usually used to specify the type of
functions which returns nothing.
21. State the rules for declaring variables in c
To declare any variable in C language you need to follow rules and regulation of C
Language, which is given below;

• Every variable name should start with alphabets or underscore (_).


• No spaces are allowed in variable declaration.
• Except underscore (_) no other special symbol are allowed in the middle of the variable
declaration (not allowed -> roll-no, allowed -> roll_no).
• Maximum length of variable is 8 characters depend on compiler and operation system.
• Every variable name always should exist in the left hand side of assignment operator
(invalid -> 10=a; valid -> a=10;).
• No keyword should access variable name (int for <- invalid because for is keyword).

22. Discuss about scope of variables in C.

A scope is a region of the program, and the scope of variables refers to the area of the
program where the variables can be accessed after its declaration.

In C every variable defined in scope. You can define scope as the section or region of a
program where a variable has its existence; moreover, that variable cannot be used or accessed
beyond that region.The variable can be declared in three places. These are:

Position Type
Inside a function or a block local variables
Out of all functions. Global variables
In the function parameters. Formal parameters
Example:

Local variable Global variable


#include <stdio.h> #include <stdio.h>
int z;
int main () int main ()
{ {
int x,y,z; int x,y;
x = 20; x = 20;
y = 30; y = 30;
z = x + y; z = x + y;
printf ("value of x = %d, y = %d and z = %d\n", printf ("value of x = %d, y = %d and z = %d\n",
x, y, z); x, y, z);
return 0; return 0;
} }
X,y,z are the local variables z is a global variable
23. Categorize and explain the various formatted input and output functions in C.
24. Solve the following program and give its output
Code Output
#include<stdio.h> 2
int main() 4
{ 1
int a; 8
float b;
char c;
double d;
printf("%d\n",sizeof(a));
printf("%d\n",sizeof(b));
printf("%d\n",sizeof(c));
printf("%d\n",sizeof(d));
return 0;
}

25. Solve the following program and find its output:

Code output
#include<stdio.h> 11-1-1
int main()
{
print(“%d”,4 % 3);
print(“%d”,4 % -3);
print(“%d”,-4 % 3);
print(“%d”,-4 % -3);
return 0;
}

26. Difference between formatted and unformatted statement?

27. What is meant by storage class of variable?

A storage class defines the scope (visibility) and life-time of variables and/or functions
within a C Program. They precede the type that they modify. We have four different storage
classes in a C program −

1. auto
2. register
3. static
4. extern
auto
➢ The auto storage class is the default storage class for all local variables
register
➢ The register storage class is used to define local variables that should be
stored in a register instead of RAM. This means that the variable has a
maximum size equal to the register size (usually one word) and can't have
the unary '&' operator applied to it (as it does not have a memory
location).
➢ The register should only be used for variables that require quick access
such as counters.

static
➢ The static storage class instructs the compiler to keep a local variable in
existence during the life-time of the program instead of creating and
destroying it each time it comes into and goes out of scope. Therefore,
making local variables static allows them to maintain their values between
function calls.

extern
➢ The extern storage class is used to give a reference of a global variable
that is visible to ALL the program files. When you use 'extern', the
variable cannot be initialized however, it points the variable name at a
storage location that has been previously defined.
➢ When you have multiple files and you define a global variable or
function, which will also be used in other files, then extern will be used in
another file to provide the reference of defined variable or function. Just
for understanding, extern is used to declare a global variable or function
in another file.
➢ The extern modifier is most commonly used when there are two or more
files sharing the same global variables or functions as explained below.
28. Solve the following program and find its output:

Code Output
#include<stdio.h> x=3 y=9,z=27
int main()
{
int x=3,y,z;
z=y=x;
z*=y=x*x;
printf(“x=%d y=%d,z=%d”,x,y,z);
return 0;
}

29. Write a C program to get Principal, Rate of Interest and No of Years as input from
the user and calculate the simple interest.
Code Output
#include<stdio.h> enter the principal amount: 10000
#include<math.h> enter the rate of interest: 2.5
int main() enter the no of years: 5
{ the simple interest is: 1250.00
int p,y;
float i,si;
printf("enter the principal amount:
");
scanf("%d",&p);
printf("enter the rate of interest: ");
scanf("%f",&i);
printf("enter the no of years: ");
scanf("%d",&y);
si=((p*y*i)/100);
printf("\nthe simple interest is:
%.2f",si);
return 0;
}
30. If a four digit number is input through the keyboard , write a C program to obtain
the sum of first and last digit of the number.
Code Output
#include<stdio.h> Enter the 4 digit number: 1234
#include<math.h> The sum of 1st and 4th digit is: 5
int main()
{
int a,sum,digit1,digit4;
printf("Enter the 4 digit number: ");
scanf("%d",&a);
digit1=a%10;
digit4=a/1000;
sum=digit1+digit4;
printf("\nThe sum of 1st and 4th
digit is: %d",sum);
return 0;
}

31. If the total selling price of 15 items and the total profit=25% is input through the
keyboard , write the c program to find the cost of one item.
code #include<stdio.h>
int main()
{
float p;
printf("enter the profit amount: ");
scanf("%f",&p);
float total=(p*100)/25;
printf("price of one item is:
%.2f",total/15);
return 0;
}
output enter the profit amount: 200
price of one item is: 53.33
32. Explain with example ++i and i++

There is a big distinction between the suffix and prefix versions of ++.
In the pre-increment version (i.e., ++i), the value of i is incremented, and the value of the
expression is the new value of i. So basically it first increments then assigns a value to the
expression.
In the postincrement version (i.e., i++), the value of i is incremented, but the value of the
expression is the original value of i. So basically it first assigns a value to expression and
then increments the variable.
Code Output
#include<stdio.h> 10
int main() 12
{
int a=10;
a=a++;
printf(“%d\n”,a);
a=++a;
return 0;
}

33. Solve the following expression using C programming: (a+b)2

Code Output
#include<stdio.h> the value of a is: 2
#include<math.h> the value of b is: 3
int main() the result of (a+b)^2 is: 25
{
int a,b,c;
printf("enter the values: ");
scanf("%d%d",&a,&b);
printf("\nthe value of a is: %d",a);
printf("\nthe value of b is: %d",b);
c = (pow(a,2)+pow(b,2)+(2*a*b));
printf("\nthe result of (a+b)^2 is: %d",c);
return 0;
}
34. Solve the following program and find its output:

Code Output
#include<stdio.h> 10
int main() 11
{ 11
int a=10; 10
a=a++;
printf(“%d\n”,a);
a=++a;
printf(“%d\n”,a);
a=a--;
printf(“%d\n”,a);
a=--a;
printf(“%d\n”,a);
return 0;
}

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