[go: up one dir, main page]

0% found this document useful (0 votes)
44 views39 pages

C Programming Solve: 1. Syntax Errors: 2. Semantic Errors

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)
44 views39 pages

C Programming Solve: 1. Syntax Errors: 2. Semantic Errors

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/ 39

C PROGRAMMING SOLVE

3(c).array processor:An array processor is a specialised computer processor


designed to efficiently perform operations on large arrays of numbers.
Key features and characteristics:
Parallel architecture:Multiple processing elements (PEs) work.simultaneous
operations on different data elements.
Single Instruction, Multiple Data (SIMD):A single instruction can execute the
same operation on multiple data elements simultaneously.
Vector processing: Vector instructions operate on entire vectors at once
High-performance memory:Array processors often feature fast memory
systems with high-speed processing.

Types of array processors:


Attached array processors:Separate units attached to a host computer as
co-processors.Handle array computations from the main CPU,

Distributed array processors:Processing elements are integrated within the


host computer's memory system.

9(a).difference between compiler and interpreter :

Compiler Interpreter

1.Compiler takes enter program as input 1.Interpreter takes enter program as input.

2.Intermediate object code is generated 2.does not generated

3.memory requirement more 3.less

4.execution time faster 4.slower

5.Languages C, C++, Java 5.Python, JavaScript, Ruby, PHP,

9 or)Types of error in program.


1. Syntax Errors :Occur when the code violates the grammar rules of the
programming language.Example: Missing semicolon syntax error.
2. Semantic Errors:Occur when the code is syntactically correct but does not
behave as intended due to mistakes in logic or meaning.Can be difficult to detect
Example: Incorrect conditional statement semantic error:
3. Logic Errors:Flaws in the program's logic, leading to incorrect results despite the
code being syntactically correct.Example: Incorrect loop logic error:
4. Runtime Errors:Occur during the execution of the code, due to unexpected
inputs or conditions and produce incorrect results.Examples:Division by zero error.
5. Compile-time errors : Compile-time errors, also known as syntax errors or
compilation errors, are errors that occur during the compilation process of a program.

Difference between high,middle & low level language


1.High level language 1.Middle level languages do 1.Low level languages
provides almost everything not provide all the built in provides nothing other than
that the programmer might functions found in high level access to the basic
need to do as already built languages instruction set.
into the language.

2.Java,python 2.c,c++ 2.Assembly language

Easier to learn and Easier to learn and Harder to learn and


use,portable & larger use ,portable use, less portable &
memory required compare to low level less memory
language & less required
memory required

10.what is meant by function overloading and operator overloading with c++


examples .:

Function Overloading:Function overloading is a feature of object-oriented


programming where two or more functions can have the same name but different
parameters.

C++
#include <iostream>
using namespace std;
class Cal {
public:
int add(int a,int b){
return a + b;
}
int add(int a, int b, int c)
{
return a + b + c;
}
};
int main(void) {
Cal C; // class object declaration.
cout<<C.add(10, 20)<<endl;
cout<<C.add(12, 20, 23);
return 0;
}

Operator Overloading:Operator overloading is a compile-time polymorphism in


which the operator is overloaded to provide the special meaning to the user-defined
data type.Example:

C++
#include <iostream>
using namespace std;
class Test
{
public:
int num;

Test(int x){
num =x;
}
void operator ++() {
num = num+2;
}
void Print() {
cout<<"The Count is: "<<num;
}
};
int main()
{
Test tt(8);
++tt; // calling of a function "void operator ++()"
tt.Print();
return 0;
}
Difference between i++ and ++i with example in summarize

Here's a concise summary of the difference between i++ and ++i:

Time of Increment:

● ++i (pre-increment): Increases the value of i before using it in the


expression.
● i++ (post-increment): Uses the current value of i first, then increments it.

Example:

C++

int i = 5;

int j = ++i; // i becomes 6, j is 6

int k = i++; // k is 6, i becomes 7

When to Use Each:

● Use ++i when we need the incremented value immediately.


● Use i++ when we need the original value first and then want to increment
it.

Nested if:A nested if statement is a conditional statement that contains another if


statement within its body. This allows for more complex decision-making, where
multiple conditions can be checked in a sequential manner.

Structure:

C
if (condition1) {

// Code if condition1 is true

if (condition2) { // Nested if

// Code if both conditions are true

} else {

// Code if condition1 is true but condition2 is false

} else {

// Code if condition1 is false

2.c.Write the difference between structure and union in C


programming language with examples.

Structures (struct)

● Purpose: Group multiple variables of different data types under a single


name

Unions (union)

● Purpose: Allow different data types to share the same memory location,
but only one member can hold a value at a time.

Key Differences Table:

Feature Structure (struct) Union (union)


Memory Separate for each Shared by all members
member

Size Sum of member sizes Size of largest member

Accessing Dot operator (.) Dot operator (.)


members

Simultaneou All members can hold Only one member can


s values values hold a value at a time

Use cases Complex data Memory optimization,


structures, grouping variant data types
related data

1.or.a)What is a loop? Explain loop structure with flow diagram


a loop is a control flow structure that allows a block of code to be repeated multiple
times until a certain condition is met. It's a fundamental concept that enables efficient
execution of repetitive tasks.
Here's a breakdown of the loop structure with a flow diagram:
1. Start: The program execution begins.
2. Initialization:Variables used for controlling the loop are assigned initial values.
○ Example: int i = 0; to initialize a counter variable.
3. Condition Check:A Boolean expression is evaluated to determine whether to
continue the loop.
○ Example: i < 10; checks if the counter is less than 10.
4. Loop Body:If the condition is true, the code within the loop body executes.
5. Update:Variables involved in the loop condition are updated to progress towards
termination.
○ Example: i++; increments the counter to move closer to the end
condition.
6. Iteration:The process returns to the condition check (step 3).
● Steps 3-5 repeat as long as the condition remains true.
7. End:When the condition becomes false, the loop terminates,
Flow Diagram:

2.a.define object.How to make object in c++ with example.


Object:Object is a real world entity.In other words, object is an entity that has
state and behavior. Here, state means data and behavior means
functionality.Object is an instance of a class. All the members of the class can
be accessed through object.
Example:
1. #include <iostream>
2. using namespace std;
3. class Student {
4. public:
5. int id;//data member (also instance variable)
6. string name;//data member(also instance variable)
7. };
8. int main() {
9. Student s1; //creating an object of Student
10. s1.id = 201;
11. s1.name = "Sonoo Jaiswal";
12. cout<<s1.id<<endl;
13. cout<<s1.name<<endl;
14. return 0;
15. }
b.What is friend function? Write its advantages and disadvantages.
Friend Function :a friend function can allow access to private and protected
members of a class in C++. They are the non-member functions that can
access and manipulate the private and protected members of the class for
they are declared as friends.

////bhujar jonno
.#include <iostream>
using namespace std;

class base {
private:
int private_variable;

protected:
int protected_variable;

public:
base()
{
private_variable = 10;
protected_variable = 99;
}

// friend function declaration


friend void friendFunction(base& obj);
};

// friend function definition


void friendFunction(base& obj)
{
cout << "Private Variable: " << obj.private_variable
<< endl;
cout << "Protected Variable: " << obj.protected_variable;
}

// driver code
int main()
{
base object1;
friendFunction(object1);
return 0;
}

Advantages of Friend Functions


● A friend function is able to access members without the inheriting the class.
● The friend function acts as a bridge between two classes by accessing their
private data.
● It can be used to increase the versatility of overloaded operators.
● It can be declared either in the public or private or protected part of the class.
Disadvantages of Friend Functions
● Friend functions have access to private members of a class from outside the
class which violates the law of data hiding.
● Friend functions cannot do any run-time polymorphism in their members.
Page-3
3.a)Define algorithm and flow chart.
Algorithm:A finite set of instructions or rules produce a desired output for a
given input. It's a step-by-step procedure for solving a problem or a task.
Flowchart:A graphical representation of an algorithm, using symbols and
connecting arrows. It visualizes the steps and logic of a process.

Page-4
5.c)programming language : A language that are used to communicate with
other computers.Several types of programming language that exist.

Advantages of High-Level Languages:

● Easier to learn and use: High-level languages have syntax closer to


natural language .
● More productive: high-level languages allow programmers to do
more in less time.
● More readable and maintainable: Code written in high-level
languages is generally more readable and understandable
● Portable: high-level languages are platform-independent.
● Wide range of applications: High-level languages can be used for a
wide variety of purposes, from web development and mobile apps

Disadvantages of High-Level Languages:


● Lower performance: High-level languages run slower than their
low-level language
● Larger memory: High-level programs generally require more memory
to run than low-level programs..
● Limited control over hardware: High-level languages provide less
direct control over hardware.

5.b) find 1+2+3+......n


#include<stdio.h>

int main()
{
int n,sum=0;

printf("N = ");
scanf("%d",&n);

for(int i=1;i<=n;i++){
sum = sum + i;
}

printf("summation = %d",sum);

5 .or .a)What is translator software? Discuss its types.


Translator software, also known as translation software, is a computer
program that assists in the translation of text or speech from one language to
another.Here are the common types of translator software:
1. Machine Translation (MT) Software:Translates text automatically without
human intervention.Examples: Google Translate, Microsoft Translator,
Amazon Translate.
2. Computer-Assisted Translation (CAT) Tools:Designed to support human
translators by automating repetitive tasks.Examples: Wordfast,
Memsource.
3. Translation Management Systems (TMS):Integrate CAT
tools.Examples: Smartcat, Phrase.
2.b)Different loop types in c,,,,,,
Common Loop Types:
For Loop: Used when we know the number of iterations.Example: for (int i = 0;
i < 10; i++) { ... }
While Loop: Used when you don't know the exact number of iterations but
have a condition to check.Example: while (x < 50) { ... }
Do-While Loop: Ensures the loop body executes at least once, even if the
initial condition is false.Example: do { ... } while (y > 0);

2 .or.a)What is a variable? Write the rules for writing


variables
a variable is a storage location in the computer's memory that holds a value.
It's like a labelled box where we can store data to use later in our program.

Rules for naming variables:


.Start with a letter (a-z or A-Z) or an underscore (_):
○ Valid: name, _count, firstName
○ Invalid: 123name, @username
.Can contain letters, numbers, and underscores:
○ Valid: total_items, user2, is_active
.Case sensitive:
○ age is different from Age or AGE.
.Restrictions on keywords:
○ Avoid using reserved keywords specific to the programming
language (e.g., int, if, while).
.Descriptive and meaningful names:
○ Avoid single-letter names

2.c).2^2+4^2+6^2+...+n^2 code in c

○ #include <stdio.h>

○ int main() {
○ int n,sum=0;


○ printf("Enter the value of n: ");
○ scanf("%d", &n);

○ // Loop through even numbers from 2 to n
○ for (int i = 2; i <= n; i += 2) { // Increment by 2 to consider only
even numbers
○ sum= sum + i * i; // Add the square of each even number
○ }

○ printf("The sum of squares of even numbers from 2 to %d is:
%d\n", n, sum);

○ return 0;
○ }

○ page-5
1.a)Difference between call by value and call by reference?
6.pointer is not used 6. used
call by value and call by reference || C programming || [Bangla Tutorial]
(youtube.com)



1.b)Can I use int data type to store 32678 value? If not why? //////short
int hobe
No, you cannot use the standard int data type to store the value 32678.

Range of int: The typical range of the int data type on most systems is -32768
to 32767. This means it can only accommodate integers within this range. 32678
falls outside this range, so trying to store it in an int variable would lead to
unexpected behavior or errors.
Alternative Data Types:

To store the value 32678, you have two primary options:

1. long int:(-2^31 to 2^31 - 1)

○ It's specifically designed to hold larger integer values.


○ Its range is typically -2147483648 to 2147483647, which can easily
accommodate 32678.
2. Unsigned short int (0 to 2^32 - 1)
○ It can only store non-negative integers (0 and positive values).
○ Its range is usually 0 to 65535, which includes 32678.

Here's the table of data types in C with their ranges expressed in 2^power
notation:

Data Type Size Range (2^power)


(bytes)

char 1 -2^7 to 2^7 - 1 (signed) or 0 to 2^8 - 1


(unsigned)

unsigned 1 0 to 2^8 - 1
char

short int 2 -2^15 to 2^15 - 1

unsigned 2 0 to 2^16 - 1
short int

int 4 -2^31 to 2^31 - 1


unsigned int 4 0 to 2^32 - 1

long int 4 or 8 -2^31 to 2^31 - 1 (at least)

unsigned 4 or 8 0 to 2^32 - 1 (at least)


long int

float 4 Approximately -2^126 to 2^126

double 8 Approximately -2^1022 to 2^1022

C.go to page number 3

1.D. call by value and call by reference

1.or .a)Define thread.

A thread is the smallest sequence of programmed instructions that can be


managed independently by a computer's operating system. It's a fundamental
unit of CPU utilization.Advantages of using threads:
Improved responsiveness and performance
Efficient resource utilization
Simplified parallel programming
Better handling of asynchronous operations
b.Define recursion with example
Recursion is a programming technique where a function calls itself directly or
indirectly to solve a problem. It is breaking down a problem into smaller.
Example:
#include <stdio.h>

int main() {
int n;

printf("Enter the value of n: ");


scanf("%d",&n);
int factorial = fact(n);
printf("The factorial of %d is %d\n", n, factorial);

}
int fact(int a){
if(a==0)
return 1;
else
return a*fact(a-1);

}
c)Define pointer.
Pointer:The pointer is a variable which stores the address of another
variable.Pointer reduces the code and improves the performance.We can
return multiple values from a function using the pointer.
///just understanding DMA সি প্রোগ্রামিং -২৬ঃ Pointer- Dynamic memory allocation,
malloc(), calloc(), free(), realloc() (youtube.com)

Secure than calloc less secure


2.a)What is Object Oriented Programming? Why is it needed? Write its
basic concepts.
OOP:Object Oriented Programming is a paradigm that provides many
concepts such as inheritance, data binding, polymorphism etc.
Benefits of OOP:
● Improved code organization and readability
● Enhanced maintainability and reusability
● Easier code debugging and testing
● Better modeling of real-world systems
● Increased code flexibility and adaptability
Inheritance:When one object acquires all the properties and behaviours of
parent object i.e. known as inheritance
Polymorphism:When one task is performed by different ways i.e. known as
polymorphism.
Abstraction:Hiding internal details and showing functionality is known as
abstraction.
Encapsulation:Binding (or wrapping) code and data together into a single
unit is known as encapsulation.
b.Difference between class and object with example
c++.
difference between class and object in c++ | class and
object | learning c with programming (youtube.com)
Class Object
class Car { Car myCar; // Create an object of
the Car class
void start() {
cout << "Car started!\n";
} myCar.start(); // Output: Car started!

};

C.function overloading and overriding…..


Page-2
function overriding:If derived class defines same function as defined in its
base class, it is known as function overriding
1. #include <iostream>
2. using namespace std;
3. class Animal {
4. public:
5. void eat(){
6. cout<<"Eating...";
7. }
8. };
9. class Dog: public Animal
10. {
11. public:
12. void eat()
13. {
14. cout<<"Eating bread...";
15. }
16. };
17. int main(void) {
18. Dog d ;;
19. d.eat();
20. return 0;
21. }
Or:static variable and static method
If we apply static keyword with any method, it is known as static
method.Static Methods can access class variables (static variables)
without using object of the class, If we apply static keyword with any
variable, it is known as static variableThe static variable gets memory
only once in class area at the time of class loading.

class JavaExample
{

static int i = 100;


static String s = " book ";
static void display()
{
System.out.println("i:"+i);
System.out.println("book:"+s);
}

public static void main(String args[])


{
JavaExample obj = new JavaExample();

display();
}
}

2.b)Basic Operations in Arrays


The basic operations in the Arrays are insertion, deletion, searching, display,
traverse, and update. Following are the basic operations supported by an
array.
​ Traverse − print all the array elements one by one.
​ Insertion − Adds an element at the given index.
​ Deletion − Deletes an element at the given index.
​ Search − Searches an element using the given index or by the value.
​ Update − Updates an element at the given index.
​ Display − Displays the contents of the array.
5.b)go to page 16.
5.c)Explain for loop structure
Structure:
for (initialization; condition; increment/decrement) {
// code to be executed repeatedly
}
Go to page 6,10
5.or.a)Stages/steps involved in programming:
1.Analyzing the problem 2.Algorithm design 3.Make flow chart 4.Coding
5.Debugging 6.Testing 7.Final output 8.Documentation.

Page-8

5.or.b)1^2+2^2+3^2+4^2+5^2+.....................+N^2
Go to page 9 ( i repace by i*i)
6.Define function prototype.
In programming, a function prototype is a declaration of a function.
Key elements of a function prototype:
1. Return type: Declares the data type of the value the function will return
2. Function name: The identifier used to call the function.
3. Parameter list: It lists the names and data types of the arguments the function
expects to receive.
4. Optional modifiers: Some languages allow additional modifiers to specify
features
Example (C++):

int addNumbers(int a, int b); // Function prototype

Explanation:
● int: Return type
● addNumbers: Function name.
● (int a, int b): Parameter list,
Function overloading –go to page 2

7.Define code generation and code optimization.

Code Generation:It's the process of translating a program's intermediate


code into executable machine code that the target hardware can directly
understand and execute.It's typically the final stage of a compiler or
interpreter.
● It involves:
Assigning registers to variables
Generating instructions for operations
Managing memory allocation
Handling jumps and branches
Producing the final object code
Code Optimization:It's the process of modifying code to improve its
performance or resource usage without changing its functionality.
● It can be applied at various stages of compilation, including:
○ During code generation
○ After code generation
7.or)
Pointers :The pointer is a variable which stores the address of another
variable. This variable can be of type int, char, array, function, or any other
pointer.
Advantage of pointer
1) Pointer reduces the code and improves the performance,
2) We can return multiple values from a function using the pointer.
3) It makes you able to access any memory location in the computer's
memory.
Declaring a pointer:The pointer in c language can be declared using *
(asterisk symbol).
1. int *a;//pointer to int
2. char *c;//pointer to char

3.a)Array:An array is defined as the collection of similar type of data items


stored at contiguous memory locations. Arrays are the derived data type in C
programming language

Advantage of C Array(not included)

1) Code Optimization

2) Ease of traversing

3) Ease of sorting:

4) Random Access

Declaration of C Array

We can declare an array in the c language in the following way.

1. data_type array_name[array_size];
Now, let us see the example to declare the array.

1. int marks[5];

3.0r.a)go to page 10.

Local Variables:Declared within a function.Example


#include <stdio.h>

void myFunction() {
int localVar = 10; // Local variable
printf("Inside function: localVar = %d\n", localVar);
}

int main() {
myFunction();
// printf("Inside main: localVar = %d\n", localVar); // Error: localVar is not
accessible here
return 0;
}

Global Variables:Declared outside all functions.Example


C
#include <stdio.h>

int globalVar = 20; // Global variable

void myFunction() {
printf("Inside function: globalVar = %d\n", globalVar);
}

int main() {
printf("Inside main: globalVar = %d\n", globalVar);
myFunction();
return 0;
}

3.or.b) go to page 13
3.or.c)go to page 3
Page-9
7.Program in C language to find area and perimeter of circle
#include<stdio.h>
int main()
{
double r,area,Perimeter.;
printf("Enter radius : ");
scanf("%lf",&r);
area=3.1416*r*r;
Perimeter=2*3.1416*r;
printf("Area of the circle: %.2lf \n", area);
printf("Perimeter. of the circle: %.2lf units\n", Perimeter.);
}

1.a.find prime numbers in c


#include<stdio.h>

int main(){
int i,n,count=0;

printf("Enter any number :");


scanf("%d",&n);
if(n<=1){
count=1;
}
for(i=2; i<n; i++){
if(n%i==0){
count++;
break;
}
}
if(count==0)
printf("%d number is Prime",n);
else
printf("%d number is not Prime",n);

}
C programming Bangla Tutorial : Check Prime Number (youtube.com)

3.or.b)go to page 7,16 (object),,,


Inheritance:When one object acquires all the properties and behaviours of
parent object i.e. known as inheritance.
C++ supports five types of inheritance:
Single inheritance
Multiple inheritance
Hierarchical inheritance
Multilevel inheritance
Hybrid inheritance
#include <iostream>

class Animal {
public:
void eat() {
std::cout << "Animal is eating." << std::endl;
}
};

class Dog : public Animal {


public:
void bark() {
std::cout << "Woof!" << std::endl;
}
};

int main() {
Dog dog;
dog.eat(); // Inherited from Animal
dog.bark(); // Specific to Dog
return 0;
}

Polymorphism:When one task is performed by different ways i.e. known as


polymorphism.
Function overloading:go to page 16
Function Overriding:go to page 16
Dynamic binding (virtual functions): The specific method implementation to
call is determined at runtime.
Page-10
8.go to page 14…..
Write a program to find gcd of two numbers using recursive functions .
Here's the C program to find the GCD of two numbers using recursion:

C
#include <stdio.h>
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}

int main() {
int num1, num2;

printf("Enter two positive integers: ");


scanf("%d %d", &num1, &num2);

int result = gcd(num1, num2);

printf("GCD of %d and %d is %d\n", num1, num2, result);

return 0;
}

4.go to page 9,10………………………

Write a program in C to find the area of a triangle


C
#include
<stdio.h>

int
main()
{
float base, height, area;

printf("Enter the base of the triangle: ");


scanf("%f", &base);

printf("Enter the height of the triangle: ");


scanf("%f", &height);

area = 0.5 * base * height;

printf("Area of the triangle = %.2f square units\n", area);

return 0;
}
5.or.What do you mean by low level language? Write its advantages and
disadvantages
Low-Level Language:Assembly language uses symbolic to represent
various machine language instructions(ADD,SUB,MUL,DIV,INC). It has to
convert into machine language. Assembler convert assembly language to
machine language.
Advantages:
● Performance: They offer speed and efficiency
● Fine-grained control:we have greater control over hardware resources,
memory management, and optimizations.
● Portability: Some languages like assembly are relatively
machine-independent and can run on different platforms.
Disadvantages:
● Complexity: They are harder to learn and use
● Error-prone: The lack of built-in checks makes them to errors
● Readability and maintainability: Code can be less readable and harder
to maintain
Go to page - 9
Page-11
10.or .go to page 13 (datatype)
1.a.Flowchart:A graphical representation of an algorithm, using symbols and
connecting arrows. It visualizes the steps and logic of a process.
How many types of flowcharts and what are they? Write function with
diagram of program flowchart drawing symbols.
While there are many types of flowcharts, here are some of the most common
ones:
1. Process Flowchart:
2. Workflow Diagram:
3. Swimlane Flowchart:
4. Data Flow Diagram (DFD):
5. Program Flowchart:
Here's a simple example of a program flowchart using common symbols:
● Oval for Start
● Parallelogram for Input
● Rectangle for Process
● Diamond for Decision
● Parallelogram for Output
● Oval for End
● Arrows indicating flow direction]
1.or)Why is C Plus Plus called an improved version of C?
C++ is indeed considered an improved version of C for several reasons:
1. Object-Oriented Programming (OOP): C++ introduces object-oriented
features
2. Templates: C++ allows creating generic templates
3. Exception Handling: C++ handles errors with exception handling
mechanisms
4. Standard Template Library (STL): C++ boasts a rich Standard Template
Library (STL)
5. Memory Management: C++ offers both manual and automatic memory
management,
6. Inline Functions: C++ allows you to declare functions within other functions
7. Enhanced Syntax: C++ inherits the familiar syntax of C.
2.a)Program:A set of instruction that are used to solve a particular problem.
Go to page -18
2.b) Go to page -20

6.or) Go to page -8
Page-12
1.b) Go to page -18
1.c)Go to page -3
1.or.b)Go to page -24
2.c)Go to page -19
3.a)Go to page -15
4.b)Go to page -1
Page-13
10.or)Go to page -5

Difference between Generation Language

1st Generation 2nd Generation 3rd Generation 4th Generation 5th Generation

Called Called Called High Called Natural


Machine level Assembly level Non-procedur language
programming level programming al level programming
programming programming

No need for Need Need Need Need


translator translator translator translator translator
software software as software as software software
Assembler compiler
,interpreter

Education is Education is 2 2 2
very fast slow
compare 1st
generation

Machine Assembly c,c++ Query Q&A,HAL(Hu


Language Language Languages man Access
Language)

Slow Significant 2 2 2
performance performance
improvement
over the first
generation.

1.b)Go to page -13


1.or.b)write c program to find largest number among three numbers
#include<stdio.h>

int main(){
int n,a,b,c;

printf("Enter three numbers ");


scanf("%d %d %d",&a,&b,&c);

if(a>b && a>c){


printf("%d is largest",a);
}
else if(b>a && b>c){
printf("%d is largest",b);
}
else{
printf("%d is largest",c);
}
}
2.a)Go to page -12
2.b)how to declare a union in c
1. Use the union keyword:
2. Enclose members within curly braces:
3. Terminate with a semicolon:
union un {
int member1;
char member2;
float member3;
};

Example:Go to page -6

Page-14
9.or)Go to page -15
1.c)find leap year using c program

1.or.b)benefits of recursion function —---Go to page -14


● Recursion offers powerful benefits for elegance, readability,
problem-solving, and specific algorithms.
● Carefully consider its trade-offs regarding performance, stack usage,
and debugging complexity
● Use recursion strategically to leverage its strengths for problems.
1.or.c)Go to page -20
2.b))Go to page -15,22

Advantage of Encapsulation in Java

It provides the control over the data.

It is a way to achieve data hiding in Java

The encapsulate class is easy to test. So, it is better for unit testing.

page-15
8.Go to page -6
1.a)Go to page -26
1.b)Go to page -17,20
define register variable
Register variables are a special type of variable in some programming
languages that are stored directly in the CPU's registers instead of in main
memory. This provides faster access and manipulation of their values.
● Declaration: They are declared using the register keyword before the
variable type in most languages that support them (e.g., register int
count;).
1.or.b.)Go to page -19
page-16
5.a.)Go to page -15
8)Go to page -7
1.b)Go to page -3
1.c)
Encapsulation:Binding (or wrapping) code and data together into a single
unit is known as encapsulation.
Go to 29

Abstraction in Java : Abstraction is a process of hiding the implementation


details and showing only functionality to the user. It shows only important
things to the user and hides the internal details .There are two ways to
achieve abstraction in java are Abstract class (0-100%) and Interface (100%) .
Abstract Class: A class that is declared using “abstract” keyword is known
as abstract class.abstract methods (methods without body) as well as
concrete methods (regular methods with body). A normal class (non-abstract
class) cannot have abstract methods. abstract class create an object. If a
class contain any abstract method then the class is declared as abstract class.
because it can also have concrete method.
Abstract method : Method that are declared without any body within an
abstract class are called abstract method. The method body will be defined
by its subclass.Abstract method can never be final and static.
abstract class A
{
abstract void callme();
}
class B extends A
{
void callme()
{
System.out.println("this is callme.");
}
public static void main(String[] args)
{
B b = new B();
b.callme();
}
}

Page-17
5.or.b)Go to page -1
7)Go to page -5
2.a)Go to page -13
2.b)Go to page -6
2.or.a)Go to page -5
2.or.b)Explain the difference between recursion and recursive function
Recursion is a programming technique where a function calls itself directly or
indirectly, breaking down a problem into smaller subproblems. It's a powerful
approach for solving problems.
Recursive function is a function that employs recursion to solve a problem. It
has two essential components:
1. Base case(s): The simplest cases that can be solved directly without
further recursion. They act as the stopping points for the recursive calls.
2. Recursive case(s): The cases that break the problem down into smaller
versions of itself, calling the function recursively.
Key points to remember:
● Recursion itself is the concept of a function calling itself.
● A recursive function is a specific implementation of that concept,
designed to solve a problem using recursion.

Go to 14 page
Page-18
7.or) Go to page 9 ( i repace by i*i)

8) Go to page 22
Page-19

1) Go to page 1
7) Go to page 19
11)finds and prints even numbers from 1 to 50:
#include <stdio.h>

int main() {
int i;

printf("Even numbers between 1 to 50 (inclusive):\n");

for (i = 1; i <= 50; i++) {


// Check for even numbers using the modulo operator (%)
if (i % 2 == 0) {
printf("%d ", i);
}
}

return 0;
}
15.find the Fibonacci series
#include <stdio.h>

int main() {
int n, i, first = 0, second = 1, fibo;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci Series: ");

printf("%d %d ", first, second); // Print the first two terms

for (i = 3; i <= n; ++i) {


fibo = first + second;
printf("%d ", fibo);
first = second;
second = fibo;
}

return 0;
}

Page -20
20) print prime number
#include <stdio.h>
int main() {
int i, num, count;

printf("Prime numbers between 1 and 100:\n");

for (num = 2; num <= 100; num++) {


count = 1; // Assume the number is prime initially

// Check for divisibility from 2 up to the square root of num


for (i = 2; i * i <= num; i++) {
if (num % i == 0) {
count = 0; // Number is not prime
break; // No need to check further
}
}

// Print the prime number


if (count) {
printf("%d ", num);
}
}

printf("\n");
return 0;
}

12)Go to page 9
17)Go to page 27
Page-21
11)Go to page 13
14)Go to page 18
16)Go to page 22
10)Go to page 6
17)find summation of fibonacci series in c
#include <stdio.h>

int main() {
int n, i, first = 0, second = 1,sum=0, fibo;

printf("Enter the number of terms: ");


scanf("%d", &n);

printf("Fibonacci Series: ");

printf("%d %d ", first, second); // Print the first two terms

for (i = 3; i <= n; ++i) {


fibo = first + second;
printf("%d ", fibo);

sum = sum + fibo;


first = second;
second = fibo;
}
printf("\n");
printf("Summation of series = %d",sum+1);

return 0;
}
Page-22
1.or.a)Go to page 26
10.or.)Go to page 25

Page-23
1.or.a)Go to page 26
7.or)Go to page 9
1.or)Go to page 26
Page-24
or)Go to page 26
6)Go to page 9
9)Go to page 10,25
1.or)Go to page 26

Page-25
6).Go to page 25
5.or)Go to page 9
Page-26
6)Go to page 9
1)Go to page 26
4.a)Go to page 10,20,
Page-27
6)Go to page 25

c/////////////code/////////
7.#include <stdio.h>

int main() {
float C,F;
scanf("%f",&F);
C=((F-32)/9)*5;
printf("%f",C);
return 0;
}

8.#include <stdio.h>

int main() {
int a,b,c;
printf("Enter three numbers :");
scanf("%d %d %d",&a,&b,&c);
if(a>=b && a>=c)
printf("%d is largest",a);
else if (b>=a && b>=c)
printf("%d is largest",b);
else
printf("%d is largest",c);
return 0;
}

10.#include <stdio.h>

int main() {
int i,n,sum=0;
scanf("%d",&n);
for(i=0;i<=n;i++)
{
sum=sum+i;
}
printf("Summation = %d",sum);
return 0;
}
19.#include <stdio.h>
#include <math.h>
int main() {
int i,sum=0,n;
printf("Enter any number that you want to display for series:");
scanf("%d",&n);
for(i=1;i<=n;i=i+1){
sum=sum+pow(i,i);
}
printf("Summation = %d",sum);
return 0;
}
30.#include <stdio.h>

int main() {
int first =0,second=1,count=0,fibo,n;
printf("Enter the range of series :");
scanf("%d",&n);
while(count<n){
if(count<=1){
fibo = count;
}
else{
fibo = first + second;
first = second;
second = fibo;
}
printf(" %d ",fibo);
count++;
}

return 0;
}

33.#include <stdio.h>

int main() {
int n,count=0;
printf("Enter any numbers: ");
scanf("%d",&n);
for(int i =2;i<n;i++){
if(n%i==0){
count++;
break;
}
}
if(count==0){
printf("Prime");

}
else{
printf("Not prime");
}

return 0;
}
34.#include <stdio.h>

int main() {
int even_count = 0, odd_count = 0, num;

// Repeat for 10 numbers


for (int i = 1; i <= 10; i++) {
printf("Enter number %d: ", i);
scanf("%d", &num);

// Check if the number is even or odd


if (num % 2 == 0) {
even_count++;
} else {
odd_count++;
}
}

// Print the counts of even and odd numbers


printf("Number of even numbers: %d\n", even_count);
printf("Number of odd numbers: %d\n", odd_count);

return 0;
}
35.#include <stdio.h>

int main() {
int num,positive=0,negative=0;

for(int i=1;i<=10;i++){
printf("Enter number %d:",i);
scanf("%d",&num);
if(num>0){
positive++;
}else{
negative++;
}
}
printf("positive = %d",positive);
printf("negative= %d",negative);
return 0;
}
36.#include <stdio.h>
#include <ctype.h>
int main() {
char xx;
printf("Enter any character:");
scanf("%c",&xx);
printf("Uppercase equivalent of %c is %c\n",xx,toupper(xx));
}
38.#include <stdio.h>
#include <math.h>

int main() {
float a, b, c, discriminant, root1, root2;

printf("Enter coefficients a, b, and c: ");


scanf("%f %f %f", &a, &b, &c);

// Calculate discriminant
discriminant = b * b - 4 * a * c;

// Calculate roots
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("Roots are real and different:\n");
printf("Root 1 = %.2f\n", root1);
printf("Root 2 = %.2f\n", root2);
} else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("Roots are real and same:\n");
printf("Root 1 = Root 2 = %.2f\n", root1);
} else {

printf("Roots are complex and different:\n");

return 0;
}
20) print prime number
#include <stdio.h>
int main() {
int i, num, count;

printf("Prime numbers between 1 and 100:\n");

for (num = 2; num <= 100; num++) {


count = 0; // Assume the number is prime initially

// Check for divisibility from 2 up to the square root of num


for (i = 2; i * i <= num; i++) {
if (num % i == 0) {
count ++; // Number is not prime
break; // No need to check further
}
}

// Print the prime number


if (count==0) {
printf("%d ", num);
}
}

printf("\n");
return 0;
}

You might also like