C Program to Draw a Circle Using C Graphics

C Program to Draw a Circle Using C Graphics

Write a program in C to draw a circle on screen using graphics.h header file
In this program, we will draw a circle on screen having centre at mid of the screen and radius of 80 pixels. We will use outtextxy and circle functions of graphics.h header file. Below is the detailed descriptions of graphics functions used in this program.

Function Description
initgraph It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode.
getmaxx It returns the maximum X coordinate in current graphics mode and driver.
getmaxy It returns the maximum Y coordinate in current graphics mode and driver.
outtextxy It displays a string at a particular point (x,y) on screen.
circle It draws a circle with radius r and centre at (x, y).
closegraph It unloads the graphics drivers and sets the screen back to text mode.

C program to draw circle using c graphics

In this program we first initialize graphics mode, by passing graphics driver(DETECT), default graphics mode and specifies the directory path where initgraph looks for graphics drivers (*.BGI). It is the first step you need to do during graphics programming. Setting graphics driver as DETECT, means instructing the compiler to auto detect graphics driver. Here we are using getmaxx and getmaxy function to find the center coordinate of the screen.

C Program to Draw a Circle Using C Graphics

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
 
int main(){
   int gd = DETECT,gm;
   int x ,y ,radius=80;
   initgraph(&gd, &gm, "C:\\TC\\BGI");
   /* Initialize center of circle with center of screen */
   x = getmaxx()/2;
   y = getmaxy()/2;
 
   outtextxy(x-100, 50, "CIRCLE Using Graphics in C");
   /* Draw circle on screen */
   circle(x, y, radius);
 
   getch();
   closegraph();
   return 0;
}

Program Output

Circle

Artificial Intelligence Lecture Notes and Study Material PDF Free Download

artificial-intelligence-lecture-notes

Artificial Intelligence Lecture Notes: Graduates eyeing to get hold of the Artificial Intelligence Lecture Notes and Study Materials can avail the best notes and reference resources for their preparation process from this article.

The chief study material for better and comprehensive preparation is the Artificial Intelligence Lecture Notes as they offer comprehensive, accurate, and credible materials that help you score better grades. Students can refer and read through the Artificial Intelligence Lecture Notes as per the latest syllabus from this article.

Artificial Intelligence Lecture Notes aim to provide aspirants with detailed yet concise information on the subject matter and gives you an advantage as you additionally acquire the latest and updated Syllabus, Important list of Questions, and Reference Books on Artificial Intelligence course programme over regular notes. Students can access the latest Artificial Intelligence Lecture Notes and Study Materials PDF Free Download from this article.

Graduates can better prepare with the right strategy and approaches and achieve better grades.

Introduction to Artificial Intelligence Notes

Artificial Intelligence is a widespread advanced study concerned with the structure of smart machines. These machines are developed to perform tasks with prerequisite human intelligence. Artificial Intelligence is a multidisciplinary Science with multiple approaches. The advancements in Machine learning create a paradigm shift that alters the virtual sector in today’s world, especially in the tech industry.

The major limitation of Artificial Intelligence is that it fails to explain what artificial intelligence is all about; however, authors Norvig and Russell state four approaches that define the field of Artificial Intelligence.

For Example,- Siri is the best Example of Artificial Intelligence. Siri uses machine learning technology to decode and understand human language and answer accordingly. It is the most iconic Example of gadgets, machine learning abilities.

B.Tech/M.Sc Artificial Intelligence Lecture Notes and Study Material PDF Free Download

Graduates pursuing Bachelors in Technology (B.Tech) or Masters in Science (M.Sc) can avail from the Artificial Intelligence Lecture Notes and Study Material updated in this article. The study resources aim to help your preparation with these ultimate tools and help you score better grades.

Students can download the lecture notes and study material to refer to them during the preparation or revision process. The utilisation of the Artificial Intelligence Lecture Notes and Study Materials as a source reference will assist graduates in getting a comprehensive understanding of the concepts and changing your score chart.

Here, are a list of a few important lecture notes that provides a comprehensive preparation of the Artificial Intelligence course programme-

  • Artificial Intelligence Fourth Semester Lecture Notes for MSc. PDF
  • Artificial Intelligence Lecture Notes PDF
  • Artificial Intelligence Handwritten Lecture Notes PDFs
  • Artificial Intelligence Lecture Notes for CSE PDFs
  • Artificial Intelligence Programme Question Paper PDFs
  • Artificial Intelligence Fifth Semester Lecture Notes for B.Tech. PDF
  • Artificial Intelligence PPT Lecture Notes PDF
  • Artificial Intelligence CSC384 – Lectures Slides and Readings
  • Artificial Intelligence Lecture Notes for Bachelor of Technology in Computer Science and Engineering and Information Technology PDFs

Artificial Intelligence Reference Books

Books act as a portal to credible and well-researched information. Students should ensure to refer to the best reference books for the Artificial Intelligence course programme as per the subject experts’ recommendations. Students can refer and read through artificial Intelligence Books and other sources of reference to improve their learning, organise, and structure their preparation.

The list of best reference books for Artificial Intelligence preparation is as follows. However, students should consider a book that meets their knowledge and prepare accordingly.

  1. Book on Artificial Intelligence- from Fundamentals to Intelligent Searches by Qiangfu ZHAO and Tatsuo Higuchi
  2. Artificial Intelligence and Machine Learning book by Anand Hareendran S and Vinod Chandra S S
  3. Book on Artificial Neural Networks By B Yegnanarayana
  4. Artificial Intelligence- A New Synthesis by Nils J Nilsson and Elsevier
  5. Book on Introduction to Artificial Intelligence by Patterson
  6. CENGAGE Learning on Artificial Intelligence by Saroj Kaushik
  7. The Fifth Edition of Artificial Intelligence, Strategies, and Structures for Complex Problem Solving by George F Luger
  8. Book on Artificial Intelligence- A Modern Approach by Stuart Russell and Peter Norvig
  9. Artificial Intelligence and Innovations 2007 Book by Pnevmatikakis
  10. Book on Introduction to Artificial Intelligence by Wolf Gang, Ertel, and Springer
  11. The Fifth Edition of Artificial Intelligence by Rich, Shiv Shankar B Nair, and Kevin Knight
  12. Textbook of Artificial Intelligence by A Vikraman
  13. Book on Artificial Intelligence Engines- A Tutorial Introduction to the Mathematics of Deep Learning by James V Stone
  14. Machine Learning For Absolute Beginners Book by Oliver Theobald
  15. Book on Introduction to Artificial Intelligence by Shinji Araya

Artificial Intelligence Updated Syllabus

An effective way to improve your preparation is holding an initial idea, and an overview of the Artificial Intelligence updated Syllabus. Keeping in mind every student’s requirements and stipulations, we have provided a comprehensive outlook of the Artificial Intelligence syllabus.

Course Curriculum will instruct, manage, and structure students’ preparation and give you a clear overview of what to study and how to study. The unit-wise break up of syllabus gives students a clear idea of each unit so that students can allot time to each topic accordingly.

Students must ensure to cover all the topics and essential concepts before attempting the Artificial Intelligence course exam so that the test or exam paper is reasonably answerable at the time of the exam. Students must ensure to remain aware and updated of the Artificial Intelligence Syllabus as it stops you from squandering unwanted time on redundant topics.

The updated unit-wise breakup of the Artificial Intelligence Syllabus is as follows-

Unit- I- The Fundamental of Artificial Intelligence

Overview of Artificial Intelligence concerning approaches, methods, specific theories, and technologies.

Unit- II- Machine Learning

Principles and Critical Analysis of Machine Learning and their applications. An overview of predictive tools and systems.

Unit- III- Human Language technologies

Principles, Techniques, and Models of Natural language focusing on Statistical Machine Learning approach using modern programming libraries.

Unit- IV- Distributed systems: paradigms and models

Unit- V- Intelligent Systems for Pattern Recognition

Designs of A. I based on Solutions and Applications, Presentation of Image processing and signalling; Focus on Pattern recognition problems and models

Unit-VI- Smart applications

Novel Smart Applications, Implementation of Design, Prototype of Smartwork.

Unit- VII- Computational mathematics for learning and data analysis

Use of common Computational Mathematical tools in fields like Statistics, Data fitting, Artificial Intelligence, Approximation, Information Retrieval, and others.

Unit- VIII- Robotics

Fundamentals of Robotics, Application domain for Intelligence Systems, Computer Science, Schemes, and behaviour control

Unit- IX- Semantic web

Semantic Web Technologies, Linked Data, and Wen Languages

Unit- X- Computational modelling of complex systems

Advanced modelling approaches, Case study dynamics, economy, biochemistry, and epidemiology.

List of Artificial Intelligence Important Questions

Students pursuing Bachelors in Technology (B.Tech) or M.Sc can read through the list of all the essential questions mentioned below for the Artificial Intelligence course programme. The given review questions mentioned below aim to help the graduates to excel in the examination.

  • Write a short note on the Tower of Hanoi.
  • Explain briefly how Artificial Intelligence connects to Human-based Nature.
  • Explain how you would formulate a Constraint Satisfaction Problem.
  • Write a short note on the Turing Test.
  • Elucidate the PEAS description for a Vacuum cleaner and give your opinion about heuristic function.
  • Please write a short note on the problem-solving agents along with its algorithms.
  • Define parallel machines.
  • Write a short note on the capabilities of a computer for a Turing test.
  • Define a ridge.
  • Summarize the factors relating to rationality.
  • Formulate Constraint Satisfaction Problem on a brief note.
  • List the different categories of production systems.
  • Demonstrate the condition if a problem is decomposed.
  • Write a short note on Artificial, Alternate, Natural, and Compound keys.
  • Elucidate on the Hybrid Bayesian network.

FAQs on Artificial Intelligence Lecture Notes

Question 1.
Define Artificial Intelligence with examples.

Answer:
Artificial Intelligence is an advanced subject that deals with the stimulation of human intelligence in machines programmed to function and think like humans and impersonate human actions.

Example- Tesla is a good example of Artificial Intelligence that shows the shift of automobiles towards AI.

Question 2.
State the importance of Artificial Intelligence in today’s scenario?

Answer:
Artificial Intelligence automates the discovery and learning through data. It analyses deeper and abundant data and achieves accuracy. AI adds intelligence and adapts via advanced algorithms learning. Finally, Artificial Intelligence acquires the most out of data.

Question 3.
Name a few important questions for the Artificial Intelligence course programme.

Answer:

  • Elucidate the PEAS description for a Vacuum cleaner and give your opinion about heuristic function.
  • Please write a short note on the problem-solving agents along with its algorithms.
  • Define parallel machines.
  • Write a short note on the capabilities of a computer for a Turing test.
  • Define a ridge.

Question 4.
What are a few reference books that can elevate your exam preparation?

Answer:

  • The Fifth Edition of Artificial Intelligence, Strategies, and Structures for Complex Problem Solving by George F Luger
  • Book on Artificial Intelligence- A Modern Approach by Stuart Russell and Peter Norvig
  • Artificial Intelligence and Innovations 2007 Book by Pnevmatikakis
  • Book on Introduction to Artificial Intelligence by Wolf Gang, Ertel, and Springer
  • The Fifth Edition of Artificial Intelligence by Rich, Shiv Shankar B Nair, and Kevin Knight

Conclusion

The article on Artificial Intelligence Lecture Notes is a credible source of information. It provides accurate and reliable study materials, books and resources that aim to help and enhance a student’s knowledge and comprehension of the subject during preparations and at the time of examination. Students can refer and practice from the provided Artificial Intelligence Lecture Notes,  Books, Important Questions, and Study materials from this article.

B.Tech CSE Fourth Year Notes, Reference Books, Study Materials PDF Download for Free

BTech Computer Science Engineering Fourth Year Notes PDF: Are you guys looking for the best prep resources like final year subjects Notes of Btech CSE? If yes, to help those students we have curated Computer Science Engineering Notes & Study Material in PDF format for all semesters. Here, you can view or download the Bachelor of Technology CSE Final Year 1st & 2nd Sem Notes for free and have a deeper understanding of subject concepts.

For the sake of better preparation, we even listed BTech 4th Year CSE Reference Books, Subjects list which you might need while preparing for the Semester Examinations.

BTech Fourth Year Computer Science Engineering Subject Notes PDF Free Download

Candidates can get Complete Btech 4th Year CSE Notes in Pdf format by referring further. Get to know the JNTUK Bachelor of technology final Year computer science engineering Notes for 2 semesters from here. By accessing the quick links provided on our page, you can explore the Btech CSE fourth year Notes, study materials, Reference Textbooks, and use them during your preparation. Go through the JNTUH & other institutes’ B.Tech CSE Final Year Lecture Notes Pdf and get acquainted with all the subjects and score good marks in the exam.

List of JNTUK Btech 4-1 & 4-2 Semester Subjects

IV Year I Sem:

  • Cryptography and Network Security
  • Software Architecture & Design Patterns
  • Web Technologies(WT)
  • Elective-I
    i. Big Data Analytics
    ii. Information Retrieval Systems
    iii. Mobile Computing
  • Elective-II
    i. Cloud Computing
    ii. Software Project Management
    iii. Scripting Languages

IV Year II Sem:

  • Distributed Systems(DS)
  • Management Science
  • Elective-III
    i. Concurrent and Parallel Programming
    ii. Artificial Neural Networks
    iii. Operations Research

JNTUH Final Year BTech Computer Science Engineering (CSE) Subjects List

4-1:

  • Linux Programming
  • Design Patterns
  • Data Warehousing and Data Mining
  • Cloud Computing
  • ELECTIVE – I
    1. Software Project Management
    2. Image processing and Pattern Recognition
    3. Mobile Computing
    4. Computer Graphics
    5. Operations Research
  • ELECTIVE – II
    1. Machine Learning
    2. Soft Computing
    3. Information Retrieval Systems
    4. Artificial Intelligence
    5. Computer Forensics
    6. Linux Programming Lab
    7. Data Warehousing and Mining Lab

4-2:

  • Management Science
  • ELECTIVE III
    1. Web Services
    2. Semantic Web and Social Networks
    3. Scripting Languages
    4. Multimedia & Rich Internet Applications
    5. Predictive Analytics (Associate Analytics – 3)
    6. Information Security Incident Response & Management ( Security Analyst – 3 )
  • ELECTIVE – IV
    1. Ad hoc and Sensor Networks
    2. Storage Area Networks
    3. Database Security
    4. Embedded Systems
  • Industry Oriented Mini Project
  • Seminar
  • Project Work
  • Comprehensive Viva

List of Other Universities Bachelor of Technology CSE Fourth Year Course Subjects

  • Machine Learning and  Data Mining
  • Machine Learning and  Data Mining Lab
  • Software Project Management
  • Structure and Interpretation of Computer Programs
  • Elective IV
  • Elective V
  • Elective VI
  • Project-Based Elective
  • Project Phase I
  • Project Phase II

BTech CSE IV Year I Sem & II Sem Suggested Books

Btech CSE 4th Year Exam appearing Aspirants can look at this module for collecting all subjects reference books. The compiled list of BTech Computer Science Engineering fourth year subjects recommended books are preferred by subject experts and toppers of the institute. Go with these suggested books at the time of preparation and develop your subject knowledge. You can even use this for planning a proper preparation strategy & score max. marks in the exam.

  • Cloud Computing: A Practical Approach. Anthony T.Velte. Toby J.VeFte, Robert Elsenpeter. Tata McGraw Hill.
  • Enterprise Cloud Computing Gautam Shroif, Cambridge University Press. 2010.
  • Beginning Linux Programming, 4th Edition, N.Matthew, R.Stones, Wrox, Wiley India Edition.
  • Unix for programmers and users, 3rd Edition, Graham Glass, King Ables, Pearson.
  • Applied Software Project Management, Andrew SteIbian 8 Jennifer Greene, O’Reilly. 2006
  • Head First PMP, Jennifer Greene & Andrew Steliman, ORoiHy.2007
  • Digital Image Processing – William k. Prati -John Wiley edition.
  • JAVA Enterprise Design Patterns Vol – III By Mark Grand, Wiley Dream TECH.
  • Kotler Philip and Keller Kevin Lane: Marketing Management, Pearson, 2012.
  • Koontz and Weihrich: Essentials of Management, McGraw Hill, 2012.
  • Embedding system building blocks, Labrosse, via CMP publishers.
  • Embedded Systems, Raj Kamal, TMH.
  • Multimedia Making it work, Tay Vaughan, 7th edition, TMH, 2008.
  • Introduction to multimedia communications and Applications,

FAQs on BTech Computer Science Engineering 4th Year Notes Pdf

1. Where can I find B.Tech CSE 4th Year Notes & Study Material in PDF format?

You can find the B.Tech CSE 4th Year Notes & Study Material Pdf on our page. Access the quick links provided over here and save the Btech fourth year CSE Lecture Notes Pdf offline for further reference while preparation.

2. How to download Pdf formatted JNTUK Btech Computer Science Engineering Notes PDF?

Simply press on the direct links available on this page and download the respective subject Btech CSE final year lecture notes pdf and reference books. You can use them whenever you wish during preparation.

3. What is the best resource to study well & score enough marks in Various Institutes Btech CSE 4-1 & 4-2 Semester Exams?

There are plenty of resources available online for preparation but the best one is Class Notes. It helps students to revise all the subjects easily and score better marks in the exams. We have tried mentioning Btech final year CSE Notes & Study Materials so check out them for reference & prepare efficiently.

Final Words on CSE Final Year Btech Handwritten Notes

We hope the data shared on our page about the BTech CSE Fourth Year Notes Pdf, Reference books have been helpful in clearing all your concerns about the subjects. If you need any assistance, drop a comment via the below box & we’ll get back to you soon. Meanwhile, bookmark our site for more updates on Books, BTech Notes, and other preparation related resources.

Problem Solving and Programming In C Notes and Study Material PDF Free Download

problem-solving-and-programming-in-c-notes

Problem Solving and Programming in C Notes: C is one of the popular programming languages that are simple and flexible. It is a general-purpose programming language that is widely used in different kinds of applications. Operating Systems like Windows and many others are written in C language. Git, Python Interpreter, and Oracle Database are also written in C. This language is often called the base knowledge of programming. If you know this language, it becomes easier for you to learn any other programming language. This is a simple language which can provide faster execution. The demand for C developers is very high in the job market. This programming language can extend itself. It contains various kinds of functions that are part of the library. In this article, you will find complete details about problem-solving and programming of C language Lecture Notes.

Introduction to Problem Solving And Programming In C

Ritchie first developed this language in 1972. It is a structured language that is widely used in the software development field. For every software developer, it is important to know the C language. This language can handle low-level activities and can be compiled easily. This language is primarily used in UNIX. This language is the successor of the B language. C language is used in databases, utilities, text editors, assemblers, operating systems, and language compilers. In C programming course, you will learn this programming language from scratch. You will find all the study materials of this widely used language from this article.

Problem Solving And Programming In C Notes and Study Material PDF Free Download

Anyone interested in making a career in software development should learn C programming. It is because this language is considered as the base language of every other programming language. If you plan to do a course on C programming, you can find the right study material through this article. We have made a list of some important study materials on C programming. You can check out computer programming terminologies once before starting C programming course.

Problem Solving And Programming In C textbook pdf Download
Problem Solving And Programming In C note & Study material Download
Problem Solving And Programming In C notes Download
Introduction to C programming Download

Problem Solving And Programming In C Reference Books

It is a relatively small language, but it is very useful. You need to learn some simple things in C programming. This language was mainly discovered so that programmers can interact with the machines efficiently. To learn this language, you must read the right set of books. We have made a list of some important books on C language.

  • C Programming Absolute Beginner’s Guide.
  • C Programming Language.
  • The C Programming Language 2nd Edition.
  • C Programming: A Modern Approach.
  • Expert C Programming: Deep Secrets.
  • C: The Complete Reference.
  • Head First C: A Brain-Friendly Guide.
  • Computer Fundamentals and Programming in C.
  • Low-Level Programming by Igor Zhirkov
  • C in a Nutshell by Peter Prinz & Tony Crawford

Problem Solving And Programming In C Curriculum

Before starting the course on C programming, you must know the syllabus. It is crucial to understand the syllabus. The syllabus of C programming varies depending on the type of course and institution. However, the basic structure of the C programming’s syllabus remains the same. In this article, you will get to know about the necessary details taught in C programming.

C Programming Language Syllabus

Fundamentals of C Language

About C tutorial

Important points about C

Why Use C

Applications of C

C Language and English Language

Features of C

C, C++ and Java

Overview of C Language

History of C

First Program in C Hello World

Basic Structure of C Programming

Tokens in C

Keywords in C

Identifiers in C

Format Specifiers

Format Specifiers Examples

Data Types in C Language

Introduction to Data Types in C

int Data Type in C

float Data Type in C

double Data Type in C

char Data Type in C

Variable in C Language

Variable Introduction in C

Variable Declaration and Initialization

Variable types and Scope in C

Local Variable in C

static Variable in C

Global variables in C

Storage Class in C

Constant in C Language

Constants in C

Operators and Enums in C Language

Introduction to Operator

Arithmetic Operators in C

Relational Operators in C

Bit-wise Operators in C

Logical Operators in C

Assignment Operators in C

Conditional Operator in C

size of() Operator in C

Operator Precedence

Decision Making of C Language

Decision Making in C Introduction

if Statement

if-else Statement

Nested if Statement

if-else if Ladder

switch case

Loop control in C Language

Loop Introduction in C

while loop in C

do-while Loop In C

for Loop in C

Control Flow in C Programming

break Statement in C

continue Statement in C

goto statement in C

Array in C Language

Single Dimensional Array

Multi-Dimensional Array in C

String in C Language

Introduction to String

Function in C Language

Function in C

Function Calling in C

return type in Function

Call by Value in C

User Define Function

Predefined Functions

String functions in C

All String Functions

strcat() function

strncat() function

strcpy() function

strncpy() function

strlen() function

strcmp() function

strcmpi() function

strchr() function

strrchr() function

strstr() function

strrstr() function

strdup() function

strlwr() function

strupr() function

strrev() function

strset() function

strnset() function

strtok() function

Recursion in c

Introduction to Recursion

Direct and Indirect Recursion

Pointer in C Language

Pointer in C

types of pointer

NULL pointer

Dangling Pointer

Void/Generic Pointers

Wild Pointer

Near, Far and Huge Pointer

Pointer Expressions and Arithmetic

Pointer and Array

Strings as pointers

Pointer to Function

Call by Reference in C

Structure in C Language

Structure in C

Nested Structure in C

The array of Structures in C

Pointer to Structure

Structure to Function in C

typedef in C

typedef vs #define in C

Union in C Language

Union in C

File Input/Output

Introduction to File

File Operation in c

Dynamic Memory Allocation

Introduction to DMA

calloc() and free() function

realloc() and free() function

C Pre-processor

Introduction about Pre-processor

List of Problem Solving And Programming In C Important questions

  • What is the difference between ++i and i++?
  • Give a brief note on the volatile keyword.
  • What are the basic data types related to C?
  • Explain syntax errors.
  • How can you create a decrement and increment statement in C?
  • Explain dangling pointer in C.
  • What is called the prototype function in C?
  • What is a header file? Explain its usage in C programming.
  • Explain pointer on a pointer in C language.
  • How can you save data in a stack data structure type?

FAQs on Problem Solving and Programming in C Notes

Question 1.
What is called the C language?

Answer:
C is one of the popular programming languages that are simple and flexible. It is a general-purpose programming language that is widely used in different kinds of applications.

Question 2.
What kind of software is written in the C language?

Answer:
Operating Systems like Windows and many others are written in C language. Git, Python Interpreter, and Oracle Database are also written in C.

Question 3.
When was C language developed?

Answer:

Ritchie first developed the C language in 1972. It is a structured language that is widely used in the software development field.

Question 4.
Is it tough to learn the C language?

Answer:
It is not that difficult to learn the C language. C language is often called the base language in programming. After learning the C language, it becomes easier to learn other programming languages like C++, Java, C# etc.

Conclusion

The information provided above regarding the syllabus and study materials for C programming will help in your study. If you have any other questions regarding C programming study materials, please let us know in the comment section.

Python NumPy conj() Function

Python NumPy conj() Function

NumPy conj() Function:

The conj() method of the NumPy module returns the element-by-element complex conjugate of the given array.

A complex number’s conjugate is obtained by changing the sign of its imaginary part.

For example, the conjugate of a complex number of 1+3j is 1-3j.

Syntax:

numpy.conj(a, out=None)

Parameters

a: This is required. It is an array given as input.

out: This is optional. It is the location where the result will be stored. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.

Return Value: 

The element-by-element complex conjugate of the given array is returned by the conj() method of the NumPy module

NumPy conj() Function in Python

Example1: (For 1-Dimensional Array)

Approach:

  • Import numpy module using the import keyword
  • Pass some random complex numbers list(1-Dimensional) as an argument to the
    array() function to create an array.
  • Store it in a variable.
  • Print the above-given array.
  • Pass the above-given array as an argument to the conj() function of the numpy module to get the conjugate of all the complex elements of the given array.
  • Store it in another variable.
  • Print the conjugate of all the elements of the given complex array.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(1-Dimensional) as an argument to the 
# array() function to create an array. 
# Store it in a variable.
gvn_arry = np.array([1+3j, 4+3j, 2+2j,-1-5j])                     
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the conj() function of the 
# numpy module to get the conjugate of all the complex elements of
# the given array
# Store it in another variable.
rslt = np.conj(gvn_arry)
# Print the conjugate of all the elements of the given complex array 
print("The conjugate of all the elements of the given complex array:")
print(rslt)

Output:

The above given array is:
[ 1.+3.j 4.+3.j 2.+2.j -1.-5.j]

The conjugate of all the elements of the given complex array:
[ 1.-3.j 4.-3.j 2.-2.j -1.+5.j]

Example2: (For n-Dimensional Array, where n is an integer)

Approach:

  • Import numpy module using the import keyword
  • Pass some random complex numbers list(n-Dimensional) as an argument to the
    array() function to create an array.
  • Store it in a variable.
  • Print the above-given array.
  • Pass the above-given array as an argument to the conj() function of the numpy module to get the conjugate of all the complex elements of the given array.
  • Store it in another variable.
  • Print the conjugate of all the elements of the given complex array.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(n-Dimensional) as an argument to the 
# array() function to create an array. 
# Store it in a variable.
gvn_arry = np.array([[1-3j, 4+3j],
                     [-2-4j, 5+6j]])           
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the conj() function of the 
# numpy module to get the conjugate of all the complex elements of
# the given array
# Store it in another variable.
rslt = np.conj(gvn_arry)
# Print the conjugate of all the elements of the given complex array 
print("The conjugate of all the elements of the given complex array:")
print(rslt)

Output:

The above given array is:
[[ 1.-3.j 4.+3.j]
 [-2.-4.j 5.+6.j]]

The conjugate of all the elements of the given complex array:
[[ 1.+3.j 4.-3.j]
 [-2.+4.j 5.-6.j]]

Python Program to Set nth Bit of a Number

Program to Set nth Bit of a Number

In the previous article, we have discussed Python Program to Get nth Bit of a Number

Given a number and the bit position, the task is to set the nth bit of the given Number.

For example:

Let the number = 5

Bit position=1

To set the 1st-bit position(0 indexing):

Its binary form = 101

When we set the 0 at the 1st index becomes 1 that is 111 which is equal to the number 7.

Bitwise or (|) operator:

If one of two bits is 1, sets each bit to 1.

Examples:

Example1:

Input:

Given Number = 5 
Bit position(in range 0-31)= 1

Output:

The given number { 5 } after set the { 1 } bit position =  7

Example2:

Input:

Given Number = 8
Bit position(in range 0-31)= 2

Output:

The given number { 8 } after set the { 2 } bit position = 12

Program to Set nth Bit of a Number in Python

Below are the ways to set the nth bit of the given Number in Python:

Method #1: Using Bitwise |(or) Operator (Static Input)

Approach:

  • Give the number as static input and store it in a variable.
  • Give the bit position as static input and store it in another variable.
  • Apply the left shift operator to 1 and the above-given bit position and store it in another variable.
  • Apply bitwise | operation for the given number and the above result and store it in another variable say set_numb
  • Print the given number after set the nth bit of the given Number.
  • The Exit of the Program.

Below is the implementation:

# Give the number as static input and store it in a variable.
gvn_numb = 5
# Give the bit position as static input and store it in another variable.
bitpositin = 1
# Apply the left shift operator to 1 and the above-given bit position and
# store it in another variable.
numbr_bit = (1 << bitpositin)
# Apply bitwise | operation for the given number and the above result and
# store it in another variable say set_numb.
set_numb = gvn_numb | numbr_bit
# Print the given number after set the nth bit of the given Number.
print("The given number {", gvn_numb,
      "} after set the {", bitpositin, "} bit position = ", set_numb)

Output:

The given number { 5 } after set the { 1 } bit position =  7

Method #2: Using Bitwise |(or) Operator (User Input)

Approach:

  • Give the number as user input using the int(input()) function and store it in a variable.
  • Give the bit position as user input using the int(input()) function and store it in another variable.
  • Apply the left shift operator to 1 and the above-given bit position and store it in another variable.
  • Apply bitwise | operation for the given number and the above result and store it in another variable say set_numb
  • Print the given number after set the nth bit of the given Number.
  • The Exit of the Program.

Below is the implementation:

# Give the number as user input using the int(input()) function and 
# store it in a variable.
gvn_numb = int(input("Enter some random number = "))
# Give the bit position as user input using the int(input()) function and 
# store it in another variable.
bitpositin = int(input("Enter some random number = "))
# Apply the left shift operator to 1 and the above-given bit position and
# store it in another variable.
numbr_bit = (1 << bitpositin)
# Apply bitwise | operation for the given number and the above result and
# store it in another variable say set_numb.
set_numb = gvn_numb | numbr_bit
# Print the given number after set the nth bit of the given Number.
print("The given number {", gvn_numb,
      "} after set the {", bitpositin, "} bit position = ", set_numb)

Output:

Enter some random number = 8
Enter some random number = 2
The given number { 8 } after set the { 2 } bit position = 12

Practice Python Program Examples to master coding skills and learn the fundamental concepts in the dynamic programming language Python.

Computer Science Questions and Answers

Computer Science Quiz Questions and Answers PDF Download

Discrete and Engineering Mathematics

Theory of Computation

  • Finite Automata: Regular Languages Questions and Answers
  • Push Down Automata: CFL & DCFL Questions and Answers
  • Turing Machine: RE, REC and Undecidability Questions and Answers

Digital Logic

  • Logic Functions and Minimization Questions and Answers
  • Combinational Circuits Questions and Answers
  • Sequential Circuits Questions and Answers
  • Number Systems Questions and Answers

Computer Organization & Architecture

  • CPU Architecture and Addressing Modes
  • Control Unit Design
  • Instruction Pipelining
  • Memory Organization
  • IO Organization

Programming and Data Structures

  • Programming Questions and Answers
  • Arrays Questions and Answers
  • Stacks and Queues Questions and Answers
  • Linked List Questions and Answers
  • Trees Questions and Answers
  • Graphs Questions and Answers
  • Hashing Questions and Answers

Algorithms

  • Algorithm Analysis and Asymptotic Notations Questions and Answers
  • Divide and Conquer Questions and Answers
  • Greedy Method Questions and Answers
  • Dynamic Programming Questions and Answers
  • P and NP Concepts Questions and Answers
  • Algorithms Questions and Answers

Compiler Design

  • Lexical Analysis Questions and Answers
  • Parsing Techniques Questions and Answers
  • Syntax Directed Translation Questions and Answers
  • Code Generation and Optimization Questions and Answers

Operating System

  • Operating System, Process, Threads & CPU Scheduling Questions and Answers
  • IPC, Synchronization and Concurrency Questions and Answers
  • Deadlock Questions and Answers
  • Memory Management and Virtual Memory Questions and Answers
  • File System and Device Management Questions and Answers
  • Operating System Miscellaneous Questions and Answers

Databases

  • ER-Model Questions and Answers
  • Database Design: Functional Dependencies and Normalization Questions and Answers
  • Structured Query Language SQL Questions and Answers
  • Relational Model: Relational Algebra and Tuple Calculus
  • Transactions and Concurrency Control
  • File Structures

Computer Networks

  • ISO/OSI Stack and SWP Questions and Answers
  • LAN Questions and Answers
  • TCP, UDP, and IP Questions and Answers
  • Routing and Application Layer Questions and Answers

General Aptitude

  • General Aptitude Questions and Answers

C Program for Bouncing Ball Animation Using C Graphics

Write a program in C for bouncing ball animation using graphics.h header file
In this program, we will draw a red color ball move it vertically up and down like a bouncing ball. We will use below mentioned functions in this program.

Function Description
initgraph It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode.
getmaxx It returns the maximum X coordinate in current graphics mode and driver.
setcolor It changes the current drawing colour. Default colour is white. Each color is assigned a number, like BLACK is 0 and RED is 4. Here we are using colour constants defined inside graphics.h header file.
setfillstyle It sets the current fill pattern and fill color.
circle It draws a circle with radius r and centre at (x, y).
floodfill It is used to fill a closed area with current fill pattern and fill color. It takes any point inside closed area and color of the boundary as input.
cleardevice It clears the screen, and sets current position to (0, 0).
kbhit It is used to determine whether a key is pressed or not. It returns a non-zero value if a key is pressed otherwise zero.
delay It is used to suspend execution of a program for a M milliseconds.
closegraph It unloads the graphics drivers and sets the screen back to text mode.

C program for bouncing ball graphics animation

In this program, we first draw a red color ball on screen having center at (x, y) and then erases it using cleardevice function. We again draw this ball at center (x, y + 5), or (x, y – 5) depending upon whether ball is moving down or up. This will look like a bouncing ball. We will repeat above steps until user press any key on keyboard.

C Program for Bouncing Ball Animation Using C Graphics

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
 
int main() {
 int gd = DETECT, gm;
 int i, x, y, flag=0;
 initgraph(&gd, &gm, "C:\\TC\\BGI");
 
 /* get mid positions in x and y-axis */
 x = getmaxx()/2;
 y = 30;
 
 
 while (!kbhit()) {
  if(y >= getmaxy()-30 || y <= 30)
     flag = !flag;
     /* draws the gray board */
     setcolor(RED);
     setfillstyle(SOLID_FILL, RED);
     circle(x, y, 30);
     floodfill(x, y, RED);
 
 /* delay for 50 milli seconds */
 delay(50);
 
 /* clears screen */
 cleardevice();
 if(flag){
     y = y + 5;
 } else {
     y = y - 5;
 }
    }
 
    getch();
    closegraph();
    return 0;
}

Program Output
Here is the screenshot of bouncing ball.

BOUNCING_BALL

Prototype Design Pattern

Prototype Design Pattern

The Prototype Design Pattern is used for cloning an existing object, if the cost of creating a new object of a class is complicated and resource expensive.

Here, we do not have to repeat the complex object building process to get new object of a class. This design pattern comes under creational design pattern as it provides one of the best ways to create clone of complex objects.

Advantages of Prototype Pattern

  • It hides the complexities of making new instance of a class from client.
  • Client specifies the kind of object it requires using a prototypical instance. Client is unaware of the type of object it will get.
  • It improves the performance of the system. If the cost of creating a new instance is more because of resource intensive operations(like running a database query), it is better to clone an existing prototype object.
  • One instance of a class is used to produce all future instances.

When we should use Prototype pattern

  • When the logic of creating a new object is complex and it requires resource extensive operations to be performed.
  • When we want to hide the logic of object creation and its representation from client.
  • When the classes to instantiate are specified at run-time.
  • When objects of a class can have only few different state(lets say N). It is more convenient to first create N prototype object of different states and clone them later when we need objects of different states.

Implementation of Prototype Design Pattern

We will create an abstract class Bird and it’s concrete implementation Parrot.java, Sparrow.java and Eagle.java. Each concrete implementation of Bird class will override cloneObject method.

Prototype_Pattern

Prototype Design Pattern

Bird.java
public abstract class Bird implements Cloneable  {
    protected String name;
  
    public String getName() {
        return name;
    }
     
    public void setName(String name) {
        this.name = name;
    }
  
    public abstract Bird cloneObject() throws CloneNotSupportedException;
}

Prototype Design Pattern 1

Parrot.java
public class Parrot extends Bird {
  
    public Parrot() {
        name = PrototypeFactory.PARROT;
    }
  
    @Override
    public Bird cloneObject() throws CloneNotSupportedException {
        System.out.println("Cloning a Parrot object");
        return (Bird) super.clone();
    }
}
Eagle.java
public class Eagle extends Bird {
  
    public Eagle() {
        name = PrototypeFactory.EAGLE;
    }
  
    @Override
    public Bird cloneObject() throws CloneNotSupportedException {
        System.out.println("Cloning an Eagle object");
        return (Bird) super.clone();
    }
}
Sparrow.java
public class Sparrow extends Bird {
  
    public Sparrow() {
        name = PrototypeFactory.SPARROW;
    }
  
    @Override
    public Bird cloneObject() throws CloneNotSupportedException {
        System.out.println("Cloning a Sparrow object");
        return (Bird) super.clone();
    }
}

PrototypeFactory class will create prototype instances of Parrot, Sparrow and Eagle stores then in a HashMap. The getBirdInstance method first get the prototype instance of requested bird object from HashMap and the returns a copy of it.

Prototype Design Pattern 2

import java.util.Map;
import java.util.HashMap;
 
public class PrototypeFactory {
    public static final String PARROT = "Parrot";
    public static final String SPARROW = "Sparrow";
    public static final String EAGLE = "Eagle";
 
    private Map<String, Bird> prototypeList = new HashMap<String, Bird>();
     
    public void initialize() {   
     prototypeList.put(PrototypeFactory.PARROT, new Parrot());
     prototypeList.put(PrototypeFactory.SPARROW, new Sparrow());
     prototypeList.put(PrototypeFactory.EAGLE, new Eagle());
    }
  
    public Bird getBirdInstance(String name) throws CloneNotSupportedException {
        return (Bird)prototypeList.get(name).cloneObject();
    }
}

PrototypePatternExample class uses PrototypeFactory object to create object of Parrot, Sparrow and Eagle classes.

public class PrototypePatternExample {
    public static void main(String[] args) {
        PrototypeFactory factory = new PrototypeFactory();
        factory.initialize();
        try {
            factory.getBirdInstance(PrototypeFactory.PARROT);
            factory.getBirdInstance(PrototypeFactory.SPARROW);
            factory.getBirdInstance(PrototypeFactory.EAGLE);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
}

Output

Cloning a Parrot object
Cloning a Sparrow object
Cloning an Eagle object

Adapter Design Pattern

The Adapter Pattern Convert the interface of a class into another interface clients expect. It enables a client with incompatible interface to interact with existing class using an intermediate Adapter class. An Adapter class acts like a middle man through which two classes having incompatible interfaces can interact with each other. It comes under structural design pattern as it facilitates communication between two interfaces.

Advantages of Adapter Pattern

  • Two classes having incompatible interfaces can interact with each other using an Adapter class.
  • It promotes reusability of existing system. A class can be accessed by multiple systems using different interfaces and Adapters.

When we should use Adapter pattern

  • When client wants to interact with existing system using incompatible interface.
  • When a new system wants to interact with legacy(old) system using new interface which is not compatible with interface of legacy system.
  • When you want to use a 3rd party framework or library whose interface is incompatible with your system.

Components of Adapter Pattern

  • Target Interface : This is the interface expected by the client.
  • Adapter : This is a wrapper over Adaptee class which implements the Target Interface. It receives calls from the client and translates that request to one/multiple adaptee calls using Adaptee interface.
  • Adaptee Interface : This is the existing interface which is wrapped by Adapter. Client wants to interact with Adaptee but cannot interact directly because Adaptee Interface is incompatible with Target Interface.
  • Client : Client will interact with Adapter using Target Interface.
    1. Client calls Adapter using using Target Interface.
    2. Adapter class translates this request and delegates it to adaptee using one/multiple method calls using Adaptee Interface.
    3. Adaptee returns response to Adapter class as defined in Adaptee Interface and then Adapter transforms this response before returning it to Client as defined in Target Interface.

Adapter_Pattern
We will declare two incompatible interfaces Square and Rectangle.
Adapter Design Pattern

Square.java
public interface Square {
    public void setSide(int sideLength);
    public void printAreaOfSquare();
}
Rectangle.java
public interface Rectangle {
    public void setLength(int length);
    public void setWidth(int width);
    public void printAreaOfRectangle();
}

Create Chessboard.java and Tenniscourt.java implementing Square and Rectangle interfaces respectively.
Adapter Design Pattern 1

Chessboard.java
public class Chessboard implements Square {
    int sideLength;
  
    @Override
    public void setSide(int sideLength){
        this.sideLength = sideLength;
    }
  
    @Override
    public void printAreaOfSquare(){
        System.out.println("Area of Chessbpard is " + sideLength*sideLength);
    }
}

Adapter Design Pattern 2

Tenniscourt.java
public class Tenniscourt implements Rectangle {
    int length, width;
  
    @Override
    public void setLength(int length){
        this.length = length;
    }
  
    @Override
    public void setWidth(int width){
        this.width = width;
    }
  
    @Override
    public void printAreaOfRectangle(){
        System.out.println("Area of Tennis Court is " + length*width);
    }
}

Now, we will define RectangleAdapter.java which is a wrapper over Rectangle interface. It implements Square interface over Rectangle Interface.
Adapter Design Pattern 3

RectangleAdapter.java
public class RectangleAdapter implements Square {
    Rectangle rect;
  
    public RectangleAdapter(Rectangle rect) {
        this.rect = rect;
    }
  
    // Setting length and width to same value to make it a square
    @Override
    public void setSide(int sideLength){
        rect.setLength(sideLength);
        rect.setWidth(sideLength);
    }
  
    @Override
    public void printAreaOfSquare(){
        rect.printAreaOfRectangle();
    }
}

Create AdapterPatternExample.java class to show the use of RectangleAdapter to call an Rectangle object using Square interface.
Adapter Design Pattern 4

AdapterPatternExample.java
public class AdapterPatternExample {
    public static void main(String args[]){
        Square square = new Chessboard();
        Rectangle rectangle = new Tenniscourt();
        Square adapter = new RectangleAdapter(rectangle);
  
        // Calculate Area of Square using Square Interface 
        square.setSide(5);
        square.printAreaOfSquare();
   
        // Calculate Area of Rectangle using Rectangle Interface
        rectangle.setLength(5);
        rectangle.setWidth(4);
        rectangle.printAreaOfRectangle();
   
        // Now we will call Rectangle object using Square interface 
        adapter.setSide(5);
        adapter.printAreaOfSquare(); 
    }
}

Output

Area of Chessbpard is 25
Area of Tennis Court is 20
Area of Tennis Court is 20

Important Points About Adapter Pattern

  • Adapter class changes the interface of an existing object.
  • Adapter class is a good example of object composition. Adapter class “has a” instance of the adaptee class.
  • We can use an Adapter with any class Implementing Adaptee Interface.
  • Adapter wraps an object to change it’s interface whereas a decorator wraps an object to add extra functionalities.