0% found this document useful (0 votes)
5 views9 pages

PPS Ans

Uploaded by

pranavkharat7888
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)
5 views9 pages

PPS Ans

Uploaded by

pranavkharat7888
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/ 9

Q.1. ⁠Explain Process of programming.

The process of programming involves writing code, compiling it into machine language, and then
executing the code to perform a task:

1. Understand the problem

Define the problem, identify objectives, and understand the needs of the end users.

2. Write code

Use a programming language to write a set of instructions, or program, that tells the computer what
to do.

3. Compile the code

A compiler converts the code into machine language so the computer can understand it.

4. Execute the code

The computer scans and executes the code to perform the task.

Some examples of programming languages include:

• C and C++: Compiled programming languages

• SQL: A programming language

• Java: A programming language

• Python: A programming language

Q.2. ⁠List types of computer software and explain each.


Here are some types of computer software and what they do:
• Application software
Also known as an app, this software helps users complete tasks. Examples
include mobile apps, business application software, and customer relationship
management (CRM) software.
• Operating system
This system software manages resources and provides services for other
software. There are many types of operating systems, including embedded,
real-time, distributed, single-user, multi-user, and mobile.
• Utility software
This system software performs tasks to keep the computer running, such as
security and optimization programs. Utility software runs in the background.
• Device drivers
This specialized software controls specific computer hardware. There are two
main types of device drivers: user device drivers and kernel device drivers.
• Freeware
This application software is free to download and use.
• Application development software
This software is used to develop apps. Examples include Meteor and Flutter.
The two main categories of software are application software and system
software. System software runs the computer's hardware and provides a
platform for applications to run on.

Q.3. ⁠Write a C program to declare and initialize variables of different data types
and display their sizes.
#incIude<stdio.h>
#incIude<conio.h>
void main()

int a=1O;
float b=JO.23;
char c='A';
double d=99.888888;
clrscr();
printf("\nEnter Values:");
printf("\nInteger Value:%d ",a);
printf("\nFIoat Value:%f ",b);
printf("\nCharacter:%c ",c);
printf("\nDoubIe Value:%d ",d);
printf("\nEnter Sizes:");
printf("Size Of Integer-%d Bytes\n",sizeof(int));
printf("Size Of Float-%d Bytes\n",sizeof(float));
printf("Size Of Double-%d Bytes\n",sizeof(double));
printf("Size Of Character-%d Bytes\n",sizeof(char));
getch();
}
Q.4. What is Control Statement in C Programming? Explain if-else in detail
with example.
A control statement in C programming is a construct that allows a computer
to execute certain code based on conditions. The if-else statement is a
fundamental control flow structure that uses conditional logic to make
decisions and direct the flow of a program.
The syntax for an if-else statement is:
• if (condition): The condition to be evaluated
• {: The statements to execute if the condition is true
• } else: The statements to execute if the condition is false
Here's an example of an if-else statement in action:
• if (surgePricingActive): Tests if surge pricing is active
• {: If surge pricing is active, this is what to do
• printf("Surge pricing is active. Fares might be higher now. "); Prints a
message to the user
• } else: If surge pricing is not active, this is what to do
• {: If surge pricing is not active, this is what to do
• printf("No surge pricing. Good time to book a ride! "); Prints a message
to the user
If-else statements are a crucial tool for programmers to create dynamic and
responsive programs. They allow programs to respond correctly to different
situations and inputs.
Q.5. Explain switch case in detail
n C programming, the switch statement provides an efficient way to execute
one out of multiple possible code blocks based on the value of a single
variable or expression. It is a control structure that is particularly useful when
you have many possible values to compare against a variable, as it is often
more readable and efficient than using multiple if-else statements.
Syntax of Switch-Case:
switch (expression) {
case constant1:
// Code block 1
break;

case constant2:
// Code block 2
break;

case constant3:
// Code block 3
break;

// more cases if necessary

default:
// Code block if no case matches
}
Q.6. Write a short note on loops.
In C programming, loops are control structures that allow you to execute a
block of code multiple times, based on certain conditions. They help in
automating repetitive tasks and optimizing code. C provides three main types
of loops:
1. For Loop: Used when the number of iterations is known beforehand.
2. While Loop: Used when the number of iterations is not fixed and depends on a
condition that is checked before each iteration.
3. Do-While Loop: Similar to the while loop, but the condition is checked after the
code executes, ensuring that the loop runs at least once.

Key Points:
• The for loop is ideal for situations where the number of iterations is
known.
• The while and do-while loops are used when the loop condition needs
to be evaluated during execution.
• Loops in C can be controlled using break (to exit the loop) and continue
(to skip the current iteration).
Loops are a fundamental part of C programming, enabling the creation of
efficient and concise code for repetitive tasks.

Q.7. What is function? Explain types of functions.


A function is a block of code that performs a specific task.
Types of function
There are two types of function in C programming:
• Standard library functions
• User-defined functions

Standard library functions


The standard library functions are built-in functions in C programming.
These functions are defined in header files. For example,
• The printf() is a standard library function to send formatted output to
the screen (display output on the screen). This function is defined in
the stdio.h header file.
Hence, to use the printf()function, we need to include
the stdio.h header file using #include <stdio.h>.
• The sqrt() function calculates the square root of a number. The function
is defined in the math.h header file.
Visit standard library functions in C programming to learn more.

User-defined function
You can also create functions as per your need. Such functions created by the
user are known as user-defined functions.
How user-defined function works?
#include <stdio.h>
void functionName()
{
... .. ...
... .. ...
}

int main()
{
... .. ...
... .. ...

functionName();

... .. ...
... .. ...
}
The execution of a C program begins from the main() function.
When the compiler encounters functionName();, control of the program
jumps to
void functionName()
And, the compiler starts executing the codes inside functionName().
The control of the program jumps back to the main() function once
code inside the function definition is executed.
Q.8. Explain while loop. Write a C program to reverse a number.
A while loop in C is a control flow statement that repeatedly executes a block
of code as long as a specified condition is true:
• Syntax
The syntax for a while loop is while (condition) { // code block to be executed
}
• Explanation
The while keyword marks the beginning of the loop, the condition is a
Boolean expression that is evaluated before each iteration, and the code
inside the curly braces is the body of the loop
• Purpose
While loops are commonly used when the number of iterations is unknown
to the user. They can save time, reduce errors, and make code more
readable.
• Example
For example, the following code will run the code in the loop over and over
again as long as a variable (i) is less than 5:
• Termination: The while statement can also terminate when
a break, goto, or return within the statement body is
executed. The continue statement can be used to terminate an
iteration without exiting the while loop.
• #include <stdio.h>
• #include <conio.h>
• void main()
• {
• int n, reverse = 0, remainder, original;

• printf("Enter an integer: ");
• scanf("%d", &n);

• original = n;

• while (n != 0) {
• remainder = n % 10;
• reverse = reverse * 10 + remainder;
• n /= 10;
• }

• if (original % 10 == 0) {
• printf("Reversed number = %d", reverse);

• while (original % 10 == 0) {
• printf("0");
• original /= 10;
• }
• } else {
• printf("Reversed number = %d", reverse);
• }

• return 0;
• }

Q.9. Write a C program to perform any two arithmetic operations on integer


numbers using functions.
#include <stdio.h>

// Function to perform addition


int add(int a, int b) {
return a + b;
}
// Function to perform multiplication
int multiply(int a, int b) {
return a * b;
}

int main() {
int num1, num2, sum, product;

// Input two integer numbers


printf("Enter two integers: ");
scanf("%d %d", &num1, &num2);

// Perform addition
sum = add(num1, num2);

// Perform multiplication
product = multiply(num1, num2);

// Output the results


printf("Sum of %d and %d is: %d\n", num1, num2, sum);
printf("Product of %d and %d is: %d\n", num1, num2, product);

return 0;
}

You might also like