<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1961538785934969307</id><updated>2026-10-19T04:12:50.331+05:30</updated><category term="for-loop"/><category term="CPP"/><category term="C-Programming"/><category term="Python"/><category term="Beginners"/><category term="While-loop"/><category term="if-else"/><category term="do-while-loop"/><category term="Menu-Driven-Programs"/><category term="Pattern-Programs"/><category term="Switch-Case"/><category term="Matrix-Program"/><category term="Array"/><category term="Linked-Lists"/><category term="Vipul-Khokhar"/><category term="Data-Structures"/><category term="Functions"/><category term="Hackerrank-Solution"/><category term="Recursion"/><category term="Strings"/><category term="Binary-Tree-Traversal"/><category term="DSA"/><category term="Giveaway"/><category term="PYTHON-FRAMEWORKS"/><category term="Segment-Tree"/><category term="striver-sde-sheet"/><title type='text'>Coding with Sid</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>62</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-4143722126282238124</id><published>2026-01-18T15:19:00.005+05:30</published><updated>2026-01-18T15:30:46.816+05:30</updated><title type='text'>How I Came into Software Development?</title><content type='html'>&lt;p&gt;
  On &lt;strong&gt;16th January 2026&lt;/strong&gt;, I completed 
  &lt;strong&gt;three years in the software development&lt;/strong&gt;. 
  I started my journey as a 
  &lt;strong&gt;Frontend Developer Intern on 16th January 2023&lt;/strong&gt;, 
  and today I am working as a 
  &lt;strong&gt;Software Engineer II&lt;/strong&gt;.
&lt;/p&gt;

&lt;p&gt;
  It all began back in &lt;strong&gt;2017&lt;/strong&gt;, when I opted for 
  &lt;strong&gt;PCM with Computer Science&lt;/strong&gt; in Class XI because there were no vacant seats in 
  &lt;strong&gt;PCMB&lt;/strong&gt;. After a week, our class teacher who also taught Computer Science announced that students could still change sections if anyone wanted to take 
  &lt;strong&gt;Biology instead of Computer Science&lt;/strong&gt;.
&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
  &lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhfW_yvB4dRoGkRnA94n6_-6fFGaKuZMnvimBPpeWbAgVtkzKLpYRYMIw1nu5vmMslW1edQEtb4lYPImcWjeXXsOfMA9beB5IInpZ7BTt6uBjWfmHNNKDQ034zoSjjJ__b5iLoqABd_HHW-c_4MZ10l92_X-b1BDlsfEHqZCVDRgVd4pmlJPAxh1EGKP8o&quot;
     &gt;
    &lt;img
      alt=&quot;How I Came into Software Development?&quot;
      src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhfW_yvB4dRoGkRnA94n6_-6fFGaKuZMnvimBPpeWbAgVtkzKLpYRYMIw1nu5vmMslW1edQEtb4lYPImcWjeXXsOfMA9beB5IInpZ7BTt6uBjWfmHNNKDQ034zoSjjJ__b5iLoqABd_HHW-c_4MZ10l92_X-b1BDlsfEHqZCVDRgVd4pmlJPAxh1EGKP8o=s16000&quot;
      title=&quot;How I Came into Software Development?&quot;
    /&gt;
  &lt;/a&gt;
&lt;/div&gt;

&lt;p&gt;
  During lunch break, I went to the computer lab (the best classroom in the school, and the only one with air conditioners) and told my teacher that I wanted to switch to Biology. Why I wanted Biology is a different story, which I’ll cover another time.
&lt;/p&gt;

&lt;p&gt;
  She looked at me and said, 
  &lt;em&gt;“Dar lag gaya kya CS se?”&lt;/em&gt; (Did Computer Science scare you?)&lt;br /&gt;
  I didn’t reply. I just left the room.
&lt;/p&gt;

&lt;p&gt;
  After lunch, she came to our classroom to take attendance. Once she was done, she asked me in front of everyone,&lt;br /&gt;
  “Siddharth, do you want to take Biology instead of Computer Science?”
&lt;/p&gt;

&lt;p&gt;
  I replied, &lt;strong&gt;“No.”&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
  She asked, “Why?”
&lt;/p&gt;

&lt;p&gt;
  At that moment, one of the backbenchers shouted, 
  &lt;em&gt;“Maine samjha diya hai ise!”&lt;/em&gt;&lt;br /&gt;
  He used to sit behind me during exams, and if I changed sections, he wouldn’t be able to copy my answers.
&lt;/p&gt;

&lt;p&gt;
  I smiled and said, &lt;strong&gt;“Haan, isne samjha diya hai.”&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
  Now comes the real challenge.
&lt;/p&gt;

&lt;p&gt;
  I had to study &lt;strong&gt;Computer Science without having a computer at home&lt;/strong&gt;. 
  I read &lt;strong&gt;each and every line&lt;/strong&gt; of the 
  &lt;strong&gt;Sumita Arora Computer Science book&lt;/strong&gt; and executed every line of code 
  &lt;strong&gt;in my mind&lt;/strong&gt;. This habit made me strong in 
  &lt;strong&gt;output-based questions&lt;/strong&gt; and helped me write accurate code on paper.
&lt;/p&gt;

&lt;p&gt;
  One day, after checking my answer sheet, my Computer Science teacher mentioned during the assembly that my answers were really good. While writing code on the blackboard, she pointed at me and said,&lt;br /&gt;
  “Siddharth, we initialize a character using &lt;strong&gt;‘char’&lt;/strong&gt;.”
&lt;/p&gt;

&lt;p&gt;
  In my answers, I had written &lt;strong&gt;“ch”&lt;/strong&gt; instead of &lt;strong&gt;“char”&lt;/strong&gt; everywhere. 
  I think she understood that I wasn’t actually running code on a computer. 
  I was running it in my head.
&lt;/p&gt;

&lt;p&gt;
  She was one of the &lt;strong&gt;best teachers of my life&lt;/strong&gt;. 
  &lt;span&gt;Without reading anything about linear search in arrays or matrices, I independently wrote its code in Class 11.&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
  I derived the logic on my own by understanding how data is stored and accessed, which strengthened my problem-solving and algorithmic thinking at an early stage.
&lt;/p&gt;

&lt;p&gt;
  Because of her teaching, I became good in 
  &lt;strong&gt;functions, arrays, and strings&lt;/strong&gt;. 
  I scored &lt;strong&gt;95/100 in my board exams&lt;/strong&gt;.
&lt;/p&gt;

&lt;p&gt;
  And today, here I completed &lt;strong&gt;three years into my coding journey&lt;/strong&gt; – 
  building new features, fixing bugs, working on complex financial reports for 
  &lt;strong&gt;US schools&lt;/strong&gt;, implementing logic more complex than I ever imagined, and constantly optimizing solutions.
&lt;/p&gt;

&lt;p&gt;
  From running code in my head to running systems in production, 
  &lt;strong&gt;this journey has been unreal.&lt;/strong&gt;
&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/4143722126282238124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2026/01/how-i-came-into-software-development.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4143722126282238124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4143722126282238124'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2026/01/how-i-came-into-software-development.html' title='How I Came into Software Development?'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhfW_yvB4dRoGkRnA94n6_-6fFGaKuZMnvimBPpeWbAgVtkzKLpYRYMIw1nu5vmMslW1edQEtb4lYPImcWjeXXsOfMA9beB5IInpZ7BTt6uBjWfmHNNKDQ034zoSjjJ__b5iLoqABd_HHW-c_4MZ10l92_X-b1BDlsfEHqZCVDRgVd4pmlJPAxh1EGKP8o=s72-c" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6632346623768162749</id><published>2023-11-12T21:30:00.002+05:30</published><updated>2023-11-12T22:42:36.162+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Program to Generate a Random Number in 3 easy steps</title><content type='html'>&lt;p&gt;In this program, we are going to make a python program which will generate random number.&lt;/p&gt;
&lt;h2&gt;Python program to generate a random number between 1 and 100&lt;/h2&gt;
&lt;p&gt;We will import random module in our program. We will use a predefined function called randint.&lt;/p&gt;
&lt;pre&gt;import random
randomNumber = random.randint(1, 100)
print(randomNumber)&lt;/pre&gt;

&lt;p&gt;Let suppose you want to find a random between 2 numbers x and y(both inlcusive), then you will use random.randint(x, y);&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&quot;&quot; class=&quot;BLOG_video_class&quot; height=&quot;266&quot; src=&quot;https://www.youtube.com/embed/KooBHi0V_f0&quot; width=&quot;320&quot; youtube-src-id=&quot;KooBHi0V_f0&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2&gt;Random number in dice program python&lt;/h2&gt;
&lt;pre&gt;import random
red = random.randint(1, 6)
print(res)&lt;/pre&gt;

  &lt;p&gt; If you want to generate random number without using random module, you can read on &lt;a href=&quot;https://stackoverflow.com/questions/28705965/python-random-function-without-using-random-module&quot;&gt;stackoverflow&lt;/a&gt; about it.&lt;/p&gt;

&lt;h2&gt;Steps to write a program to generate random number in python in 3 easy steps&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Importing the random Module. &lt;br /&gt; &lt;pre&gt;import random
&lt;/pre&gt;&lt;/li&gt;
  &lt;li&gt;Now we will select the interval. Random number will be fall in the provided interval. &lt;pre&gt;random.randint(1, 10)&lt;/pre&gt;&lt;/li&gt;
  &lt;li&gt;Now you can print the number returned in step 2.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This is all about Python Program to Generate a Random Number. If you have any doubts regarding this program, let me know in the comment section.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6632346623768162749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2023/11/python-program-to-generate-random-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6632346623768162749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6632346623768162749'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2023/11/python-program-to-generate-random-number.html' title='Python Program to Generate a Random Number in 3 easy steps'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/KooBHi0V_f0/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-710741840480134981</id><published>2022-11-23T10:52:00.010+05:30</published><updated>2026-02-19T23:05:05.938+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Menu-Driven-Programs"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Menu driven Program in Python using while loop</title><content type='html'>
&lt;p&gt;
A &lt;strong&gt;Menu Driven Program in Python&lt;/strong&gt; is a program that displays multiple options to the user. 
Based on the user&#39;s choice, the program performs a specific task. 
This program is very important for &lt;strong&gt;Class 12 CBSE board practical exams&lt;/strong&gt;.
&lt;/p&gt;


&lt;h2&gt;What is a Menu Driven Program?&lt;/h2&gt;

&lt;p&gt;
A &lt;strong&gt;menu-driven program&lt;/strong&gt; allows users to select from different options displayed on the screen. 
The program then executes the operation based on the selected option using &lt;strong&gt;if-elif-else statements&lt;/strong&gt; and &lt;strong&gt;loops&lt;/strong&gt;.
&lt;/p&gt;


&lt;h2&gt;Menu Driven Program in Python Using While Loop&lt;/h2&gt;

&lt;p&gt;In this example, we calculate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Area of Circle&lt;/li&gt;
&lt;li&gt;Area of Rectangle&lt;/li&gt;
&lt;li&gt;Area of Square&lt;/li&gt;
&lt;li&gt;Exit Program&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Python Code&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;
while True:
    print(&quot;Menu Driven Program&quot;)
    print(&quot;1. Area of Circle&quot;)
    print(&quot;2. Area of Rectangle&quot;)
    print(&quot;3. Area of Square&quot;)
    print(&quot;4. Exit&quot;)

    choice = int(input(&quot;Enter your choice: &quot;))

    if choice == 1:
        radius = int(input(&quot;Enter radius of Circle: &quot;))
        print(&quot;Area of Circle:&quot;, 3.14 * radius * radius)

    elif choice == 2:
        length = int(input(&quot;Enter length of Rectangle: &quot;))
        breadth = int(input(&quot;Enter breadth of Rectangle: &quot;))
        print(&quot;Area of Rectangle:&quot;, length * breadth)

    elif choice == 3:
        side = int(input(&quot;Enter side of Square: &quot;))
        print(&quot;Area of Square:&quot;, side * side)

    elif choice == 4:
        print(&quot;Exiting Program...&quot;)
        break

    else:
        print(&quot;Wrong Choice&quot;)

    repeat = input(&quot;Do you want to continue? (y/n): &quot;)
    if repeat.lower() == &#39;n&#39;:
        break
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;Sample Output&lt;/h2&gt;

&lt;pre&gt;Menu Driven Program
1. Area of Circle
2. Area of Rectangle
3. Area of Square
4. Exit
Enter your choice: 3
Enter side of Square: 5
Area of Square: 25
&lt;/pre&gt;

&lt;div style=&quot;margin: 20px 0px; text-align: center;&quot;&gt;
  &lt;img alt=&quot;Menu Driven Program in Python using while loop example output&quot; loading=&quot;lazy&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_CSEghdckWM5oiMUqMl8ODE3SDkHisq47AgdnNqyBl77Brk7YIKuC5f5rMXWSfFxPRRiMCtWXrDRxLf_2V8FbJLmveV0FYvrBf0UbN6jZR-AcZslIarEBxXvqlZZTFsOYRAAQsXsBn9Q/w533-h640/menu+driven+program+in+python+using+while+loop.webp&quot; style=&quot;border-radius: 8px; height: auto; max-width: 100%;&quot; title=&quot;Menu Driven Program in Python using while loop&quot; width=&quot;533&quot; /&gt;
&lt;/div&gt;


&lt;h2&gt;Quick Algorithm&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Display the menu options.&lt;/li&gt;
&lt;li&gt;Take input from the user.&lt;/li&gt;
&lt;li&gt;Check the choice using if-elif-else.&lt;/li&gt;
&lt;li&gt;Perform the selected operation.&lt;/li&gt;
&lt;li&gt;Use break statement to exit.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;Menu Driven Program in Python Using Functions&lt;/h2&gt;

&lt;p&gt;Now let’s implement the same program using Python functions.&lt;/p&gt;

&lt;h3&gt;Python Code Using Functions&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;
def circle(radius):
    print(&quot;Area of Circle:&quot;, 3.14 * radius * radius)

def rectangle(length, breadth):
    print(&quot;Area of Rectangle:&quot;, length * breadth)

def square(side):
    print(&quot;Area of Square:&quot;, side * side)

while True:
    print(&quot;Menu Driven Program&quot;)
    print(&quot;1. Area of Circle&quot;)
    print(&quot;2. Area of Rectangle&quot;)
    print(&quot;3. Area of Square&quot;)
    print(&quot;4. Exit&quot;)

    choice = int(input(&quot;Enter your choice: &quot;))

    if choice == 1:
        radius = int(input(&quot;Enter radius of Circle: &quot;))
        circle(radius)

    elif choice == 2:
        length = int(input(&quot;Enter length of Rectangle: &quot;))
        breadth = int(input(&quot;Enter breadth of Rectangle: &quot;))
        rectangle(length, breadth)

    elif choice == 3:
        side = int(input(&quot;Enter side of Square: &quot;))
        square(side)

    elif choice == 4:
        print(&quot;Exiting Program...&quot;)
        break

    else:
        print(&quot;Wrong Choice&quot;)
&lt;/code&gt;&lt;/pre&gt;


&lt;h2&gt;Why This Program is Important for CBSE Class 12?&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Commonly asked in practical exams&lt;/li&gt;
&lt;li&gt;Tests understanding of loops&lt;/li&gt;
&lt;li&gt;Checks conditional statements knowledge&lt;/li&gt;
&lt;li&gt;Evaluates function usage&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Frequently Asked Questions (FAQ)&lt;/h2&gt;

&lt;h3&gt;What is a menu-driven program in Python?&lt;/h3&gt;
&lt;p&gt;
A menu-driven program displays multiple options to users and performs operations based on their selection using loops and conditional statements.
&lt;/p&gt;

&lt;h3&gt;How do you exit a menu-driven program?&lt;/h3&gt;
&lt;p&gt;
We use the &lt;code&gt;break&lt;/code&gt; statement inside the loop when the user selects the exit option.
&lt;/p&gt;

&lt;h3&gt;Can we use functions in a menu-driven program?&lt;/h3&gt;
&lt;p&gt;
Yes, functions make the program more modular, readable, and structured.
&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;  
This menu-driven program in Python using while loop and functions is essential for beginners and Class 12 students. 
Practice this program thoroughly for board exams and practicals.
&lt;/p&gt;

</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/710741840480134981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html#comment-form' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/710741840480134981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/710741840480134981'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html' title='Menu driven Program in Python using while loop'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_CSEghdckWM5oiMUqMl8ODE3SDkHisq47AgdnNqyBl77Brk7YIKuC5f5rMXWSfFxPRRiMCtWXrDRxLf_2V8FbJLmveV0FYvrBf0UbN6jZR-AcZslIarEBxXvqlZZTFsOYRAAQsXsBn9Q/s72-w533-h640-c/menu+driven+program+in+python+using+while+loop.webp" height="72" width="72"/><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-396580727790825499</id><published>2022-11-22T08:23:00.001+05:30</published><updated>2022-11-22T08:25:36.078+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Palindrome Program in Python using for loop [New]</title><content type='html'>
&lt;details class=&quot;sp toc&quot; open=&quot;&quot;&gt;
   &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2&gt;Palindrome program in python using for loop&lt;/h2&gt;

&lt;pre class=&quot;prettyprint language-py&quot;&gt;number=input(&quot;Enter any number/word :&quot;)
i=0
for i in range(len(number)):
    if number[i]!=number[-1-i]:
        print(&#39;It is not a palindrome&#39;)
        break
else:
    print(&#39;It is a palindrome&#39;)
&lt;/pre&gt;


  
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter any number:5665&lt;br /&gt;
It is a palindrome&lt;br /&gt;&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;



&lt;h2&gt;Palindrome String Program in Python using while loop&lt;/h2&gt;
&lt;div&gt;In this program, we will take two pointers i and j. Variable &quot;i&quot; will point to the leftmost characters of the string and &quot;j&quot; will point to the rightmost character. If they are the same then will increase &quot;i&quot; by 1 and decrease j by 1 and so on. If at any index, the characters present at these indexes are different then the given string is not a palindrome.
&lt;pre&gt;str=input(&quot;Enter String: &quot;)
i=0
j=len(str)-1
isPalindrome=True
while i&amp;lt;=j:
    if(str[i]!=str[j]):
        isPalindrome=False
        break
    i+=1
    j-=1

if isPalindrome:
    print(f&quot;{str} is Palindrome.&quot;)
else:
    print(f&quot;{str} is not a Palindrome.&quot;)
    
&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter String: racecar&lt;br /&gt;
racecar is Palindrome.&lt;br /&gt;
  
  &lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

 &lt;div class=&quot;pRelate&quot;&gt;
  &lt;!--[ Related title ]--&gt;
  &lt;b&gt;You may want to read this post :&lt;/b&gt;

  &lt;ul&gt;
     &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/p/python-programs-for-practice.html&quot;&gt;Python Programs for Practice [Beginner + Advance]&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2022/04/prime-number-program-in-python.html&quot;&gt;Python program to check prime number&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Factorial Program in Python&lt;/a&gt;&lt;/li&gt;
   
  &lt;/ul&gt;
&lt;/div&gt;
  &lt;h2&gt;Video Solution&lt;/h2&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/uUIucXNMEKc&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;h2&gt;Using an inbuilt reversed function&lt;/h2&gt;
&lt;!--Ezoic - incontent_7 - incontent_7--&gt;
&lt;div id=&quot;ezoic-pub-ad-placeholder-130&quot;&gt; &lt;/div&gt;
&lt;!--End Ezoic - incontent_7 - incontent_7--&gt;
&lt;pre class=&quot;prettyprint language-py&quot;&gt;word=input(&quot;Enter any word :&quot;)
rev=reversed(word)
if list(word)==list(rev):
    print(&#39;It is a palindrome&#39;)
else:
    print(&#39;It is not a palindrome&#39;)
&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter any word: madam&lt;br /&gt;
It is a palindrome&lt;br /&gt;&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;




  
&lt;h3&gt;Approach to check whether the given string is palindrome or not using an inbuilt reversed function:&lt;/h3&gt;
  
  &lt;ul&gt;
&lt;li&gt;First, we input the string using the input() function.&lt;/li&gt;&lt;li&gt;Using the reversed() function, we reverse the word entered by the user and assign it to a new variable called rev.&lt;/li&gt;&lt;li&gt;Using the if statement, we compare the list(word) &amp;amp; list(rev). If they are the same, then we will print &quot;it is a palindrome&quot;, and if they are not the same, we will print &quot;it is not a palindrome&quot;.&lt;/li&gt;&lt;/ul&gt;
  
  &lt;h2&gt;Valid Palindrome leetcode accepted solution in python&lt;/h2&gt;
  &lt;p&gt;First, we have to remove all non-alphanumeric characters in the given string, and then convert all upper-case letters into lower-case letters. Then we have to check whether the converted string is a valid palindrome or not. A valid palindrome is one which read the same forward and backwards.
&lt;br /&gt;
  &lt;a class=&quot;extL&quot; href=&quot;https://leetcode.com/problems/valid-palindrome/&quot; rel=&quot;noreferrer&quot; target=&quot;_blank&quot;&gt;Problem Link&lt;/a&gt;


  &lt;/p&gt;&lt;pre&gt;import re
class Solution:
    def isPalindrome(self, s: str) -&amp;gt; bool:
        str1=&quot;&quot;.join(re.split(&quot;[^a-zA-Z0-9]*&quot;,s)).lower()
        i=0
        j=len(str1)-1
        isPalindrome=True
        while i&amp;lt;=j:
            if str1[i]!=str1[j]:
                isPalindrome=False
                break
            i+=1
            j-=1
        return isPalindrome
  
  &lt;/pre&gt;
  
&lt;h2&gt;Q. What is a palindrome number in python?&lt;/h2&gt;&lt;p&gt;A number is a palindrome when its reverse is also the same as the original number.&lt;/p&gt;&lt;p&gt;To check whether a number is a palindrome or not, we have to reverse the number using the reversed() function. Then we compare the actual and reversed numbers using the if statement.&lt;/p&gt;&lt;p&gt;for example:8558, is a palindrome&lt;/p&gt;&lt;p&gt;Q. How do you write a palindrome program in python using for loop?&lt;/p&gt;&lt;p&gt;First, we input a number using the input() function, then reverse it using the reversed() function. Then we compare the number (or a word) with its reverse if the actual number and the reversed number are the same, and then we print the number entered as a palindrome. Else, we print the number entered is not a palindrome.&lt;/p&gt; 
  

&lt;div&gt;Programs you may like:&lt;br /&gt;
  &lt;a href=&quot;https://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html&quot;&gt;Menu-driven program in python using while loop&lt;/a&gt;
  &lt;br /&gt;
  &lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Factorial Program in Python using for loop&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;About this Post:&lt;/b&gt;&lt;/div&gt;

  
  
  &lt;p&gt;It is my first python program, so please share and comment below to support us. You can also learn python and many other languages from the &lt;a href=&quot;https://progate.com/&quot;&gt;progate&lt;/a&gt; app. You can download it via the &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.progate&quot;&gt;google play store&lt;/a&gt;.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;You can comment below or contact us if you have any queries related to this program. Thanks for reading this Palindrome program in python.&lt;/p&gt;&lt;p&gt;I hope you enjoy my programs as much as I enjoy offering them to you. If you have any questions or queries related to any program, please don&#39;t hesitate to contact me.&lt;/p&gt;
&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;    &lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/396580727790825499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/05/palindrome-program-in-python.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/396580727790825499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/396580727790825499'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/05/palindrome-program-in-python.html' title='Palindrome Program in Python using for loop [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/uUIucXNMEKc/default.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6391092057723749250</id><published>2022-11-20T21:49:00.000+05:30</published><updated>2022-11-20T21:49:03.141+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="do-while-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Menu-Driven-Programs"/><title type='text'>Menu-Driven Program in C using Switch Case [New]</title><content type='html'>&lt;div&gt;In this post, we will make many menu-driven programs for different tasks, like a program to calculate the area of different shapes, perform the given tasks, and perform arithmetic operations between two matrices.&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Menu-driven program in c:&lt;/b&gt;&amp;nbsp;A program that obtains choice from a user by displaying the menu.

Here are three menu-driven programs using switch case, do-while loop, and while loop.
&lt;/div&gt;
&lt;br /&gt;

&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;&lt;/details&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;
 	&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/11/menu-driven-cplusplus-program-for-a-simple-calculator.html&quot;&gt;In C++&lt;/a&gt;&lt;/li&gt;
 	&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2022/02/calculator-program-in-c.html&quot; rel=&quot;noopener&quot; target=&quot;_blank&quot;&gt;Calculator program in C using Switch Case&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Menu-driven program in c using Switch Case&lt;/h2&gt;
&lt;div&gt;
In this program, we will create a menu-driven program that will print the area of different shapes according to the user&#39;s choice.
&lt;script async=&quot;&quot; crossorigin=&quot;anonymous&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4466619634374852&quot;&gt;&lt;/script&gt;
&lt;!--Ads Above code--&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-4466619634374852&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;5334517657&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/div&gt;
&lt;pre class=&quot;prettyprint language-cpp&quot;&gt;#include&amp;lt;stdio.h&amp;gt;
int main()
{
  int choice, radius, length, breadth, side;
  float area;
  printf(&quot;\n Press 1 to calculate area of Circle &amp;nbsp;\n Press 2 to calculate area of Rectangle \n Press 3 to calculate area of Square \n Press 4 to Exit&quot;);
  printf(&quot;\n Enter your choice:&quot;);
  scanf(&quot;%d&quot;,&amp;amp;choice);
  switch(choice)
  {
    case 1: printf(&quot;\n Enter radius:&quot;);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scanf(&quot;%d&quot;,&amp;amp;radius);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;area=3.14*radius*radius;
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n Area of circle: %f&quot;,area);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;
    case 2: printf(&quot;\n Enter length:&quot;);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scanf(&quot;%d&quot;,&amp;amp;length);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n Enter breadth:&quot;);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scanf(&quot;%d&quot;,&amp;amp;breadth);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n Area of rectangle: %d&quot;,length*breadth);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;
    case 3: printf(&quot;\n Enter Side:&quot;);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;scanf(&quot;%d&quot;,&amp;amp;side);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;\n Area of square: %d&quot;,side*side);
    &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;
    case 4: return 0;
    default: printf(&quot;\n wrong choice&quot;);
  }
  return 0;
}&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;

Press 1 to calculate the area of Circle &lt;br /&gt;
Press 2 to calculate the area of Rectangle&lt;br /&gt;
Press 3 to calculate the area of Square&lt;br /&gt;

Press 4 to Exit&lt;br /&gt;
Enter your choice:1&lt;br /&gt;
Enter radius:5&lt;br /&gt;
Area of circle: 78.500000&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/XS4PfOBw30k&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;h2&gt;Menu-driven program in c&lt;/h2&gt;
&lt;div&gt;Write a c program which performs the following operations:
  &lt;ol&gt;&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/02/factorial-program-in-c-using-for-loop.html&quot;&gt;Factorial program in c using for loop&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;
    &lt;a href=&quot;https://www.codingwithsid.in/2020/05/prime-number-program-in-c.html&quot;&gt;C program to check whether the number is prime or not&lt;/a&gt;.&lt;/li&gt;

&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/05/odd-and-even-numbers-program-in-c.html&quot;&gt;C program to check whether the number is odd or even&lt;/a&gt;.&lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
int main()
{
    char fav;
    int num = 0, choice = 1, fact = 1, i;
    printf(&quot;\n Enter a Number:&quot;);
    scanf(&quot;%d&quot;, &amp;amp;num);
    do
    {
        printf(&quot;\n Press 1 to find factorial of a number \n Press 2 to check whether the number is Prime or Not \n Press 3 to find check number is even or odd \n Press 4 to Exit&quot;);
        printf(&quot;\n Enter your choice:&quot;);
        scanf(&quot;%d&quot;, &amp;amp;choice);
        switch (choice)
        {
        case 1:
            for (i = num; i &amp;gt; 1; i--)
                fact *= i;
            printf(&quot;\n Factorial of %d&quot;, num);
            printf(&quot; is %d&quot;, fact);
            break;
        case 2:
            for (i = 2; i &amp;lt; num; i++)
            {
                if (num % i == 0)
                {
                    printf(&quot; \n %d is not a prime number&quot;, num);
                    break;
                }
            }
            if (num == i)
                printf(&quot;%d is a prime number&quot;, num);
            break;
        case 3:
            if (num % 2 == 0)
                printf(&quot;%d is an even number&quot;, num);
            else
                printf(&quot;\n %d is an odd number&quot;, num);
            break;
        case 4:
            return 0;
        default:
            printf(&quot;\n wrong choice&quot;);
        }
        printf(&quot;\n Do you want to continue?(y/n)\n&quot;);
        scanf(&quot;\n %c&quot;, &amp;amp;fav);
    } while (fav == &#39;y&#39;);
    return 0;
}
&lt;/pre&gt;

&lt;img alt=&quot;Menu driven program in c using switch case and do-while loop&quot; border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7qdmG_qBDiba7c1BkggWpeilMMwiKf2m-4Ms9WEQ88F-aaCa4URVLOy1WzcIbiL6hv-cpzx75LdN_b7gejsfrbC4W2thhbARQbQ1PFLLO4RsFJvYEABDsWzJPjPbcZtaLvXh_xvqCvWA/w640-h360/Menu+driven+program+in+c+using+switch+case+and+do-while+loop.webp&quot; title=&quot;Menu driven program in c using switch case and do-while loop&quot; width=&quot;640&quot; /&gt;
&lt;img alt=&quot;Output of c program to check whether the number is odd or even&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNtwKYwTPpxTeeM4IexSZkbMzaRHtas8b_3OqDEbceGPXVi8fas2XFh9vtVPgmRL-68hJsUewkZ_7ZpajPOx1B2PK9tB_MeevH2z5V_lBQAiTbd9Lo96oYWzOHD66smKpFDiEGbVJ-L-E/w640-h360/Output+of+c+program+to+check+whether+the+number+is+odd+or+even++.png&quot; title=&quot;Output of c program to check whether the number is odd or even&quot; width=&quot;640&quot; /&gt;
&lt;h3&gt;Algorithm for Menu-driven program in c&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Initialize three int variables and a one-character variable.&lt;/li&gt;&lt;li&gt;Now take the number from the user and store it in an int variable.&lt;/li&gt;&lt;li&gt;Print all the choices on the screen and take the user&#39;s choice.&lt;/li&gt;&lt;li&gt;We will pass our choice variable to the switch case, and the choice is an int variable containing the user&#39;s preference. (you can write any valid identifier)&lt;/li&gt;&lt;li&gt;Make statements of case 1, case 2, case 3, etc., using for loop and if-else statements, and at the end of every case statement, write a break so that it doesn&#39;t go for the next statement.&lt;/li&gt;&lt;li&gt;Write a default statement in case the user enters the wrong choice.&lt;/li&gt;&lt;li&gt;Now display a message on the screen that do you want to continue?&lt;/li&gt;&lt;li&gt;&amp;nbsp;If the user wants to continue, then they should press y.&lt;/li&gt;&lt;li&gt;Take the input from the user in the character variable, and don&#39;t forget to press the space between &quot;and % in the scanf statement.&lt;/li&gt;&lt;li&gt;In the end, you must write the do-while loop&#39;s testing statement.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Menu-driven program for matrix operations in c using switch case&lt;/h2&gt;
In this program, we will perform all three functions, i.e., addition, subtraction, and multiplication of matrices, using a 2-D array.
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
    int C[10][10], A[10][10], B[10][10], i, j, ch, rows, cols,l;
    printf(&quot;Menu-driven program for matrix operations in c&quot;);

    printf(&quot;\n Enter Rows:&quot;);
    scanf(&quot;%d&quot;, &amp;amp;rows);

    printf(&quot;\n Enter Columns:&quot;);
    scanf(&quot;%d&quot;, &amp;amp;cols);

    printf(&quot;\n Matrix A\n&quot;);
    printf(&quot;\n Enter the numbers you want to insert in the matrix A:&quot;);
    for (i = 0; i &amp;lt; rows; i++)
    {
        for (j = 0; j &amp;lt; cols; j++)
        {
            printf(&quot;\t&quot;);
            scanf(&quot;%d&quot;, &amp;amp;A[i][j]);
        }
    }
    printf(&quot;\n Matrix A:\n&quot;);
    for (i = 0; i &amp;lt; rows; i++)
    {
        for (j = 0; j &amp;lt; cols; j++)
        {
            printf(&quot;%d&quot;, A[i][j]);
            printf(&quot;\t&quot;);
        }
        printf(&quot;\n&quot;);
    }
    printf(&quot;\n Enter the numbers you want to insert in the matrix B:&quot;);
    for (i = 0; i &amp;lt; rows; i++)
    {
        for (j = 0; j &amp;lt; cols; j++)
        {
            printf(&quot;\t&quot;);
            scanf(&quot;%d&quot;, &amp;amp;B[i][j]);
        }
    }
    printf(&quot;\n Matrix B:\n&quot;);
    for (i = 0; i &amp;lt; rows; i++)
    {
        for (j = 0; j &amp;lt; cols; j++)
        {
            printf(&quot;%d&quot;, B[i][j]);
            printf(&quot;\t&quot;);
        }
        printf(&quot;\n&quot;);
    }
    printf(&quot;\n 1. Addition of Matrix A &amp;amp; B &quot;);
    printf(&quot;\n 2. Subtraction Of Matrix A and matrix B n&quot;);
    printf(&quot;\n 3. Multiplication of Matrix A &amp;amp; B&quot;);
    printf(&quot;\n Enter your choice (1 ,2,3):&quot;);
    scanf(&quot;\n %d&quot;, &amp;amp;ch);
    switch (ch)
    {
    case 1:
        printf(&quot;\n A+B=\n&quot;);
        for (i = 0; i &amp;lt; rows; i++)
        {
            for (j = 0; j &amp;lt; cols; j++)
            {
                C[i][j] = A[i][j] + B[i][j];
                printf(&quot;%d&quot;, C[i][j]);
                printf(&quot;\t&quot;);
            }
            printf(&quot;\n&quot;);
        }
        break;
    case 2:
        printf(&quot;\n A-B=\n&quot;);
        for (i = 0; i &amp;lt; rows; i++)
        {
            for (j = 0; j &amp;lt; cols; j++)
            {
                C[i][j] = A[i][j] - B[i][j];
                printf(&quot;%d&quot;, C[i][j]);
                printf(&quot;\t&quot;);
            }
            printf(&quot;\n&quot;);
        }
        break;
    case 3:
        printf(&quot;\n A*B=\n&quot;);
        for (i = 0; i &amp;lt; rows; i++)
        {
            for (j = 0; j &amp;lt; rows; j++)
            {
                C[i][j] = 0;
                for (l = 0; l &amp;lt; cols; l++)
                {
                    C[i][j] = C[i][j] + A[i][l] * B[l][j];
                }
                printf(&quot;%d&quot;, C[i][j]);
                printf(&quot;\t&quot;);
            }
            printf(&quot;\n&quot;);
        }
        break;
    default:
        printf(&quot;\n Wrong Choice&quot;);
    }
    return 0;
}
&lt;/pre&gt;&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Matrix A:&lt;br /&gt;
1 2&lt;br /&gt;
3 4&lt;br /&gt;

Matrix B:&lt;br /&gt;
1 2&lt;br /&gt;
3 4&lt;br /&gt;

1. Addition of Matrix A &amp;amp; B&lt;br /&gt;
2. Subtraction Of Matrix A and matrix B&lt;br /&gt;
3. Multiplication of Matrix A &amp;amp; B&lt;br /&gt;
Enter your choice (1, 2, 3):1&lt;br /&gt;
A+B=&lt;br /&gt;
2 4&lt;br /&gt;
6 8&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3&gt;About this Post:&lt;/h3&gt;
&lt;div&gt;&lt;div&gt;In this post, we learn to make a menu-driven program to print areas of circles, squares, and rectangles. We also perform matrix operations using a switch case and do-while loop.&amp;nbsp;&lt;/div&gt;&lt;br /&gt;
  
  &lt;div&gt;The second program answers one of the most essential questions in the book &quot;Let Us C&quot; by Yashwant Singh Kandari.&lt;/div&gt;&lt;br /&gt;
  
&lt;div&gt;If you like this, please comment below to support us, and you can freely ask your doubts in the comment section.&lt;/div&gt;&lt;br /&gt;
  
  &lt;div&gt;This program will clear your concepts about switch case programs, do-while loops, for loops, if-else statements, and exit functions.&lt;/div&gt;&lt;br /&gt;
  
&lt;h2&gt;The solution of scanf (“%c”,&amp;amp;ch) not working&lt;/h2&gt;
&lt;div&gt;Important note about taking the value of a character from a user in c using scanf
&lt;blockquote&gt;scanf(“%c”,&amp;amp;ch)&lt;/blockquote&gt;&lt;div&gt;The above statement is wrong, but the compiler ignores this error; when you compile this statement in your program, it will not show any errors.&lt;br /&gt;
  Moreover, this statement will not be executed when you execute your program.&lt;br /&gt;
  Therefore you have to press space between &quot;and % means you have to use the following statement:&lt;/div&gt;
  &lt;blockquote&gt;scanf(“ %c”,&amp;amp;ch)&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;
&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6391092057723749250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/06/menu-driven-program-in-c.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6391092057723749250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6391092057723749250'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/06/menu-driven-program-in-c.html' title='Menu-Driven Program in C using Switch Case [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/XS4PfOBw30k/default.jpg" height="72" width="72"/><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-4452821757975185895</id><published>2022-11-20T21:33:00.000+05:30</published><updated>2022-11-20T21:33:18.456+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="if-else"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Leap Year Program in Python using if-else</title><content type='html'>
&lt;p&gt;&amp;nbsp;In this post, we will make a python program to check whether the given year is a leap year.&lt;/p&gt;&lt;p&gt;Leap Year: One year in every four&amp;nbsp;has 366 days [February has 29 days instead of 28].&amp;nbsp;The reason why we have leap years is really fascinating, this video does more justice: &lt;a class=&quot;extL&quot; href=&quot;https://www.youtube.com/watch?v=xX96xng7sAE&quot; rel=&quot;noreferrer&quot; target=&quot;_blank&quot;&gt;Video Link&lt;/a&gt;
&lt;/p&gt;
&lt;h2&gt;Algorithm:&lt;/h2&gt;
If one of the following conditions is satisfied then the given year is a leap year.
&lt;ul&gt;
  &lt;li&gt;Every year that is divisible by 4 and not divisible by 100.&lt;/li&gt;
  &lt;li&gt;A year that is divisible by 4 and also divisible by 400.&lt;br /&gt;&lt;/li&gt;
  
&lt;/ul&gt;
&lt;h2&gt;Leap Year Program in Python&amp;nbsp;using if-else&lt;/h2&gt;
&lt;div&gt;In this program, we will check for leap year using simple if-else conditions. We will take input from the user and typecast it to int and then check whether the given year is a leap year or not using the above algorithm.&lt;/div&gt;
&lt;pre&gt;year = int(input(&quot;Which year do you want to check? &quot;))

if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0):
    print(&quot;Leap year.&quot;)
else:
    print(&quot;Not leap year.&quot;)

&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Which year do you want to check? 2022&lt;br /&gt;
Not leap year.&lt;br /&gt;
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/3cZGJZbc1BA&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;

&lt;div class=&quot;pRelate&quot;&gt;&lt;b&gt;Related Posts :&lt;/b&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Factorial Program in Python&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/05/palindrome-program-in-python.html&quot;&gt;Python program for palindrome&lt;/a&gt;&lt;/li&gt;
    
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h2&gt;leap year program in python hackerrank solution&lt;/h2&gt;
&lt;div&gt;In this program, we will code answers for the leap year question at hackerrank. We completed the is_leap function and it will return true when the given year is a leap year and false otherwise.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjHTl6jmRwzAs4OXb4snSD8kXwc0aC_Nd_GxttpasHVaNFmWHg1zxQlr8LsBxylMvWkD32W2HB1cCbZRj5CCRceCvbemXAA-4S6A0Ay0RtxXllhaD6u51DxV9-WxO3TIyZt8MY1qk7skAau49WgUK384gGH-QbUFeT_rwFgMPtXRS2LlhnhvfbFfio/s896/Leap%20Year%20Program%20in%20Python.webp&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;leap year program in python hackerrank solution&quot; border=&quot;0&quot; data-original-height=&quot;592&quot; data-original-width=&quot;896&quot; height=&quot;422&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjHTl6jmRwzAs4OXb4snSD8kXwc0aC_Nd_GxttpasHVaNFmWHg1zxQlr8LsBxylMvWkD32W2HB1cCbZRj5CCRceCvbemXAA-4S6A0Ay0RtxXllhaD6u51DxV9-WxO3TIyZt8MY1qk7skAau49WgUK384gGH-QbUFeT_rwFgMPtXRS2LlhnhvfbFfio/w640-h422/Leap%20Year%20Program%20in%20Python.webp&quot; title=&quot;leap year program in python hackerrank solution&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
  
&lt;pre&gt;def is_leap(year):
  leap = False

  # Write your logic here
  if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0):
      leap=True
  return leap

year = int(input())
print(is_leap(year))
&lt;/pre&gt;
  
&lt;div&gt;I hope you like this post, if you like this post please comment and if you are new to our blog please subscribe to our &lt;a href=&quot;https://follow.it/coding-with-sid?pub&quot; target=&quot;_blank&quot;&gt;newsletter&lt;/a&gt;. Thank you so much for reading. &lt;br /&gt;&lt;br /&gt;If you are looking for jobs/internships, you may join our &lt;a href=&quot;https://t.me/hiringseajobs&quot;&gt;telegram&lt;/a&gt; for the latest jobs and internships updates.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/4452821757975185895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/10/leap-year-program-in-python.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4452821757975185895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4452821757975185895'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/10/leap-year-program-in-python.html' title='Leap Year Program in Python using if-else'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/3cZGJZbc1BA/default.jpg" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-5921710419934005711</id><published>2022-11-15T13:45:00.001+05:30</published><updated>2022-11-15T13:49:07.102+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Python Program to Check Armstrong Number using while loop</title><content type='html'>&lt;details class=&quot;sp toc&quot; open=&quot;&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In this program, we will make a program to check whether the given number is Armstrong. We will also make a python program to print(or find) Armstrong numbers in an interval.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;&lt;strong style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0e101a; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;Armstrong numbers in python:&lt;/strong&gt;&lt;span data-preserver-spaces=&quot;true&quot; style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #0e101a; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;&amp;nbsp;Armstrong number is a number that is the sum of its digits, each raised to the power of the number of digits.&lt;/span&gt;&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:image--&gt;
&lt;img alt=&quot;Python Program to Check Armstrong Number using while loop&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZt-1Dk25gg45940hjfpHERdIOkiWjzoS9pK58zfMiIPdvGCAkoAgkyPpNn6uYv0ytMIm_ej7YJxxXDP58qzB1md2aopsvWEmBoi7rJyIkKS13JceqnfhJ_KkPPAqNgfuiLgS29zqKaXU/s16000/armstrong.jpg&quot; title=&quot;Python Program to Check Armstrong Number using while loop&quot; /&gt;
&lt;!--/wp:image--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Python Program to Check Armstrong Number using while loop&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In this Python program, we will check whether the number entered by the user is an Armstrong number.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:preformatted--&gt;
&lt;pre class=&quot;prettyprint language-py&quot;&gt;num = int(input(&quot;Enter a Number:&quot;))
order = len(str(num))
temp = num;
sum = 0
while(temp&amp;gt;0):
	digit =temp%10
	sum += digit **order
	temp = temp//10
if(sum==num):
	print(&quot;&quot;,num,&quot;is an Armstrong number&quot;)
else:
	print(&quot;&quot;,num,&quot;is not an Armstrong number&quot;)

	&lt;/pre&gt;
&lt;!--/wp:preformatted--&gt;

&lt;!--wp:paragraph--&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter a Number:371&lt;br /&gt;
371 is an Armstrong number
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:heading {&quot;level&quot;:3}--&gt;
&lt;h3&gt;Algorithm:&lt;/h3&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:list {&quot;ordered&quot;:true}--&gt;
&lt;ol&gt;&lt;li&gt;Input the number from the user.&lt;/li&gt;&lt;li&gt;Initialize &quot;order&quot; with the length of the num variable.(order= Number of digits)&lt;/li&gt;&lt;li&gt;Store the value of the num variable in the temp variable.&lt;/li&gt;&lt;li&gt;Initialize the sum of digits with zero.&lt;/li&gt;&lt;li&gt;While temp&amp;gt;0, repeat steps 6-7.&lt;/li&gt;&lt;li&gt;digit =temp%10 and sum += digit **order&lt;/li&gt;&lt;li&gt;temp = temp//10&lt;/li&gt;&lt;li&gt;If the sum equals num, then we will print the number entered by the user as an Armstrong number&lt;/li&gt;&lt;/ol&gt;
&lt;!--/wp:list--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;Related post: &lt;a href=&quot;https://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html&quot;&gt;Menu-Driven Program in Python using while loop&lt;/a&gt;&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Python Program to find Armstrong Number in an Interval.&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;This program will print Armstrong numbers between intervals according to the lower and upper range. Here, the lower range and upper range are given by the user.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:preformatted--&gt;
&lt;pre class=&quot;prettyprint language-py&quot;&gt;lower = int(input(&quot;Enter lower range:&quot;))
upper = int(input(&quot;Enter upper range:&quot;))


for num in range(lower,upper+1):
	sum = 0
	order = len(str(num))
	temp = num;
	while(temp&amp;gt;0):
		digit=temp%10
		sum += digit **order
		temp = temp//10
		if(sum==num):
			print(num)
&lt;/pre&gt;
&lt;!--/wp:preformatted--&gt;

&lt;!--wp:paragraph--&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter lower range:100&lt;br /&gt;Enter upper range:1000&lt;br /&gt;125&lt;br /&gt;153&lt;br /&gt;216&lt;br /&gt;370&lt;br /&gt;371&lt;br /&gt;407&lt;br /&gt;729
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;&lt;!--/wp:paragraph--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Armstrong Number in Python using for loop&lt;/h2&gt;
&lt;!--/wp:heading--&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/W_dtihcaR5g&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;

&lt;!--wp:preformatted--&gt;
&lt;pre class=&quot;prettyprint language-py&quot;&gt;num = int(input(&quot;Enter a Number:&quot;))
order = len(str(num))
temp = num;
sum = 0
stnum=str(num)
for i in stnum:
    digit =temp%10
    sum += digit **order
    temp = temp//10
if(sum==num):
    print(&quot;&quot;,num,&quot;is an Armstrong number&quot;)
else:
    print(&quot;&quot;,num,&quot;is not an Armstrong number&quot;)
&lt;/pre&gt;
&lt;!--/wp:preformatted--&gt;

&lt;!--wp:paragraph--&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter a Number:656&lt;br /&gt;
656 is not an Armstrong number
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;
Related posts:&lt;br /&gt; &lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Python program to find the factorial of a number&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://www.codingwithsid.in/2020/05/palindrome-program-in-python.html&quot;&gt;Palindrome Program in Python&lt;/a&gt;
&lt;/div&gt;
&lt;div&gt;&lt;h3&gt;Conclusion:&lt;/h3&gt;
    This post is all about making a program to check an Armstrong number. I hope this program will run successfully on your device. You should comment below if you have any doubts about this program.&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;&lt;/div&gt;
&lt;!--/wp:paragraph--&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/5921710419934005711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2021/02/python-program-to-check-armstrong-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5921710419934005711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5921710419934005711'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2021/02/python-program-to-check-armstrong-number.html' title='Python Program to Check Armstrong Number using while loop'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZt-1Dk25gg45940hjfpHERdIOkiWjzoS9pK58zfMiIPdvGCAkoAgkyPpNn6uYv0ytMIm_ej7YJxxXDP58qzB1md2aopsvWEmBoi7rJyIkKS13JceqnfhJ_KkPPAqNgfuiLgS29zqKaXU/s72-c/armstrong.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-5399521156723983342</id><published>2022-10-28T21:48:00.000+05:30</published><updated>2022-10-28T21:48:21.578+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Calculator Program in Python using while loop</title><content type='html'>&lt;div&gt; &lt;b&gt; Menu-driven calculator program:&lt;/b&gt; According to the input, it will perform addition, subtraction, multiplication, and division of two numbers.&lt;/div&gt;&lt;br /&gt;

&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2&gt;Calculator Program in Python using while loop&lt;/h2&gt;
&lt;div&gt;
We will make a calculator by creating a &lt;a href=&quot;https://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html&quot;&gt;menu-driven program in python&lt;/a&gt; for addition, subtraction, multiplication, and division of two numbers. The user will choose any options, and then we will take input from the user and call the appropriate function. We will perform some operations and print the result.&lt;/div&gt;

&lt;pre class=&quot;prettyprint language-py&quot;&gt;def addition(num1,num2):
&amp;nbsp; &amp;nbsp; print(&quot;Addition=&quot;,num1+num2)

def subtraction(num1,num2):
&amp;nbsp; &amp;nbsp; print(&quot;Subtraction=&quot;,num1-num2)

def multiplication(num1,num2):
&amp;nbsp; &amp;nbsp; print(&quot;Multiplication=&quot;,num1*num2)

def division(num1,num2):
&amp;nbsp; &amp;nbsp; print(&quot;Division=&quot;,num1/num2)

while True:
&amp;nbsp; &amp;nbsp; print(&quot;1. Addition&quot;)
&amp;nbsp; &amp;nbsp; print(&quot;2. Subtraction&quot;)
&amp;nbsp; &amp;nbsp; print(&quot;3. Multiplication&quot;)
&amp;nbsp; &amp;nbsp; print(&quot;4. Division&quot;) &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; print(&quot;5. Exit&quot;)
&amp;nbsp; &amp;nbsp; choice=int(input(&quot;Enter your choice(1-5):&quot;))

&amp;nbsp; &amp;nbsp; if choice==1:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num1=int(input(&quot;Enter 1st Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num2=int(input(&quot;Enter 2nd Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; addition(num1,num2)


&amp;nbsp; &amp;nbsp; elif choice==2:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num1=int(input(&quot;Enter 1st Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num2=int(input(&quot;Enter 2nd Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; subtraction(num1,num2)
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; elif choice==3:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num1=int(input(&quot;Enter 1st Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num2=int(input(&quot;Enter 2nd Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; multiplication(num1,num2)
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; elif choice==4:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num1=int(input(&quot;Enter 1st Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num2=int(input(&quot;Enter 2nd Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if num2 == 0:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(&#39;Infinity&#39;)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; division(num1,num2)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; elif choice==5:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break
&amp;nbsp; &amp;nbsp; else:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(&quot;Wrong Choice&quot;)

&lt;/pre&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvd4Tk5KL5oc9HObgVBGHDNfLkGJdFsMqs3YADlsKNzqQd4y-XsJohVRf2hGUU-_3AhmVb77tCAs52Ik7CtzSrJsicVfufaLaXHvcp_-d7sDzjEOYBNLuF_mBPWOFbmqUV98Uyy7e-x-w/s1365/Calculator+Program+in+Python+using+while+loop.webp&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Calculator Program in Python using while loop&quot; border=&quot;0&quot; data-original-height=&quot;735&quot; data-original-width=&quot;1365&quot; height=&quot;344&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvd4Tk5KL5oc9HObgVBGHDNfLkGJdFsMqs3YADlsKNzqQd4y-XsJohVRf2hGUU-_3AhmVb77tCAs52Ik7CtzSrJsicVfufaLaXHvcp_-d7sDzjEOYBNLuF_mBPWOFbmqUV98Uyy7e-x-w/w640-h344/Calculator+Program+in+Python+using+while+loop.webp&quot; title=&quot;Calculator Program in Python using while loop&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;1. Addition&lt;br /&gt;
2. Subtraction&lt;br /&gt;
3. Multiplication&lt;br /&gt;
4. Division&lt;br /&gt;
5. Exit Enter your choice(1-5):1&lt;br /&gt;
Enter 1st Number:2&lt;br /&gt;
Enter 2nd Number:6&lt;br /&gt;
Addition= 8&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Video Solution&lt;/h2&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; alt=&quot;Menu-driven Calculator Program in Python&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/8Pzfb42MB5A&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;


&lt;div&gt;&lt;b&gt;Quick algorithm for Calculator Program:&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Print the menu for those arithmetic operations our program can perform, i.e., addition, subtraction, multiplication, and division.&lt;/li&gt;&lt;li&gt;Take the input from the user.&lt;/li&gt;&lt;li&gt;According to their choice, call the appropriate function.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Handle edge case for division operation, i.e., denominator can&#39;t be equal to zero.&lt;/li&gt;&lt;li&gt;We will perform the arithmetic operation and print the result.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;For example:&amp;nbsp;&lt;br /&gt;
      &lt;pre class=&quot;prettyprint language-py&quot;&gt;&amp;nbsp; &amp;nbsp; if choice==1:
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num1=int(input(&quot;Enter 1st Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; num2=int(input(&quot;Enter 2nd Number:&quot;))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; addition(num1,num2)&lt;/pre&gt;&amp;nbsp;&lt;/div&gt;
&lt;h2&gt;Python Program for Calculator using functions&lt;/h2&gt;
&lt;p&gt;In this program, I made a calculator using functions, a dictionary and a while loop.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;functions: To perform different arithmetic operations like addition, subtraction, multiplication and division.&lt;/li&gt;
  &lt;li&gt;dictionary: To assign every arithmetic symbol to the function name. [&#39;+&#39; to &lt;b&gt;add&lt;/b&gt; function]&lt;/li&gt;
  &lt;li&gt;while loop: To perform repetitive calculations according to user choice.&lt;/li&gt;
  &lt;li&gt;Users can also continue calculations with the previous answers or can also perform the new calculation.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;logo = &quot;&quot;&quot;
 _____________________
|  _________________  |
| |                 | |  .----------------.  .----------------.  .----------------.  .----------------. 
| |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. |
|  ___ ___ ___   ___  | | |     ______   | || |      __      | || |   _____      | || |     ______   | |
| | 7 | 8 | 9 | | + | | | |   .&#39; ___  |  | || |     /  \     | || |  |_   _|     | || |   .&#39; ___  |  | |
| |___|___|___| |___| | | |  / .&#39;   \_|  | || |    / /\ \    | || |    | |       | || |  / .&#39;   \_|  | |
| | 4 | 5 | 6 | | - | | | |  | |         | || |   / ____ \   | || |    | |   _   | || |  | |         | |
| |___|___|___| |___| | | |  \ `.___.&#39;\  | || | _/ /    \ \_ | || |   _| |__/ |  | || |  \ `.___.&#39;\  | |
| | 1 | 2 | 3 | | x | | | |   `._____.&#39;  | || ||____|  |____|| || |  |________|  | || |   `._____.&#39;  | |
| |___|___|___| |___| | | |              | || |              | || |              | || |              | |
| | . | 0 | = | | / | | | &#39;--------------&#39; || &#39;--------------&#39; || &#39;--------------&#39; || &#39;--------------&#39; |
| |___|___|___| |___| |  &#39;----------------&#39;  &#39;----------------&#39;  &#39;----------------&#39;  &#39;----------------&#39; 
|_____________________|
&quot;&quot;&quot;



def add(n1,n2):
  return n1+n2

def subtract(n1,n2):
  return n1-n2

def multiply(n1,n2):
  return n1*n2

def divide(n1,n2):
  return n1/n2

operations={
  &#39;+&#39;:add,
  &#39;-&#39;:subtract,
  &#39;*&#39;:multiply,
  &#39;/&#39;:divide
}
def calculator():
  print(logo)
  choice=True
  num1=float(input(&quot;What&#39;s the first number?&quot;))
  for key in operations:
      print(key)
    
  while choice:
    
    operation_symbol=input(&quot;Pick an operation: &quot;)
    num2=float(input(&quot;What&#39;s the second number?&quot;))
    ans=operations[operation_symbol](num1,num2)
    
    print(f&quot;{num1} {operation_symbol} {num2} = {ans}&quot;)
    cont=input(f&quot;Type&#39;y&#39; to continue calculating with {ans},or type &#39;n&#39; to exit.: &quot;).lower()
    if cont!=&#39;y&#39;:
        choice=False
        calculator()
    else:
      num1=ans

calculator()

&lt;/pre&gt;
  &lt;h3&gt;About this Menu-driven Calculator Program:&lt;/h3&gt;
 &lt;div&gt; We made a simple calculator program in python using a while loop, if-else statements, and functions. According to the user&#39;s choice, this program can add, subtract, multiply and divide two numbers. It is also a menu-driven program to perform arithmetic operations in python. &lt;/div&gt;
&lt;div&gt;
  &lt;b&gt;Related Posts:&lt;/b&gt;&lt;br /&gt;
  &lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Python Program to Find Factorial of a Number using for loop&lt;/a&gt;&lt;br /&gt;
  &lt;a href=&quot;https://www.codingwithsid.in/2020/10/menu-driven-program-in-python.html&quot;&gt;Menu Driven Program in Python using while loop&lt;/a&gt;&lt;br /&gt;
   &lt;a href=&quot;https://www.codingwithsid.in/2021/03/python-program-to-calculate-simple-interest-and-compound-interest.html&quot;&gt;Simple Interest Program in Python&lt;/a&gt;
  &lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/5399521156723983342/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2021/03/calculator-program-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5399521156723983342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5399521156723983342'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2021/03/calculator-program-in-python.html' title='Calculator Program in Python using while loop'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvd4Tk5KL5oc9HObgVBGHDNfLkGJdFsMqs3YADlsKNzqQd4y-XsJohVRf2hGUU-_3AhmVb77tCAs52Ik7CtzSrJsicVfufaLaXHvcp_-d7sDzjEOYBNLuF_mBPWOFbmqUV98Uyy7e-x-w/s72-w640-h344-c/Calculator+Program+in+Python+using+while+loop.webp" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-8798338363785624218</id><published>2022-10-08T12:41:00.004+05:30</published><updated>2022-10-27T21:35:40.221+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Switch-Case"/><title type='text'>Calculator program in C using Switch Case [New]</title><content type='html'>
&lt;p&gt;In this Calculator program in C using a switch case, we will perform arithmetic operations (i.e., addition, subtraction, multiplication, and division) between two numbers in c language using a&amp;nbsp;&lt;a href=&quot;https://www.codingwithsid.in/search/label/Switch-Case&quot;&gt;switch case&lt;/a&gt; and &lt;a href=&quot;https://www.codingwithsid.in/search/label/do-whileloop&quot;&gt;do-while loop&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;
&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2&gt;Calculator program in C using switch case&lt;/h2&gt;
&lt;div&gt;In this post, we will make a simple calculator using a switch case in c. We can add, subtract, multiply and divide two numbers using this program.&lt;/div&gt;
&lt;pre class=&quot;prettyprint language-c&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
int main()
{
	int a, b, ch;
	char choice;
	printf(&quot;\n Enter two numbers:&quot;);
	scanf(&quot;%d%d&quot;, &amp;amp;a, &amp;amp;b);
	do
	{
		printf(&quot;\n Press 1 to add %d and %d&quot;, a, b);
		printf(&quot;\n Press 2 to subtract %d and %d&quot;, a, b);
		printf(&quot;\n Press 3 to multiply %d and %d&quot;, a, b);
		printf(&quot;\n Press 4 to divide %d and %d&quot;, a, b);
		printf(&quot;\n Enter Your Choice: &quot;);
		scanf(&quot;%d&quot;, &amp;amp;ch);
		switch (ch)
		{
		case 1:
			printf(&quot;Sum: %d&quot;, a + b);
			break;
		case 2:
			printf(&quot;Subtract :%d&quot;, a - b);
			break;
		case 3:
			printf(&quot;Multiply :%d&quot;, a * b);
			break;
		case 4:
			if (b == 0)
				printf(&quot;\n Denominator cannot be zero&quot;);
			else
				printf(&quot;Divide :%d&quot;, a / b); // b should not be zero
			break;
		default:
			printf(&quot;Wrong choice!&quot;);
		}
		printf(&quot;\n Do you want to continue? (Press y/n)&quot;);
		scanf(&quot; %c&quot;, &amp;amp;choice);
	} while (choice == &#39;y&#39;);
	return 0;
}
&lt;/pre&gt;
&lt;div class=&quot;pRelate&quot;&gt;
  &lt;!--[ Related title ]--&gt;
  &lt;b&gt;You may want to read this post :&lt;/b&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/05/prime-number-program-in-c.html&quot;&gt;Prime Number Program in C using for loop and while loop&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/06/menu-driven-program-in-c.html&quot;&gt;Menu-Driven Program in C using Switch Case [New]&lt;/a&gt;&lt;/li&gt;
    
  &lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEje4mRKMZrIELOFMnNhQGK6HaDIEva-0XXUccu_lCqcjrLk5lERXkeBg6quvvHE3lG-TYGPrrs-M_mgQuwh10tJAOaM3SmLMysPARrAnBuDsdzErZ0XGBqu4_IFU5_lWGsQ2PkvtT3YhWPR6JoQi4OOA8uqpUf5hVOp_57GvsuJO9S2JsSNjJo0z0vL=s699&quot; style=&quot;display: block; padding: 1em 0px; text-align: center;&quot;&gt;&lt;img alt=&quot;Calculator program in C using Switch Case&quot; border=&quot;0&quot; data-original-height=&quot;637&quot; data-original-width=&quot;699&quot; height=&quot;583&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEje4mRKMZrIELOFMnNhQGK6HaDIEva-0XXUccu_lCqcjrLk5lERXkeBg6quvvHE3lG-TYGPrrs-M_mgQuwh10tJAOaM3SmLMysPARrAnBuDsdzErZ0XGBqu4_IFU5_lWGsQ2PkvtT3YhWPR6JoQi4OOA8uqpUf5hVOp_57GvsuJO9S2JsSNjJo0z0vL=w640-h583&quot; title=&quot;Calculator program in C using Switch Case&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
 Enter two numbers:5 3&lt;br /&gt;
&lt;br /&gt;
 Press 1 to add 5 and 3&lt;br /&gt;
 Press 2 to subtract 5 and 3&lt;br /&gt;
 Press 3 to multiply 5 and 3&lt;br /&gt;
 Press 4 to divide 5 and 3&lt;br /&gt;
 Enter Your Choice: 1&lt;br /&gt;
 Sum: 8&lt;br /&gt;
 Do you want to continue? (Press y/n)n&lt;/samp&gt;&lt;/p&gt;&lt;/div&gt;


&lt;h3&gt;Approach to make a simple calculator program using switch case and do-while loop:-&lt;/h3&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Initialize three numbers, one number is for the user&#39;s choice, and we perform arithmetic operations on the other two numbers.&lt;/li&gt;&lt;li&gt;Input two numbers on which we perform arithmetic operations.&lt;/li&gt;&lt;li&gt;Print all the options and input the preference of the user.&lt;/li&gt;&lt;li&gt;Using the switch keyword, we write all four cases for addition, subtraction, multiplication, and division.&lt;/li&gt;&lt;li&gt;Do not forget to write a break at the end of the case statement.&lt;/li&gt;&lt;li&gt;You can also write a default statement if the user inputs the wrong choice.&lt;/li&gt;&lt;li&gt;for example: - default:printf(&quot;Wrong choice!&quot;);&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;


&lt;h2&gt;Simple Calculator Program in C using functions&lt;/h2&gt;
&lt;p&gt;In this program, we are making a Calculator program in C using Switch Case and functions.&lt;/p&gt;
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
int add(int a,int b)
{
    return a+b;
}

int subtract(int a,int b)
{
    return a-b;
}

int multilply(int a,int b)
{
    return a*b;
}

int divide(int a,int b)
{
    return a/b;
}
int main()
{
	int a, b;
	char choice;
	printf(&quot;\n Enter two numbers:&quot;);
	scanf(&quot;%d%d&quot;, &amp;amp;a, &amp;amp;b);
	
	
	printf(&quot;\n Enter Your Choice (+,-,*,/): &quot;);
	scanf(&quot; %c&quot;, &amp;amp;choice);
	switch (choice)
	{
	case &#39;+&#39;:
	    
		printf(&quot;Sum: %d&quot;, add(a,b));
		break;
	case &#39;-&#39;:
		printf(&quot;Subtract :%d&quot;, subtract(a,b));
		break;
	case &#39;*&#39;:
		printf(&quot;Multiply :%d&quot;, multilply(a,b));
		break;
	case &#39;/&#39;:
		if (b == 0)
			printf(&quot;\n Denominator cannot be zero&quot;);
		else
			printf(&quot;Divide :%d&quot;, divide(a,b)); // b should not be zero
		break;
	default:
		printf(&quot;Wrong choice!&quot;);
	}
	return 0;
}

&lt;/pre&gt;

&lt;h2&gt;Program for Calculator in c using while loop&lt;/h2&gt;
&lt;p&gt;In this program, we will make a simple calculator using a while loop and an if-else statement instead of a switch case.&lt;/p&gt;

&lt;div class=&quot;videoYt&quot;&gt;
  &lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; class=&quot;lazy&quot; data-src=&quot;https://www.youtube.com/embed/5QLxkgnl1Nc&quot; title=&quot;Lazy Iframe&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;h3&gt;C program to create a Calculator using if-else&lt;/h3&gt;

&lt;pre class=&quot;prettyprint language-c&quot;&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdlib.h&amp;gt;
int main()
{
int num1, num2, choice;
while(1)
&amp;nbsp; &amp;nbsp;&amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Menu Driven Program in c&quot;);
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; printf(&quot;\n 1.Addition&quot;);
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; printf(&quot;\n 2.Subtraction&quot;);
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; printf(&quot;\n 3.Multiplication&quot;);&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;printf(&quot;\n 4.Division&quot;);
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; printf(&quot;\n 5.exit&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter Choice:&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;choice);&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; if(choice&amp;gt;0 &amp;amp;&amp;amp; choice&amp;lt;6)
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp;&amp;nbsp;if (choice==1)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 1st number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 2nd number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n %d + %d = %d&quot;,num1,num2,num1+num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; if (choice==2)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 1st number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 2nd number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n %d - %d = %d&quot;,num1,num2,num1-num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; if (choice==3)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 1st number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 2nd number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n %d * %d = %d&quot;,num1,num2,num1*num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp;&amp;nbsp;if (choice==4)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 1st number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num1);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Enter 2nd number: &quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; scanf(&quot;%d&quot;,&amp;amp;num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(num2==2)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n Denominator cannot be zero&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n %d / %d = &quot;,num1,num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;%d&quot;,num1/num2);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; if(choice==5)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(0);
&amp;nbsp; &amp;nbsp; } &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; else printf(&quot;\n Wrong choice&quot;);
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; return 0;
}&lt;/pre&gt;
&lt;h4&gt;Output for Menu-driven Calculator Program using while-loop and if-else&lt;/h4&gt;

&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;

 1. Addition&lt;br /&gt;
 2. Subtraction&lt;br /&gt;
 3. Multiplication&lt;br /&gt;
 4. Division&lt;br /&gt;
 5. exit&lt;br /&gt;
 Enter Choice:1&lt;br /&gt;
 Enter 1st number: 5&lt;br /&gt;
 Enter 2nd number: 6&lt;br /&gt;
 5 + 6 = 11&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;h2&gt;C Program to make Calculator using Switch Case&lt;/h2&gt;&lt;div&gt;Durgesh Kumar gives this code. He was facing a problem with the same program. He was not able to run his last line of code. See in the comment section of this post.&lt;/div&gt;

&lt;p class=&quot;note wr&quot;&gt;When taking a character input, you must write scanf(&quot; %c&quot; &amp;amp;choice);. You have to give a space between &quot; &amp;amp; %.&lt;/p&gt;




&lt;pre class=&quot;prettyprint language-c&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
    int num1, num2, opt;
    char choice;
    // taking the input from the users
    printf(&quot;enter the first integer= &quot;);
    scanf(&quot;%d&quot;, &amp;amp;num1);
    printf(&quot;enter the second integer= &quot;);
    scanf(&quot;%d&quot;, &amp;amp;num2);

    printf(&quot;*****************************&quot;);
    do
    {

        printf(&quot;\n please enter your choice. \n\n 1.Addition\n 2.Subtraction \n 3.Multiplication \n 4.division \n 5.Modulas\n&quot;);
        scanf(&quot;%d&quot;, &amp;amp;opt);
        switch (opt)
        {
        case 1:
            printf(&quot;The addition of %d + %d = %d&quot;, num1, num2, num1 + num2);
            break;
        case 2:
            printf(&quot;the subtraction of %d - %d = %d&quot;, num1, num2, num1 - num2);
            break;
        case 3:
            printf(&quot;The multiplication of %d * %d = %d&quot;, num1, num2, num1 * num2);
            break;
        case 4:
            if (num2 == 0)
            {
                printf(&quot;this number can&#39;t divide by zero\n&quot;);
            }
            else
            {
                printf(&quot;the division of %d / %d = %d&quot;, num1, num2, num1 / num2);
            }
            break;
        case 5:
            if (num2 == 0)
            {
                printf(&quot;we can&#39;t find the remainder&quot;);
            }
            else
            {
                printf(&quot;the remainder of %d % %d = %d&quot;, num1, num2, num1 % num2);
            }
            break;
        default:
            printf(&quot;Please choose the correct option&quot;);
        }

        printf(&quot;\ndo you want to continue? press(y/n)&quot;);
        scanf(&quot; %c&quot;, &amp;amp;choice);
    } while (choice == &#39;y&#39;);
    return 0;
}
&lt;/pre&gt;
&lt;h2&gt;About this calculator program in c using switch case:&lt;/h2&gt;

&lt;div&gt;In conclusion, we have just gone through the different calculator programs in c. It depends on your choice, but I recommend you make this program using a switch case. These types of programs are known as menu-driven programs.&lt;/div&gt;
&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/8798338363785624218/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/02/calculator-program-in-c.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8798338363785624218'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8798338363785624218'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/02/calculator-program-in-c.html' title='Calculator program in C using Switch Case [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEje4mRKMZrIELOFMnNhQGK6HaDIEva-0XXUccu_lCqcjrLk5lERXkeBg6quvvHE3lG-TYGPrrs-M_mgQuwh10tJAOaM3SmLMysPARrAnBuDsdzErZ0XGBqu4_IFU5_lWGsQ2PkvtT3YhWPR6JoQi4OOA8uqpUf5hVOp_57GvsuJO9S2JsSNjJo0z0vL=s72-w640-h583-c" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6148673145792771373</id><published>2022-09-24T19:53:00.003+05:30</published><updated>2022-10-08T10:10:07.703+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Program to Check Even or Odd</title><content type='html'>&lt;p&gt;In this program, we are going to make a python program to check even or odd number.&lt;/p&gt;
&lt;h2&gt;Python Program to Check Even or Odd&lt;/h2&gt;
&lt;div&gt;In this program, we will check whether the number is odd  or even using modulus operator. Modulus operator gives us the remainder between two number.&lt;br /&gt;&lt;br /&gt;If the number is even so it is divisible by 2 so we can check if the number modulus 2 comes out to zero then we will print the given number is even.&lt;br /&gt;&lt;/div&gt;

&lt;pre&gt;number = int(input(&quot;Which number do you want to check? &quot;))

if number%2==0:
    print(f&quot;{number} is an even number.&quot;)
else:
    print(f&quot;{number} is an odd number.&quot;)
&lt;/pre&gt;
&lt;div&gt;
Related Post: &lt;a href=&quot;https://www.codingwithsid.in/2022/04/prime-number-program-in-python.html&quot; target=&quot;_blank&quot;&gt;Prime Number Program in Python using while loop&lt;/a&gt;&lt;/div&gt;

&lt;h2&gt;Video Solution&lt;/h2&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/-SebC5aZlAM&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;h3&gt; Python Example Program to Check if a Number is Even or Odd ( User Input )&lt;/h3&gt;
&lt;pre&gt;number = int(input(&quot;Enter an integer number: &quot;))
remainder=number%2
if remainder==0:
    print(number,&quot; is an even number.&quot;)
else:
    print(number,&quot; is an odd number.&quot;)
&lt;/pre&gt;


&lt;h2&gt;Using bit manipulation&lt;/h2&gt;
&lt;p&gt;Last bit of every odd number is set, so if we perform &quot;&amp;amp;&quot; operation between odd number and 1(whose last bit is set &quot;001&quot;) it comes out to a one otherwise it is zero.

&lt;/p&gt;&lt;pre&gt;number = int(input(&quot;Which number do you want to check? &quot;))

if number&amp;amp;1:
    print(&quot;This is an odd number.&quot;)
else:
    print(&quot;This is an even number.&quot;)
&lt;/pre&gt;

&lt;p&gt;This is all about this post, if you have doubts let me know in the comment section. Please rate well in &lt;a href=&quot;https://www.codingwithsid.in/p/feedback-form.html&quot;&gt;feedback form&lt;/a&gt;.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6148673145792771373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/09/python-program-to-check-even-or-odd.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6148673145792771373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6148673145792771373'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/09/python-program-to-check-even-or-odd.html' title='Python Program to Check Even or Odd'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/-SebC5aZlAM/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-8916906473504707617</id><published>2022-09-17T17:41:00.007+05:30</published><updated>2022-09-19T18:14:34.984+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="striver-sde-sheet"/><title type='text'>Striver SDE Sheet Solutions [Day 1]</title><content type='html'>&lt;p&gt;In this post, we will provide solutions for Day 1 striver sde sheet.
&lt;/p&gt;

&lt;h2&gt;Day 1: Arrays&lt;br /&gt;&lt;/h2&gt;
&lt;h3&gt;1. Set Matrix Zeroes&lt;/h3&gt;

  &lt;pre&gt;  class Solution {
public:
    void setZeroes(vector&amp;lt;vector &amp;lt;int&amp;gt;&amp;gt;&amp;amp; matrix) {
        int r=matrix.size(),c=matrix[0].size();
        vector&amp;lt;int&amp;gt; rows(r,0),cols(c,0);
        
        for(int i=0;i&amp;lt;r;i++)
        {
            for(int j=0;j&amp;lt;c;j++)
            {
                if(matrix[i][j]==0)
                {
                    rows[i]=1;
                    cols[j]=1;
                }
            }
        }
        
        for(int i=0;i&amp;lt;r;i++)
        {
            for(int j=0;j&amp;lt;c;j++)
            {
                if(cols[j]==1||rows[i]==1)
                {
                    matrix[i][j]=0;
                }
            }
        }
        
    }
};
  &lt;/pre&gt;


&lt;h3&gt;2. Pascal&#39;s Triangle&lt;/h3&gt;
&lt;pre&gt;class Solution {
public:
    vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; generate(int numRows) {
        vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt; ans(numRows);
        for(int i=0;i&amp;lt;numRows;i++)
        {
            ans[i].resize(i+1,1);
            for(int j=0;j&amp;lt;=i;j++)
            {
                if(j==0||j==i) continue;
                ans[i][j]=ans[i-1][j-1]+ans[i-1][j];
            }
        }
        return ans;
    }
};
&lt;/pre&gt;






&lt;h2&gt;3. Next Permutation in C++&lt;/h2&gt;
  &lt;p&gt;&amp;nbsp;In this program, we are going to make a c++ program for next permutation.&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhFQYwQVd9p1gtu58ztOjGxcpRbvm4AfyzunTpp7HObQHRq7jFf13CBzaAHkLHbbpBSly7DAJs6vs721aLkKFOm8YDIXHyqmGK8oe3Cq5xXoTE7L0OkARgw1fjUzROuNvPfSdlkramAj2OI3wPqQzfqA8eA5xFcFKr-bQ9z5ruUafufNBKXeilu8QME&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Striver SDE Sheet Solutions [Day 1]&quot; data-original-height=&quot;459&quot; data-original-width=&quot;867&quot; height=&quot;338&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhFQYwQVd9p1gtu58ztOjGxcpRbvm4AfyzunTpp7HObQHRq7jFf13CBzaAHkLHbbpBSly7DAJs6vs721aLkKFOm8YDIXHyqmGK8oe3Cq5xXoTE7L0OkARgw1fjUzROuNvPfSdlkramAj2OI3wPqQzfqA8eA5xFcFKr-bQ9z5ruUafufNBKXeilu8QME=w640-h338&quot; title=&quot;Striver SDE Sheet Solutions [Day 1]&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Credits: &lt;a href=&quot;https://takeuforward.org/interviews/strivers-sde-sheet-top-coding-interview-problems/&quot; target=&quot;_blank&quot;&gt;Striver SDE Sheet&lt;/a&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A man named Narayana Pandita presented the following &lt;a href=&quot;https://leetcode.com/problems/next-permutation/discuss/13867/C%2B%2B-from-Wikipedia&quot; target=&quot;_blank&quot;&gt;algorithm&lt;/a&gt; to solve the next permutation problem&amp;nbsp;in the 14th century.&lt;br /&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Find the largest index &quot;ind&quot; such that nums[ind]&amp;lt;nums[ind+1]. If there is no such index exist just reverse the array and return.&lt;/li&gt;&lt;li&gt;Find the largest index j&amp;gt;ind such that nums[ind]&amp;lt;nums[j].&lt;/li&gt;&lt;li&gt;Swap (nums[ind],nums[j]);&lt;/li&gt;&lt;li&gt;Reverse the subarray on the right side of nums[ind]. {reverse(nums.begin()+ind+1,nums.end());}&lt;/li&gt;&lt;/ol&gt;
&lt;pre&gt;class Solution {
public:
    void nextPermutation(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        int n=nums.size();
        int ind=-1;
        for(int i=n-2;i&amp;gt;=0;i--)
        {
            if(nums[i]&amp;lt;nums[i+1])
            {
                ind=i;
                break;
            }
        }
        
        if(ind==-1) {
            reverse(nums.begin(),nums.end());
            return;
        }
        
        for(int j=n-1;j&amp;gt;ind;j--)
        {
            if(nums[j]&amp;gt;nums[ind])
            {
                swap(nums[j],nums[ind]);
                break;
            }
        }
       reverse(nums.begin()+ind+1,nums.end());
    }
};

&lt;/pre&gt;

&lt;div&gt;In this program, we just coded the algorithm for next permutation given by Narayana Pandita.&lt;/div&gt;

&lt;h3&gt;4. Maximum Subarray&lt;/h3&gt;
&lt;div&gt;In this question, we have to return the &lt;a href=&quot;https://www.codingwithsid.in/2021/10/maximum-subarray-sum-kadane-algorithm.html&quot;&gt;maximum subarray sum&lt;/a&gt;.&lt;/div&gt;
&lt;pre&gt;class Solution {
public:
    int maxSubArray(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        int curr=0,ans=INT_MIN;
        
        for(auto it:nums)
        {
            curr+=it;
            ans=max(ans,curr);
            
            if(curr&amp;lt;0)
                curr=0;
        }
        return ans;
        
    }
};
&lt;/pre&gt;

&lt;h3&gt;5. Sort 0,1 and 2&lt;/h3&gt;

&lt;pre&gt;void sortColors(vector&amp;lt;int&amp;gt;&amp;amp; nums) {
        int i=0,j=0,k=nums.size()-1;
        
        while(j&amp;lt;=k)
        {
            if(nums[j]==1) j++;
            else
                if(nums[j]==0) swap(nums[i++],nums[j++]);
            else
                if(nums[j]==2) swap(nums[k--],nums[j]);
        }
        
    }
&lt;/pre&gt;

&lt;h3&gt;6. Best Time to Buy and Sell Stock&lt;/h3&gt;
&lt;pre&gt;int maxProfit(vector&amp;lt;int&amp;gt;&amp;amp; prices) {
        int mn=prices[0],ans=0;
        
        for(auto it:prices)
        {
            ans=max(ans,it-mn);
            mn=min(it,mn);
        }
        return ans;
    }
&lt;/pre&gt;
&lt;div&gt;I want to update you about the Sale. If you purchase a coding ninjas course today, you shall get a flat 40% discount (30% Early Bird + 10% from my side) on the course.&lt;a href=&quot;https://www.codingninjas.com/?referralCode=LAPRU&quot;&gt;&amp;nbsp;[course]&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/8916906473504707617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/09/striver-sde-sheet-solutions-day-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8916906473504707617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8916906473504707617'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/09/striver-sde-sheet-solutions-day-1.html' title='Striver SDE Sheet Solutions [Day 1]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhFQYwQVd9p1gtu58ztOjGxcpRbvm4AfyzunTpp7HObQHRq7jFf13CBzaAHkLHbbpBSly7DAJs6vs721aLkKFOm8YDIXHyqmGK8oe3Cq5xXoTE7L0OkARgw1fjUzROuNvPfSdlkramAj2OI3wPqQzfqA8eA5xFcFKr-bQ9z5ruUafufNBKXeilu8QME=s72-w640-h338-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-1292957582058488729</id><published>2022-08-25T17:26:00.004+05:30</published><updated>2022-09-15T22:00:14.017+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Giveaway"/><title type='text'>Giveaway of Web Development Bootcamp by Angela Yu</title><content type='html'>&lt;p&gt;In this post, I will share information about the giveaway of web development course by Angela Yu.&lt;br /&gt;&lt;br /&gt;Course: The Complete 2022 Web Development Bootcamp on Udemy&lt;/p&gt;&lt;p&gt;Become a Full-Stack Web Developer with just ONE course. HTML, CSS, JavaScript, Node, React, MongoDB, Web3 and DApps&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvEFJJjOQNDNoLViFV3GAM5hHx4A4BsKpaVoYTrkQwvBJIHP4utu2K6R3sHWV8joNJcJ78UwgktIIPlkZOK7SzDjhJmAbTtBJzvxW_8EG00pwoenJR2EJQHs_Hdgx2t3pNgSkXW4tV3LBxFvNKoLyJ0dIUPUCoocQQJkcGFXCOjiy8upqe_AT5SPaN/s856/The%20Complete%202022%20Web%20Development%20Bootcamp.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;The Complete 2022 Web Development Bootcamp&quot; border=&quot;0&quot; data-original-height=&quot;496&quot; data-original-width=&quot;856&quot; height=&quot;370&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvEFJJjOQNDNoLViFV3GAM5hHx4A4BsKpaVoYTrkQwvBJIHP4utu2K6R3sHWV8joNJcJ78UwgktIIPlkZOK7SzDjhJmAbTtBJzvxW_8EG00pwoenJR2EJQHs_Hdgx2t3pNgSkXW4tV3LBxFvNKoLyJ0dIUPUCoocQQJkcGFXCOjiy8upqe_AT5SPaN/w640-h370/The%20Complete%202022%20Web%20Development%20Bootcamp.png&quot; title=&quot;The Complete 2022 Web Development Bootcamp&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;Steps to take part in this giveaway:&lt;br /&gt;&lt;/p&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Comment below, why do you need this course and your Instagram account.&lt;/li&gt;&lt;li&gt;Follow Our Instagram account: &lt;a href=&quot;https://www.instagram.com/codingwithsid_/&quot; target=&quot;_blank&quot;&gt;CodingwithSid_&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;div&gt;
  Send your giveaway entries at &lt;a href=&quot;https://www.instagram.com/codingwithsid_/&quot;&gt;https://instagram.com/codingwithsid_&lt;/a&gt;. Good luck :)
  
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/1292957582058488729/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/08/giveaway.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/1292957582058488729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/1292957582058488729'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/08/giveaway.html' title='Giveaway of Web Development Bootcamp by Angela Yu'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvEFJJjOQNDNoLViFV3GAM5hHx4A4BsKpaVoYTrkQwvBJIHP4utu2K6R3sHWV8joNJcJ78UwgktIIPlkZOK7SzDjhJmAbTtBJzvxW_8EG00pwoenJR2EJQHs_Hdgx2t3pNgSkXW4tV3LBxFvNKoLyJ0dIUPUCoocQQJkcGFXCOjiy8upqe_AT5SPaN/s72-w640-h370-c/The%20Complete%202022%20Web%20Development%20Bootcamp.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-413014728995334735</id><published>2022-08-04T20:21:00.002+05:30</published><updated>2022-08-04T20:25:04.946+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array"/><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Data-Structures"/><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="if-else"/><title type='text'>Subarray Sum Equals K in Linear Time Complexity [New]</title><content type='html'>&lt;p&gt;In this post, we will make a C++ program to print the total number of subarray sums equals k and another program based on the idea of a cumulative sum.&lt;/p&gt;
&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;br /&gt;

&lt;img alt=&quot;Subarray Sum Equals K&quot; border=&quot;0&quot; data-original-height=&quot;720&quot; data-original-width=&quot;1280&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilVSVONs5dlXkxqLc391USgz9H1LB6w0Tycgu3HUXRLwMrSD9qkcsXCBP31e3ACTN4aApSOBaa-opuzGmo_vi3m5yQa19QxkRJz7Cn9f0ktPoZA4bwx2I0CkQ73_l7VCouiqA8F8b0Rlo/w640-h360/Number+of+Subarrays+having+Sum+Exactly+Equal+to+K.webp&quot; title=&quot;Subarray Sum Equals K&quot; width=&quot;640&quot; /&gt;
&lt;br /&gt;

&lt;h2&gt;Total Number of Subarrays whose Sum Equals k&lt;/h2&gt;
&lt;div&gt;Given an unsorted array of integers, we will find the number of continuous subarrays having a sum exactly equal to a given number k in linear time complexity. We will use hashmap to store prefix sum.&lt;/div&gt;
&lt;p class=&quot;note&quot;&gt;Problem link: &lt;a class=&quot;extL&quot; href=&quot;https://leetcode.com/problems/subarray-sum-equals-k/&quot;&gt;Leetcode&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;int subarraySum(vector&amp;lt;int&amp;gt;&amp;amp; nums, int k) {
        int sum=0,ans=0;
        unordered_map&amp;lt;int,int&amp;gt; mp;
        mp[0] = 1; // we always have 1 sum of zero, which is sum of none.
        for(int i=0;i&amp;lt;nums.size();i++)
        {
            sum+=nums[i];
        
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;// We have x prefix array to create this value. So count is added with the existing combinations
            if(mp.find(sum-k)!=mp.end())
                ans+=mp[sum-k];
            mp[sum]++;
        }
        return ans;
    }
&lt;/pre&gt;


&lt;h2&gt;C++ Program to Print Total Number of Subarrays having Sum Exactly Equal to K&lt;/h2&gt;
&lt;p&gt;In this program, we will make a program that takes an array from the user and Subarray sum(k). We will print the total number of Subarray sums equal to k.&lt;/p&gt;

&lt;blockquote&gt;Time complexity for finding the number of subarrays sum equals k: O( &lt;b&gt;&lt;i&gt;N&lt;/i&gt;&lt;sup&gt;3&lt;/sup&gt;&lt;/b&gt;) &lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;
&lt;br /&gt;&lt;pre class=&quot;prettyprint language-cpp&quot;&gt;#include&amp;lt;iostream&amp;gt;
using namespace std;
int main()
{
    int arr[1000], k, n, ksum, currentsum, count = 0;
    cout&amp;lt;&amp;lt;&quot;\n Enter number of elements:&quot;;
    cin&amp;gt;&amp;gt;n;
    cout&amp;lt;&amp;lt;&quot;\n Enter array elements:&quot;;
    for (int i = 0; i &amp;lt; n; i++)
    {
        cin&amp;gt;&amp;gt;arr[i];
    }
    cout&amp;lt;&amp;lt;&quot;\n Subarray sum equals:&quot;;
    cin&amp;gt;&amp;gt;ksum;
    for (int i=0; i&amp;lt;n; i++)
    {
        for(int j = i; j &amp;lt; n; j++)
        {
            currentsum=0;
            for(int k = i; k &amp;lt;= j; k++)
            {
                currentsum+= arr[k];
            }
            if ( currentsum == ksum)
            count++;
        }
    }
    cout&amp;lt;&amp;lt;&quot;Total no. of subarray sum equals &quot;&amp;lt;&amp;lt;ksum&amp;lt;&amp;lt;&quot; is &quot;;
    cout&amp;lt;&amp;lt;count;
    return 0;
    }
    &lt;/pre&gt;&lt;br /&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter the number of elements:9&lt;br /&gt;
Enter array elements:-4 1 3 -2 6 2 -1 -4 -7&lt;br /&gt;
Subarray sum equals:10&lt;br /&gt;
Total no. of subarray sum equals ten is 1&lt;br /&gt;
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2&gt;Video Solution&lt;/h2&gt;
&lt;div class=&quot;videoYt&quot;&gt;
  &lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; class=&quot;lazy&quot; data-src=&quot;https://www.youtube.com/embed/20v8zSo2v18&quot; title=&quot;Lazy Iframe&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;h2&gt;Program to Print Total number of Subarray Sum equals k using Cumulative Sum&lt;/h2&gt;&lt;div&gt;In the last program, we made a program to print the total number of subarrays with a sum equal to k. In this program, we will make a program based on the idea of cumulative sum, which is slightly more optimized than the previous method. &lt;/div&gt;
&lt;br /&gt;&lt;div&gt;
&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&amp;nbsp;We used three nested loops in the last method, and the processor will do work that is proportional to&amp;nbsp;&lt;b&gt;&lt;i&gt;N&lt;/i&gt;&lt;sup&gt;&amp;nbsp;3&lt;/sup&gt;&lt;/b&gt;. In this program, we will solve the problem of printing the total number of Subarray sums equals K using two nested loops, and the processor will do work proportional to&amp;nbsp;&lt;b&gt;&lt;i&gt;N&lt;/i&gt;&lt;sup&gt;&amp;nbsp;2&lt;/sup&gt;&lt;/b&gt;.&lt;/div&gt;
&lt;div&gt;&lt;blockquote&gt;The time complexity for finding the count of subarrays sum equals k using cumulative sum: O( &lt;b&gt;&lt;i&gt;N&lt;/i&gt;&lt;sup&gt;&amp;nbsp;2&lt;/sup&gt;&lt;/b&gt;)&lt;/blockquote&gt;&lt;br /&gt;
  &lt;pre class=&quot;prettyprint language-cpp&quot;&gt;#include&amp;lt;iostream&amp;gt;
using namespace std;
int main()
{
    int arr[1000], k, n, ksum, currentsum, count = 0,cumulativesum[1000]={0};
    cout&amp;lt;&amp;lt;&quot;\n Enter number of elements:&quot;;
    cin&amp;gt;&amp;gt;n;
    cout&amp;lt;&amp;lt;&quot;\n Enter array elements:&quot;;
    cin&amp;gt;&amp;gt;arr[0];
    cumulativesum[0]=arr[0];
    for (int i = 1; i &amp;lt; n; i++)  
    {
        cin&amp;gt;&amp;gt;arr[i];
        cumulativesum[i] = cumulativesum[i-1] + arr[i];
    }
    cout&amp;lt;&amp;lt;&quot;\n Subarray sum equals:&quot;;
    cin&amp;gt;&amp;gt;ksum;
    for (int i=0; i&amp;lt;n; i++)
    {
        for(int j = i; j &amp;lt; n; j++)
        {
            currentsum=0;
            currentsum = cumulativesum[j] - cumulativesum[i-1];
            if ( currentsum == ksum)
            count++;
        }   
        
    }
    cout&amp;lt;&amp;lt;&quot;Total no. of subarray sum equals &quot;&amp;lt;&amp;lt;ksum&amp;lt;&amp;lt;&quot; is &quot;;
    cout&amp;lt;&amp;lt;count;
    return 0;
    }
    &lt;/pre&gt;
  
&lt;div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Related posts:&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://www.codingwithsid.in/2021/02/menu-driven-program-for-singly-linked-list.html&quot;&gt;Menu Driven Program for Singly Linked List in C++&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/09/menu-driven-program-array-operations-in-cpp.html&quot;&gt;Menu-Driven Program for Array Operations in C++&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/12/binary-tree-traversal.html&quot;&gt;Binary Tree traversal in C++&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;About this post: &lt;/h3&gt;
Siddharth Jha writes this post. In this post, we print the total number of subarrays having a sum equal to k using three nested. In another program, we used the concept of cumulative sum and showed the number of subarray sums equal to k using two nested loops.
&lt;/div&gt;

&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/413014728995334735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/08/subarray-sum-equals-k.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/413014728995334735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/413014728995334735'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/08/subarray-sum-equals-k.html' title='Subarray Sum Equals K in Linear Time Complexity [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilVSVONs5dlXkxqLc391USgz9H1LB6w0Tycgu3HUXRLwMrSD9qkcsXCBP31e3ACTN4aApSOBaa-opuzGmo_vi3m5yQa19QxkRJz7Cn9f0ktPoZA4bwx2I0CkQ73_l7VCouiqA8F8b0Rlo/s72-w640-h360-c/Number+of+Subarrays+having+Sum+Exactly+Equal+to+K.webp" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-5022825445776154515</id><published>2022-07-21T09:37:00.001+05:30</published><updated>2022-09-15T21:54:06.911+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="if-else"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Palindrome Program in C [New]</title><content type='html'>&lt;div&gt;
It is a program to check whether the number is a palindrome or not in the c language. We will make it using for loop, a while loop, and functions.&lt;/div&gt;
  
  &lt;div class=&quot;mbtTOC&quot;&gt;
&lt;ul id=&quot;mbtTOC&quot;&gt;&lt;/ul&gt;
&lt;/div&gt;

&lt;h2&gt;Palindrome program in c using for loop&lt;/h2&gt;
&lt;div&gt;&lt;div&gt;In this program, we will take the input number from the user. We will take another variable which will store the reverse number.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We will take the modulus of the current number by 10, which gives the unit digit of the current number. We will multiply the &quot;reversed number&quot; by ten and add the unit digit. At last, we will divide the current number by 10.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We will do this process till the current number is greater than zero.&lt;/div&gt;&lt;/div&gt;
  &lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;

int main()
{
    int i, n, remainder, rev=0;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;,&amp;amp;n);
    for(i=n;i&amp;gt;0;i=i/10)
    {
        remainder=i%10;&lt;br /&gt;        rev=rev*10+remainder;&lt;br /&gt;    }
    if(rev==n)
        printf(&quot;\n It is a palindrome&quot;);
    else
        printf(&quot;\n It is not a palindrome&quot;);
    return 0;
}&lt;/pre&gt;
  &lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Palindrome program in c using for loop&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;178&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlrdM46Xp2VbC1gJFg6vfVJmTIsjmwZxToXr-cYWGQ0ViwDquRKxntsapNcSHIoYFc_TN5sIg_P_KagLEEoh7aj1OR5wKotg5P9gj17vbq9YCsZgfQEbSy3U7B_Sr0lwKJa4OAvIuZwjk/w320-h178/Palindrome+program+in+c.png&quot; title=&quot;Palindrome program in c using for loop&quot; width=&quot;320&quot; /&gt;&lt;/div&gt;&lt;h2&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Palindrome program in c using while loop&lt;/h2&gt;

&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;


int main()
{
    int i, n, r, s = 0;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;, &amp;amp;n);
    i = n;
    while (i &amp;gt; 0)
    {
        r = i % 10;
        s = (s * 10) + r;
        i = i / 10;
    }
    
    if (s == n)
        printf(&quot;\n It is a palindrome&quot;);
    else
        printf(&quot;\n It is not a palindrome&quot;);
    return 0;
}

&lt;/pre&gt;
  
  
&lt;h2&gt;Palindrome program in c using functions&lt;/h2&gt;

&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
int palindrome(int a);
int main()
{
    int b, c;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;, &amp;amp;b);
    c = b;
    c = palindrome(c);
    if (b == c)
        printf(&quot;%d is a palindrome&quot;, b);
    else
        printf(&quot;%d is not a palindrome&quot;, b);
    return 0;
}
int palindrome(int a)
{
    int i, r, s = 0;
    i = a;
    while (i &amp;gt; 0)
    {
        r = i % 10;
        s = (s * 10) + r;
        i = i / 10;
    }
    return s;
}

&lt;/pre&gt;


&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
Output: &lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/#&quot;&gt;&lt;img alt=&quot;Palindrome program in c using functions&quot; border=&quot;0&quot; height=&quot;180&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5yLC645Wg92i_A9EXfwZWkTHq3s6PPkEIwHQRK_OBF8m8f-grpt4LFW_mJQc1XOuOvVZyE9RGNkaCvqvd5Adq4rWsYP-QqpgsMgoiJbvsthQ1XZb0y_4US6BdYCSo4BYbqCDAz6FQLvo/w320-h180/Screenshot+%252855%2529.png&quot; title=&quot;Palindrome program in c using functions&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;   &lt;b&gt;Q. How do You Check if a number is a palindrome?&lt;/b&gt; &lt;br /&gt;&lt;div&gt;To check palindrome, we have to check its reverse should also equal to it.&lt;/div&gt;&lt;div&gt;For example:7227 is a palindrome as its reverse is also 7227.&lt;/div&gt; 
  
  
  &lt;br /&gt;&lt;div&gt;&lt;b&gt;Q. What is the palindrome program in c?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;To make a palindrome program, we have to compare its reverse with the number entered by the user, and if its reverse is equal to the original number (number entered by the user), then it is a palindrome.&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Q. How do you write a palindrome program?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;First, we input a number by the user, then reverse it. At last, we compare the number entered by the user with its reverse if they are identical. We print the number entered by the user as a palindrome &amp;amp; if they are not identical, then we print the number entered by the user as not a palindrome.&lt;/div&gt;



&lt;br /&gt;
&lt;div&gt; Related Posts:&lt;br /&gt;
&lt;a href=&quot;https://www.codingwithsid.in/2020/02/find-greatest-number-in-c.html&quot; target=&quot;_blank&quot;&gt;C program to find the greatest number among three numbers&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.codingwithsid.in/2020/05/odd-and-even-numbers-program-in-c.html&quot; target=&quot;_blank&quot;&gt;Odd and even number program in c&lt;/a&gt;
&lt;/div&gt;
&lt;br /&gt;

  
  &lt;h3&gt;About this blog post&lt;/h3&gt;
  &lt;div&gt;&lt;div&gt;This program is brought to you by Coding Wallah. If you like this program or if this code works on your laptop/PC, comment below and share your experience.&lt;/div&gt;&lt;div&gt;Thanks for reading this blog post. I hope you enjoy this program as much as I enjoy offering them to you. If you have any questions or queries about this program, please do not hesitate to comment below or contact me.&lt;/div&gt;&lt;/div&gt;
&lt;script&gt;mbtTOC();&lt;/script&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/5022825445776154515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/03/palindrome-program-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5022825445776154515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/5022825445776154515'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/03/palindrome-program-in-c.html' title='Palindrome Program in C [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlrdM46Xp2VbC1gJFg6vfVJmTIsjmwZxToXr-cYWGQ0ViwDquRKxntsapNcSHIoYFc_TN5sIg_P_KagLEEoh7aj1OR5wKotg5P9gj17vbq9YCsZgfQEbSy3U7B_Sr0lwKJa4OAvIuZwjk/s72-w320-h178-c/Palindrome+program+in+c.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6678953102751604473</id><published>2022-07-20T14:59:00.000+05:30</published><updated>2022-07-20T14:59:24.517+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><title type='text'>String Palindrome Program in C using for loop [New]</title><content type='html'>&lt;div&gt;In this post, we will make a String Palindrome Program in C using for loop. We will check whether the given string is palindrome or not.&lt;/div&gt;
&lt;h2&gt;String Palindrome Program in C using for loop&lt;/h2&gt;
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
int main()
{

    char str[30];
    int n = 0, flag = 0, i = 0, j = 0;
    printf(&quot;Enter String:&quot;);
    scanf(&quot;%s&quot;, &amp;amp;str);
    n = strlen(str);
    for (i = 0, j = n - 1; i &amp;lt;= j; i++, j--)
    {
        if (str[i] != str[j])
        {
            flag = 1;
            break;
        }
    }

    if (flag == 1)
        printf(&quot;No, it is not a palindrome&quot;);
    else
        printf(&quot;Yes, it is a palindrome&quot;);

    return 0;
}


&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter String: saippuakivikauppias&lt;br /&gt;
Yes, it is a palindrome&lt;br /&gt;

&lt;br /&gt;
Enter String: codingwithsid&lt;br /&gt;
No, it is not a palindrome&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJs1oxlPr2GTxsJ4FsRB2LVeI3PfXCjB5ZVT0LThzLzLYv7YlQAFjMddPITx846X_nwUAZqMzlT_Qeqot32JPsTFUb6N94dHyKGTZgCKuN-dbqsKhCyK8W45KTssez2pXC5MjeczUSjZnE2phiJFrtH6eVhal422ZwTPmETACcpx0dL3VL-OFr1rk9/s630/String%20Palindrome%20Program%20in%20C%20using%20for%20loop.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;
  
  &lt;img alt=&quot;String Palindrome Program in C using for loop&quot; border=&quot;0&quot; data-original-height=&quot;543&quot; data-original-width=&quot;630&quot; height=&quot;276&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJs1oxlPr2GTxsJ4FsRB2LVeI3PfXCjB5ZVT0LThzLzLYv7YlQAFjMddPITx846X_nwUAZqMzlT_Qeqot32JPsTFUb6N94dHyKGTZgCKuN-dbqsKhCyK8W45KTssez2pXC5MjeczUSjZnE2phiJFrtH6eVhal422ZwTPmETACcpx0dL3VL-OFr1rk9/w320-h276/String%20Palindrome%20Program%20in%20C%20using%20for%20loop.png&quot; title=&quot;String Palindrome Program in C using for loop&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h2&gt;Approach for Palindrome Program in C&lt;/h2&gt;
&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;/li&gt;&lt;li&gt;Input string from user and store it in a character array.&lt;/li&gt;&lt;li&gt;Using for loop, we compare the corresponding elements of the character array. For this, we use the following statement.&lt;br /&gt;&lt;div style=&quot;text-align: center;&quot;&gt;str[i]==str[j];&lt;/div&gt;&lt;/li&gt;&lt;li&gt;We will compare the first letter with the last letter, and second letter with the last-second letter and so on.&lt;/li&gt;&lt;li&gt;If they mismatch, we break the loop and mark the flag with one.&lt;/li&gt;&lt;li&gt;Now, if the flag&#39;s value is one, we will print it is not a palindrome; otherwise, the given string is a palindrome.&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
&lt;h2&gt;C program to check whether the string is palindrome or not using while loop&lt;/h2&gt;
&lt;div&gt;In this program, we will check whether the given string is palindrome or not.&lt;/div&gt;
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;
int main()
{

    char str[30];
    int n = 0, isPalindrome = 1, i = 0, j;
    printf(&quot;Enter String:&quot;);
    scanf(&quot;%s&quot;, &amp;amp;str);
    n = strlen(str);
    j=n-1;
    while(i&amp;lt;j)
    {
        if(str[i]!=str[j])
        {
            isPalindrome=0;
            break;   
        }
        i++;
        j--;
    }

    if (isPalindrome == 0)
        printf(&quot;%s is not a palindrome&quot;,str);
    else
        printf(&quot;%s is a palindrome&quot;,str);

    return 0;
}
&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter String: racecar&lt;br /&gt;
racecar is a palindrome&lt;br /&gt;

&lt;br /&gt;
Enter String: souravjoshi&lt;br /&gt;
souravjoshi is not a palindrome&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/KibncdTmnSQ&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;br /&gt;&lt;b&gt;&lt;br /&gt;How do you check if a String is a palindrome in c? &lt;/b&gt;&lt;br /&gt; To check whether the string is a palindrome or not, you can use a&amp;nbsp; for loop statement which is given below&lt;br /&gt;
&lt;pre&gt;for (i = 0, j = n - 1; i &amp;lt;= j; i++, j--)
    {
        if (str[i] != str[j])
        {
            flag = 1;
            break;
        }
    }

&lt;/pre&gt;
Where n is the size of the string entered by the user, the above code compares its first, last value, and other array elements to their corresponding elements. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;What is a palindrome string example? &lt;/b&gt;&lt;br /&gt; Madam &lt;br /&gt; c[0]=c[4]; c[1]=c[3]; c[2]=c[2]; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;b&gt;What is the palindrome program in c? &lt;/b&gt;&lt;br /&gt;&lt;div&gt;It is a program to check whether the number is a palindrome.&lt;/div&gt;&lt;div&gt;To check palindrome, we have to check its reverse should also equal it.&lt;/div&gt; for example:7227 is a palindrome as its reverse is also 7227


&lt;div&gt;check out this post- &lt;a href=&quot;https://www.codingwithsid.in/2020/03/palindrome-program-in-c.html&quot;&gt;palindrome program&amp;nbsp;in c&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Thanks for reading the String Palindrome Program in C, and if you have any queries, you can comment below and contact us on our Instagram account.&lt;div&gt;Related posts:&lt;/div&gt;
  &lt;ul&gt;
    
&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/03/palindrome-program-in-c.html&quot;&gt;Program to print whether the number is palindrome or not in the c language.&lt;/a&gt;&lt;/li&gt;
    
&lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/02/factorial-program-in-c-using-for-loop.html&quot;&gt;Program to print the factorial of a number in c language&lt;/a&gt;.&lt;/li&gt;
  &lt;/ul&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6678953102751604473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/03/string-palindrome-program-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6678953102751604473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6678953102751604473'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/03/string-palindrome-program-in-c.html' title='String Palindrome Program in C using for loop [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJs1oxlPr2GTxsJ4FsRB2LVeI3PfXCjB5ZVT0LThzLzLYv7YlQAFjMddPITx846X_nwUAZqMzlT_Qeqot32JPsTFUb6N94dHyKGTZgCKuN-dbqsKhCyK8W45KTssez2pXC5MjeczUSjZnE2phiJFrtH6eVhal422ZwTPmETACcpx0dL3VL-OFr1rk9/s72-w320-h276-c/String%20Palindrome%20Program%20in%20C%20using%20for%20loop.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6515923134003778757</id><published>2022-07-18T17:43:00.001+05:30</published><updated>2022-07-19T19:16:16.964+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hackerrank-Solution"/><category scheme="http://www.blogger.com/atom/ns#" term="Linked-Lists"/><title type='text'>Reverse a Linked List using Recursion in C++ [New]</title><content type='html'>&lt;p&gt;&amp;nbsp;In this program, we will reverse a linked list using recursion. Whenever you solve a problem using recursion, then please think about the following things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;b&gt;Base Case: &lt;/b&gt;It is an essential step for recursion. Without this statement, your code will not stop, and the compiler will give &lt;i&gt;segmentation fault&lt;/i&gt;. To write a base case, you must consider the &lt;b&gt;smallest valid input&lt;/b&gt;.&lt;/li&gt;&lt;br /&gt;
  &lt;li&gt;&lt;b&gt;Induction Hypothesis:&lt;/b&gt;&amp;nbsp;Induction Hypothesis: Call your &lt;b&gt;recursive function&lt;/b&gt; and assume it will perform its operation. For reverse(head-&amp;gt;next), it will reverse the linked list from the next node and return the new head of the reversed link list.&lt;/li&gt;&lt;br /&gt;
  &lt;li&gt;&lt;b&gt;Induction Step: &lt;/b&gt;In this step, we write the &lt;i&gt;logic&lt;/i&gt; of our recursive function. In short, we decide on this step.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhL65h3kEM-5Zmld-3h5MjZHp4H5LZJ9BAWxF4aCd7eIQLG1QHs6mC9PHWyAPtmVkz0dqgVDJnGUZ5__d4SnfW55lLaBqhIiQZArcHH9NhZqktwqMGebahuCB0T-YPkXprfePnH1EPmG_NE4PcB2QVRzjc2US9A3mUcvSNsQtyJ6e74P5xWEJHNI89X=s498&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Reverse a Linked List using Recursion in C++&quot; border=&quot;0&quot; data-original-height=&quot;211&quot; data-original-width=&quot;498&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhL65h3kEM-5Zmld-3h5MjZHp4H5LZJ9BAWxF4aCd7eIQLG1QHs6mC9PHWyAPtmVkz0dqgVDJnGUZ5__d4SnfW55lLaBqhIiQZArcHH9NhZqktwqMGebahuCB0T-YPkXprfePnH1EPmG_NE4PcB2QVRzjc2US9A3mUcvSNsQtyJ6e74P5xWEJHNI89X=w320-h136&quot; title=&quot;Reverse a Linked List using Recursion&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;

&lt;/ol&gt;
&lt;div&gt;Pre-requisite:&lt;a href=&quot;https://www.codingwithsid.in/2020/12/linked-lists-data-structure.html&quot;&gt; Linked Lists Data Structure in C++&lt;/a&gt;&lt;/div&gt;
&lt;h2&gt;Reverse a Linked List using Recursion in C++&lt;/h2&gt;
&lt;p&gt;In this program, our base case is when the linked list has only one node. In this case, we have to return that node. Then, we call our recursive function to reverse the remaining linked list.&lt;/p&gt; &lt;p&gt;At the decision step, the Next node of the head should point to our current head node. Our current node will point to NULL. At last, we return that node we get from our recursive function.&lt;/p&gt;
&lt;pre class=&quot;prettyprint language-cpp&quot;&gt;node * reverseRecursion(node * head)
{
    if(head-&amp;gt;next==NULL)
    return head;
    node * temp=reverseRecursion(head-&amp;gt;next);
    head-&amp;gt;next-&amp;gt;next=head;
    head-&amp;gt;next=NULL;
    return temp;
}

&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Before: 1-&amp;gt;2-&amp;gt;3-&amp;gt;4-&amp;gt;5-&amp;gt;6&lt;br /&gt;
After: 6-&amp;gt;5-&amp;gt;4-&amp;gt;3-&amp;gt;2-&amp;gt;1&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
  
&lt;/div&gt;

&lt;h2&gt;Video Solution for Reversing linked list recursively&lt;/h2&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/ugQ2DVJJroc&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;

&lt;h2&gt;C++ Program to reverse a linked list&lt;/h2&gt;&lt;div&gt;In this example, we create a linked list from an array. The following program consists of the following functions:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;b&gt;Create&lt;/b&gt;: This function makes a linked list from the given array.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Display&lt;/b&gt;: It is used to print our linked list.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Reverse&lt;/b&gt;: In this function, we &lt;a href=&quot;https://www.codingwithsid.in/2021/03/reverse-linked-list-hackerrank-solution.html&quot;&gt;reverse the linked list&lt;/a&gt; and return the tail of the linked list.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;
&lt;pre class=&quot;prettyprint language-cpp&quot;&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
struct node
{
	int data;
	node* next;
}*first,*last;
void create(int arr[],int n)
{
	int i;
	node *t,*last;
	first = new node();
	first-&amp;gt;data=arr[0];
	first-&amp;gt;next=NULL;
	last=first;
	for(i=1;i&amp;lt;n;i++)
	{
		t=new node();
		t-&amp;gt;data=arr[i];
		t-&amp;gt;next=NULL;
		last-&amp;gt;next=t;
		last=t;
	}
}
void display(node *head)&lt;br /&gt;{&lt;br /&gt; while(head-&amp;gt;next!=NULL)&lt;br /&gt; {&lt;br /&gt; cout&amp;lt;&amp;lt;head-&amp;gt;data&amp;lt;&amp;lt;&quot;-&amp;gt;&quot;;&lt;br /&gt; head=head-&amp;gt;next;&lt;br /&gt; }&lt;br /&gt; cout&amp;lt;&amp;lt;head-&amp;gt;data&amp;lt;&amp;lt;endl;&lt;br /&gt;}

void reverse(node * &amp;amp;head)
{
	node *r=NULL,*q=NULL,*p=head;
	while(p)
	{
		r=q;
		q=p;
		p=p-&amp;gt;next;
		q-&amp;gt;next=r;
	}
	head=q;
}

node * reverseRecursion(node * head)
{
    if(head-&amp;gt;next==NULL)
    return head;
    node * temp=reverseRecursion(head-&amp;gt;next);
    head-&amp;gt;next-&amp;gt;next=head;
    head-&amp;gt;next=NULL;
    return temp;
}


int main()
{
	int arr[]={1,2,3,4,5,6};
	int n=sizeof(arr)/sizeof(int);
	create(arr,n);
	display(first);
    first=reverseRecursion(first);
    display(first);
	return 0;
}

&lt;/pre&gt;
&lt;h2&gt;About this Program&lt;/h2&gt;
&lt;p&gt;In conclusion, we reversed a Linked List using recursion in c++. Ask your doubts in the comment section. Your feedbacks are significant for us; please tell us how we can improve in the comment section.&lt;/p&gt;



</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6515923134003778757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/01/reverse-linked-list-using-recursion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6515923134003778757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6515923134003778757'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/01/reverse-linked-list-using-recursion.html' title='Reverse a Linked List using Recursion in C++ [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEhL65h3kEM-5Zmld-3h5MjZHp4H5LZJ9BAWxF4aCd7eIQLG1QHs6mC9PHWyAPtmVkz0dqgVDJnGUZ5__d4SnfW55lLaBqhIiQZArcHH9NhZqktwqMGebahuCB0T-YPkXprfePnH1EPmG_NE4PcB2QVRzjc2US9A3mUcvSNsQtyJ6e74P5xWEJHNI89X=s72-w320-h136-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-255961901083154911</id><published>2022-07-14T19:00:00.003+05:30</published><updated>2022-07-29T10:54:38.957+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><title type='text'>C Program for Multiplication of Matrix using 2D array [New]</title><content type='html'>
&lt;p&gt; In this C Program for Multiplication of Matrix using the 2D array, we will multiply two matrices A and B, e.g., C=A*B; then, we print matrix C. &lt;br /&gt;&lt;br /&gt;The number of columns of matrix A should equal the number of rows of matrix B. We are making a c program for the multiplication of square matrices.&lt;/p&gt;
&lt;br&gt;
&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;


   
&lt;h2&gt;Multiplication of Matrices in C using 2D array&lt;/h2&gt;
&lt;script async src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4466619634374852&quot;
     crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;!-- Ads Above code --&gt;
&lt;ins class=&quot;adsbygoogle&quot;
     style=&quot;display:block&quot;
     data-ad-client=&quot;ca-pub-4466619634374852&quot;
     data-ad-slot=&quot;5334517657&quot;
     data-ad-format=&quot;auto&quot;
     data-full-width-responsive=&quot;true&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int C[10][10], A[10][10], B[10][10], i, j, l, row, col;
    printf(&quot;Enter the number of rows (1-5): &quot;);
    scanf(&quot;%d&quot;, &amp;amp;row);
    printf(&quot;Enter the number of columns (1-5): &quot;);
    scanf(&quot;%d&quot;, &amp;amp;col);
    printf(&quot;\n Matrix A\n&quot;);
    printf(&quot;\n Enter element you want to insert in the matrix A:\n&quot;);
    for (i = 0; i &amp;lt; row; i++)
    {
        for (j = 0; j &amp;lt; col; j++)
        {
            printf(&quot;\t&quot;);
            scanf(&quot;%d&quot;, &amp;amp;A[i][j]);
        }
    }
    printf(&quot;\n Matrix A:\n&quot;);
    for (i = 0; i &amp;lt; row; i++)
    {
        for (j = 0; j &amp;lt; col; j++)
        {
            printf(&quot;%d&quot;, A[i][j]);
            printf(&quot;\t&quot;);
        }
        printf(&quot;\n&quot;);
    }
    printf(&quot;\n\n Matrix B&quot;);
    printf(&quot;\n Enter element you want to insert in the matrix B:\n&quot;);
    for (i = 0; i &amp;lt; row; i++)
    {
        for (j = 0; j &amp;lt; col; j++)
        {
            printf(&quot;\t&quot;);
            scanf(&quot;%d&quot;, &amp;amp;B[i][j]);
        }
    }
    printf(&quot;\n Matrix B:\n&quot;);
    for (i = 0; i &amp;lt; row; i++)
    {
        for (j = 0; j &amp;lt; col; j++)
        {
            printf(&quot;%d&quot;, B[i][j]);
            printf(&quot;\t&quot;);
        }
        printf(&quot;\n&quot;);
    }
    printf(&quot;\n A*B=\n&quot;);
    for (i = 0; i &amp;lt; row; i++)
    {
        for (j = 0; j &amp;lt; row; j++)
        {
            C[i][j] = 0;
            for (l = 0; l &amp;lt; col; l++)
            {
                C[i][j] = C[i][j] + A[i][l] * B[l][j];
            }
            printf(&quot;%d&quot;, C[i][j]);
            printf(&quot;\t&quot;);
        }
        printf(&quot;\n&quot;);
    }
    return 0;
}
&lt;/pre&gt;
&lt;h2&gt;Video Solution for Matrix Multiplication in C&lt;/h2&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; alt=&quot;Matrix Multiplication in C&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/7QX_vwJMsL0&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;div&gt;Output for Multiplication of Matrices in c using for loop:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;

Enter the number of rows (1-5): 2&lt;br /&gt;
Enter the number of columns (1-5): 2&lt;br /&gt;

 Matrix A &lt;br /&gt;

 Enter element you want to insert in the matrix A:&lt;br /&gt;
        1&lt;br /&gt;
        2&lt;br /&gt;
        3&lt;br /&gt;
        4&lt;br /&gt;

 Matrix A:&lt;br /&gt;
1       2&lt;br /&gt;
3       4&lt;br /&gt;


 Matrix B&lt;br /&gt;
 Enter element you want to insert in the matrix B:&lt;br /&gt;
        5&lt;br /&gt;
        6&lt;br /&gt;
        7&lt;br /&gt;
        8&lt;br /&gt;

 Matrix B:&lt;br /&gt;
5       6&lt;br /&gt;
7       8&lt;br /&gt;

 A*B=&lt;br /&gt;
19      22&lt;br /&gt;
43      50&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Matrix Multiplication in C++ using for loop&lt;/h2&gt;
&lt;p&gt;It is a c++ program for matrix multiplication. We will take input from the user for both the matrices&#39; rows and columns.&lt;/p&gt;
&lt;pre&gt;#include&amp;lt;iostream&amp;gt;
using namespace std;
int main()
{
    int row1, col1;
    cout&amp;lt;&amp;lt;&quot;Enter the number of rows of Matrix A: \n&quot;;
    cin&amp;gt;&amp;gt;row1;
    cout&amp;lt;&amp;lt;&quot;Enter the number of columns of Matrix A: \n&quot;;
    cin&amp;gt;&amp;gt;col1;

    int A[row1][col1];
    cout&amp;lt;&amp;lt;&quot;\n Matrix A\n\n&quot;;
    cout&amp;lt;&amp;lt;&quot;\n Enter element you want to insert in the matrix A:\n\n&quot;;
    for (int i = 0; i &amp;lt; row1; i++)
    {
        for (int j = 0; j &amp;lt; col1; j++)
        {            
            
            cin&amp;gt;&amp;gt;A[i][j];
        }
    }
   
    int row2, col2;
    cout&amp;lt;&amp;lt;&quot;Enter the number of rows of Matrix B: \n&quot;;
    cin&amp;gt;&amp;gt;row2;
    cout&amp;lt;&amp;lt;&quot;Enter the number of columns of Matrix B: \n&quot;;
    cin&amp;gt;&amp;gt;col2;

    int B[row2][col2];
    cout&amp;lt;&amp;lt;&quot;\n Matrix B\n\n&quot;;
    cout&amp;lt;&amp;lt;&quot;\n Enter element you want to insert in the matrix B:\n\n&quot;;
    for (int i = 0; i &amp;lt; row2; i++)
    {
        for (int j = 0; j &amp;lt; col2; j++)
        {            
            
            cin&amp;gt;&amp;gt;B[i][j];
        }
    }
    
    if(col1!=row2)
    {
        exit(0);
    }

    int C[row1][col2];
    cout&amp;lt;&amp;lt;&quot;\n A*B=\n\n&quot;;
    for (int i = 0; i &amp;lt; row1; i++)
    {
        for (int j = 0; j &amp;lt; row1; j++)
        {
            C[i][j] = 0;
            for (int l = 0; l &amp;lt; col2; l++)
            {
                C[i][j] = C[i][j] + A[i][l] * B[l][j];
            }
            cout&amp;lt;&amp;lt;C[i][j]&amp;lt;&amp;lt;&quot; &quot;;
            
        }
        cout&amp;lt;&amp;lt;&quot;\n&quot;;
    }
    return 0;
}

&lt;/pre&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhqL_pTxng4wM4XcKzWFLoa5lT77ywOBsyFOECofI75iYcaW67hLbc_O-3LgynWoZAQqXF3TVobh5zrREYyaiVr-gEv_WIAsbJetwZjAXgemdYB_F1EFWBnkYPJhFsZjy-PyPXCL5aHEPK6-Ve1SoG6uEZ7YAOi6ejk6H7BjLwmrzKfsqq4jP717pwX=s273&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;multiplication of matrices in c&quot; border=&quot;0&quot; data-original-height=&quot;273&quot; data-original-width=&quot;265&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhqL_pTxng4wM4XcKzWFLoa5lT77ywOBsyFOECofI75iYcaW67hLbc_O-3LgynWoZAQqXF3TVobh5zrREYyaiVr-gEv_WIAsbJetwZjAXgemdYB_F1EFWBnkYPJhFsZjy-PyPXCL5aHEPK6-Ve1SoG6uEZ7YAOi6ejk6H7BjLwmrzKfsqq4jP717pwX=s16000&quot; title=&quot;multiplication of matrices in c&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;Approach for Multiplication of two matrices in C using 2D array:&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Using Nested for loop, we initialize array elements in two matrices, A &amp;amp; B.&lt;/li&gt;&lt;li&gt;Using Nested for loop, we print all the elements of matrices entered by the user on the screen.&lt;/li&gt;&lt;li&gt;Using Nested for loop, we multiply two matrices. For this we use the following statement: C[i][j]= C[i][j]+A[i][l]*B[l][j];&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
  Programs you must like:&lt;/div&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/06/C-program-to-print-numbers-using-for-loop.html&quot;&gt;C program to print numbers using for loop &lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/03/matrix-program-in-c-using-array.html&quot;&gt;Matrix program in c using array&lt;/a&gt; &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/06/menu-driven-program-in-c.html&quot;&gt;Menu-driven program in c&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
  
&lt;p&gt;&lt;b&gt;About this C Program:&lt;/b&gt;&lt;br /&gt; Siddharth Jha writes this program. If you have any doubts regarding the multiplication of matrices in c, let me know in the comment section.&lt;/p&gt;

&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/255961901083154911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2021/01/c-program-for-multiplication-of-matrix.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/255961901083154911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/255961901083154911'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2021/01/c-program-for-multiplication-of-matrix.html' title='C Program for Multiplication of Matrix using 2D array [New]'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/7QX_vwJMsL0/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-4974856412693101313</id><published>2022-06-27T01:09:00.009+05:30</published><updated>2022-11-08T20:04:43.249+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="do-while-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="for-loop"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Prime Number Program in C using for loop</title><content type='html'>&lt;div&gt;In this post, we will make the Prime number program in c. It will help us to check whether the number is prime or not.&lt;/div&gt;

  &lt;br /&gt;
&lt;div&gt;&lt;div&gt;&lt;b&gt;Prime number: &lt;/b&gt;A number not divisible by any other number except one is called a prime number.&lt;/div&gt;&lt;div&gt;E.g. 2,3,5,7,11 etc.&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;

&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;

&lt;h2&gt;Prime number&amp;nbsp;program in C using for loop&lt;/h2&gt;
&lt;p&gt; In this program, we have used a function to check the Prime number in C. Return type of this function is bool type.&amp;nbsp;&lt;/p&gt;&lt;p&gt;It will return true if the number is prime and false if it is not.&lt;/p&gt;&lt;p&gt;In the &quot;isPrime&quot; function, we checked that this number is divisible by any number smaller than or equal to the square root of this number &quot;n&quot; using for loop.&lt;/p&gt;&lt;p&gt;The &lt;strong&gt;Time complexity&lt;/strong&gt; of this program is O(sqrt(n)).[Because we are running a loop from 2 to the square root of n]&lt;/p&gt; 
&lt;script async=&quot;&quot; crossorigin=&quot;anonymous&quot; src=&quot;https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4466619634374852&quot;&gt;&lt;/script&gt;
&lt;!--Ads Above code--&gt;
&lt;ins class=&quot;adsbygoogle&quot; data-ad-client=&quot;ca-pub-4466619634374852&quot; data-ad-format=&quot;auto&quot; data-ad-slot=&quot;5334517657&quot; data-full-width-responsive=&quot;true&quot; style=&quot;display: block;&quot;&gt;&lt;/ins&gt;
&lt;script&gt;
     (adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;

&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;stdbool.h&amp;gt;
bool isPrime(int n){
    if(n==1)
    return false;
    //for loop
    for(int i=2;i*i&amp;lt;=n;i++){
        if(n%i==0)
        return false;
    }
    return true;
}
int main() {
    int n;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;,&amp;amp;n);
    if(isPrime(n)==1)
        printf(&quot;\n %d is a Prime Number&quot;,n);
    else
        printf(&quot;\n %d is not a Prime Number&quot;,n);
    return 0;
}
&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter a number:573&lt;br /&gt;
573 is not a Prime Number&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div&gt;&lt;div&gt;If you cannot run this program or get an error, let me know in the comment section.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you need more optimized code for this topic, You can message us on our &lt;a href=&quot;https://www.instagram.com/codingwithsid_/&quot;&gt;Instagram account&lt;/a&gt;. We will send you a meet link on Instagram and teach you every line of code for free of cost.&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;

  &lt;h2&gt;Video Solution to Check Prime number in C using for loop&lt;/h2&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/8zILkPnpD6E&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;h2&gt;Prime number program in c using while loop&lt;/h2&gt;
&lt;div&gt;In this program, we will check whether the number is prime or not using a while loop.&lt;/div&gt;
 
&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
int main()
{
    int num,i=2;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;,&amp;amp;num);
    while(i&amp;lt;num)
    {
        if(num%i==0)
            break;
        i++;
    }
    if(i==num)
        printf(&quot;\n %d is a Prime Number&quot;,num);
    else
        printf(&quot;\n %d is not a Prime Number&quot;,num);
    return 0;
}
&lt;/pre&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
  
  &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxJmfW-pEHfmK3zPAqa4jkzfrQP_f1knlQqTH_wtVuMVQ3tEuG3iGQLUgImB_qUDKRJR88fWdmCQCXKQR5SEy4G5YqVqc-DjOcJnDrpfXOhib-tmXb0elZsWKdbQQ-4UySmV_W_sGhOKGLrG4ehqvRgwmzLwPcf5ZpN3BiexEE3lioOeyl7SuJe4Yv/s925/Prime%20Number%20Program%20in%20C%20using%20while%20loop.webp&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;
  
  &lt;img alt=&quot;Prime number program in c using while loop&quot; border=&quot;0&quot; data-original-height=&quot;516&quot; data-original-width=&quot;925&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxJmfW-pEHfmK3zPAqa4jkzfrQP_f1knlQqTH_wtVuMVQ3tEuG3iGQLUgImB_qUDKRJR88fWdmCQCXKQR5SEy4G5YqVqc-DjOcJnDrpfXOhib-tmXb0elZsWKdbQQ-4UySmV_W_sGhOKGLrG4ehqvRgwmzLwPcf5ZpN3BiexEE3lioOeyl7SuJe4Yv/w640-h358/Prime%20Number%20Program%20in%20C%20using%20while%20loop.webp&quot; title=&quot;Prime number program in c using while loop&quot; width=&quot;640&quot; /&gt;
  
  
  &lt;/a&gt;&lt;/div&gt;


&lt;h3&gt;Approach to check number entered by the user is a prime number or not using the while loop:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;We will declare two integer numbers one is num, and another is i.&lt;/li&gt;&lt;li&gt;We will initialize &quot;i&quot; with two, and the user enters the value of num.&lt;/li&gt;&lt;li&gt;In a while loop, we will perform num modulus &quot;i&quot; where i is less than num.&amp;nbsp;&amp;nbsp;&lt;/li&gt;&lt;li&gt;If num%i comes to zero, it means that the number entered by the user is not a prime number.&lt;/li&gt;&lt;li&gt;If the value of num is equal to &quot;i&quot; then it is a prime number.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;
  
  
  
  &lt;h2&gt;C program to check whether a number is prime or not using a do-while loop&lt;/h2&gt;
  
&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;

int main()
{
    int num,i=2;
    printf(&quot;\n Enter a number:&quot;);
    scanf(&quot;%d&quot;,&amp;amp;num);
    do
    {
        if(num%i==0)
        {
            break;
        }
        i++;
    }while(i&amp;lt;num);
    if(i==num)
        printf(&quot;\n %d is a prime number&quot;,num);
    else
         printf(&quot;\n %d is not a prime number&quot;,num);

    return 0;
}
&lt;/pre&gt;
  
  &lt;h3&gt;Approach to determine whether the number is prime or not using a do-while loop:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;We declare an integer number and initialize its value from the user.&lt;/li&gt;&lt;li&gt;We are using a do-while loop to check whether the number is prime or not.&lt;/li&gt;&lt;li&gt;Use the if statement and modulus operator (it gives the remainder when we divide two numbers) to compare the remainder with zero; if the remainder comes to zero, the number is divisible by another number. Hence, it is not a prime number because it is divisible by another number.&amp;nbsp;&lt;/li&gt;&lt;li&gt;We print it is not the prime number.&lt;/li&gt;&lt;li&gt;If the value of i equals the number entered by the user, then we will print it as a prime number.&lt;/li&gt;&lt;/ul&gt;
  
  &lt;h2&gt;Write a program to check if a given number is prime or not using for loop.&lt;/h2&gt;
  &lt;pre class=&quot;prettyprint language-c&quot;&gt;#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include&amp;lt;conio.h&amp;gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;int num,i;&lt;br /&gt;clrscr();&lt;br /&gt;printf(&quot;\n Enter a number:&quot;);&lt;br /&gt;scanf(&quot;%d&quot;,&amp;amp;num);&lt;br /&gt;for(i=2;i&amp;lt;num;i++)&lt;br /&gt;{&lt;br /&gt;if(num%i==0)&lt;br /&gt;{&lt;br /&gt;printf(&quot;\n %d is not a prime number&quot;,num);&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;if(i==num)&lt;br /&gt;printf(&quot;\n %d is a prime number&quot;,num);&lt;br /&gt;getch();&lt;br /&gt;return 0;&lt;br /&gt;}&lt;/pre&gt;
  
  &lt;br /&gt;&lt;b&gt;Output:&lt;/b&gt;&lt;br /&gt;Enter a number:11&lt;br /&gt;11 is a prime number&lt;br /&gt;
  &lt;h3&gt;Approach to determine whether the number is prime or not using for loop:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;First, we declare an integer number.&lt;/li&gt;&lt;li&gt;Initialize its value from the user using scanf.&lt;/li&gt;&lt;li&gt;Now we are using for loop to divide that number from all those below that number and check the remainder.&lt;/li&gt;&lt;li&gt;Use the if statement to check the remainder. If the remainder comes to zero, the number is divisible by another number.&lt;/li&gt;&lt;li&gt;We have to print that the number entered by the user is not the prime number.&lt;/li&gt;&lt;li&gt;If the value of i equals the number entered by the user, then we will print it as a prime number.&lt;/li&gt;&lt;/ul&gt;
  
  &lt;b&gt;About this post:&lt;/b&gt;&lt;br /&gt;&lt;div&gt;Siddharth Jha writes this post. It isn&#39;t easy, but I made this program the easiest way. So you can understand easily. You can also read an approach to make a Prime Number Program in C to check whether the number is prime or not, which is below all program output.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you are having issues with these programs, please comment below.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;
Recommended&amp;nbsp;post:&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/05/odd-and-even-numbers-program-in-c.html&quot;&gt;Odd and even numbers program in c&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/06/menu-driven-program-in-c.html&quot;&gt;Simple calculator program in c using switch case&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/03/matrix-program-in-c-using-array.html&quot;&gt;Matrix program in c using array&lt;/a&gt;&lt;br /&gt;
&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/4974856412693101313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2020/05/prime-number-program-in-c.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4974856412693101313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4974856412693101313'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2020/05/prime-number-program-in-c.html' title='Prime Number Program in C using for loop'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/8zILkPnpD6E/default.jpg" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-7180859823789334058</id><published>2022-05-18T17:57:00.008+05:30</published><updated>2022-08-07T15:27:43.040+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="PYTHON-FRAMEWORKS"/><title type='text'>Top 9 Python Frameworks for Web Development 2022</title><content type='html'> &lt;p&gt;This post will discover the top 9 Python Frameworks for Web Development.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Excerpt&lt;/b&gt;: Do you know which programming language is the most recent and rapidly growing web development? Python!! Yes, it is one of the most commercially viable programming languages, with over 80% of developers employing it as their primary coding language. It is not, however, limited to web development.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvdmi8dG9rEJbgTTrVqNCTWsw0-NwbHXf1QkvZlw38kp7HJL3UVOMc7GRCuedWYqedSZ_WksKMte8N0IPS2byExnodJiS3G6qYs81zAQ_B3CVl07gz9X_QUfBh8pFzuox0wGmhX29OS_F41wqEY_ptD_be5FV-BVFXZjl-ME_KeNRgzeuvCXDi_v16/s545/TOP%20PYTHON%20FRAMEWORKS%20FOR%20WEB%20DEVELOPMENT%202022.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;TOP PYTHON FRAMEWORKS FOR WEB DEVELOPMENT 2022&quot; border=&quot;0&quot; data-original-height=&quot;545&quot; data-original-width=&quot;545&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvdmi8dG9rEJbgTTrVqNCTWsw0-NwbHXf1QkvZlw38kp7HJL3UVOMc7GRCuedWYqedSZ_WksKMte8N0IPS2byExnodJiS3G6qYs81zAQ_B3CVl07gz9X_QUfBh8pFzuox0wGmhX29OS_F41wqEY_ptD_be5FV-BVFXZjl-ME_KeNRgzeuvCXDi_v16/w320-h320/TOP%20PYTHON%20FRAMEWORKS%20FOR%20WEB%20DEVELOPMENT%202022.png&quot; title=&quot;TOP PYTHON FRAMEWORKS FOR WEB DEVELOPMENT 2022&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;

    &lt;h2&gt;Introduction: &lt;/h2&gt;
    &lt;p&gt;
        Python is a powerful programming language for data scientists, artificial intelligence (AI), machine learning
        (ML), and data scientific computing. &lt;a href=&quot;https://www.codingwithsid.in/p/python-programs-for-practice.html&quot; target=&quot;_blank&quot;&gt;Python&lt;/a&gt; is expected to surpass Java and C# shortly, implying far more.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Python has grown much more throughout the last five years, by 19.0%, as per the Popularity of Programming Language Index.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Python offers a wide range of frameworks to developers. It has played a significant role in web development for over two decades, from remarkable web frameworks to micro-frameworks.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;According to a survey, python usage has increased from 33.99% in the 2020 poll. While this growth is impressive, it is not surprising. We will review some of the best Python Frameworks for Web Development for 2022 that web developers and programmers should use to improve site speed and time-to-market.&lt;/p&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;About Python:&lt;/h2&gt;&lt;p&gt;Python is a compellingly constructed, understood, and engaging object-oriented programming language. Its simple-to-learn and simple-to-read design significantly reduce development time. Python developers could use the framework&#39;s ready-made components rather than trying to write similar code for each project. Python Frameworks mainly saves time and money but shortens the time to market.&lt;/p&gt;&lt;p&gt;Python supports modules and packages, promoting methods and practices and code reusability. The Python interpreter and vast standard library are free to use and disperse in source or binary form for all major platforms. Any Python developer, new or experienced, will agree on its dependability and efficiency. Python frameworks for web development can be used and deployed by developers.&lt;/p&gt;
&lt;p&gt;Are you looking forward to making a move to the Programming field? Take the&amp;nbsp;&lt;a href=&quot;https://mindmajix.com/python-training&quot;&gt;Python
  Online Training&lt;/a&gt; and begin your career as a professional Python programmer.&lt;/p&gt;

&lt;h2&gt;Listed below are some of the top Python Frameworks for Web Development:&lt;/h2&gt;
&lt;h2&gt;
1.	Django&lt;/h2&gt;

&lt;p&gt;It&#39;s impossible to discuss web development frameworks without mentioning Django. Django, first released in 2005, is one of Python&#39;s oldest and largest frameworks. It was created and is maintained by a well-known web hosting company. Django, an open and free Python framework, allows developers to quickly build complex code and apps. The Django framework aids in the development of high-quality web applications. It is one of the most acceptable Python frameworks for rapidly developing APIs and web applications.&lt;/p&gt;&lt;p&gt;It was initially envisioned as an engine to assist developers in creating content-based websites. Since its official launch, developers have used this to power many applications and services. Such a high-level framework simplifies web application development by providing various powerful features. It has a massive library collection and emphasizes efficiency, less coding, and component reusability.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiInqTZaBxAoi30fsl7wh-MsBiVRL0R0dAwSPSJuSvVzebpUMpoIISe1e2XIewukBwpPHvqhZd6EnH0SE4whUHPizJbNNLTs_76rD2hcTg4C_YS1H7ifj-ql3pI84RELO2hdVpLZ8IFUAlblLRF8LfLlRPtejAux2D6B14TOeQ6TnSCRGNU2ATy9O_m/s371/Model%20View%20Contoller.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;model view controller&quot; border=&quot;0&quot; data-original-height=&quot;371&quot; data-original-width=&quot;330&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiInqTZaBxAoi30fsl7wh-MsBiVRL0R0dAwSPSJuSvVzebpUMpoIISe1e2XIewukBwpPHvqhZd6EnH0SE4whUHPizJbNNLTs_76rD2hcTg4C_YS1H7ifj-ql3pI84RELO2hdVpLZ8IFUAlblLRF8LfLlRPtejAux2D6B14TOeQ6TnSCRGNU2ATy9O_m/w285-h320/Model%20View%20Contoller.png&quot; title=&quot;model view controller&quot; width=&quot;285&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;

&lt;h3&gt;Features of Django:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;URL system is both simple and powerful.&lt;/li&gt;
&lt;li&gt;Object-oriented programming language database with the best data storage and recovery capabilities. &lt;/li&gt;
&lt;li&gt;The automatic admin interface service allows for the customization of editing, adding, and deleting items. &lt;/li&gt;
&lt;li&gt;Integrated authentication system&lt;/li&gt;
&lt;li&gt;A caching framework is a collection of cache mechanisms&lt;/li&gt;

&lt;/ul&gt;
&lt;h2&gt;
2.	Pyramid:
&lt;/h2&gt;
&lt;p&gt;Pyramid is a well-established and feature-rich Python web framework. Furthermore, it has a wide range of applications, including websites, web APIs, and anywhere a popular programming language like Python would be helpful. Pyramid frameworks are adaptable and can be used for simple and complex projects. Because of its clarity and measured quality, it&#39;s also the most appreciated web framework among many experienced Python developers.&lt;/p&gt;&lt;p&gt;One of Python&#39;s most valuable assets as a developer language is its community support, evident here along with consumer engagement via mailing lists, IRC channels, Stack Overflow, and other channels. Such a framework is adaptable and allows users to create simple web apps using a subtle approach.&lt;/p&gt;
&lt;h3&gt;Features of Pyramid:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;URL surveying based on Routes configuration via URL dispatch and HTML structure &lt;/li&gt;
&lt;li&gt;validation and generation by Web Helpers. &lt;/li&gt;
&lt;li&gt;Complete templating and asset details&lt;/li&gt;
&lt;li&gt;Capability to work very well with larger and smaller applications&lt;/li&gt;
&lt;li&gt;Testing, support, and detailed data documentation&lt;/li&gt;
&lt;li&gt;Authentication and approval are both flexible.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
3.	CherryPy:&lt;/h2&gt;

&lt;p&gt;CherryPy, now nearly ten years old, has proven incredibly fast and stable. It is a Python web development framework with a multi-hung server. It is compatible with any operating framework that supports Python. Furthermore, it is intended to be simple to learn and use, emphasizing simplicity and usability. CherryPy could be perfect if you&#39;re an intermediate developer looking to try something new.&lt;/p&gt;&lt;p&gt;Whereas advanced developers may discover insufficient features, it allows beginners to gain experience with Python before going deep into more complex frameworks.&lt;/p&gt;&lt;p&gt;A simple web framework enables you to use any technology for data access, templating, etc. Yes, it can handle everything a web framework can, such as sessions, file uploads, static, cookies, etc.&lt;/p&gt;&lt;p&gt;CherryPy&#39;s main attraction would be that it makes it possible to run its code without relying on other people or services.&lt;/p&gt;

&lt;h3&gt;Features of CherryPy:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;&lt;li&gt;It is simple to run multiple HTTP servers (for example, on various ports).&lt;/li&gt;&lt;li&gt;Python 2.7+, 3.5+, PyPy, Jython, and Android&lt;/li&gt;&lt;li&gt;support Built-in tools for the encryption process, sessions, prefetching, authorization, static content, and more&lt;/li&gt;&lt;li&gt;A robust configuration system for both developers and deployers.&lt;/li&gt;&lt;li&gt;Profiling, coverage, and testing are all built-in.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
4.	Grok:&lt;/h2&gt;

&lt;p&gt;Developers can select from a wide range of network and impartial libraries based on the task requirements. Grok&#39;s user interface (UI) is similar to that of other full-stack Python frameworks, including Pylons and TurboGears. It is just an open-source framework designed to accelerate application development. Grok seems to be a web framework built with the Zope toolkit technology. It provides developers with an agile development experience by focusing on two general principles: convention over configuration and DRY.&lt;/p&gt;

&lt;h3&gt;Features of Grok:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;&lt;li&gt;Grok constituent architecture assists developers in reducing development unpredictability.&lt;/li&gt;&lt;li&gt;Establishes the basis and other assets required to create custom web applications for business needs.&lt;/li&gt;&lt;li&gt;Provides a solid foundation for building robust and versatile web applications.&lt;/li&gt;&lt;li&gt;Allows web developers to take advantage of Zope 3&#39;s power.&lt;/li&gt;&lt;li&gt;A powerful object database for backups.&lt;/li&gt;&lt;li&gt;Integrated security to protect your application and grant specific access to users&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
5.	Flask:
&lt;/h2&gt;
&lt;p&gt;Flask has become one of Python&#39;s most powerful major web frameworks and one of the language&#39;s most rapidly growing tools. Flask is easy to learn, has an extensive library of add-ons, and is simple to deploy. If you want to build websites faster with Python, look into Flask. It lacks the structure of Django or Pyramid, yet it offers an excellent environment for developing functional applications.&lt;/p&gt;&lt;p&gt;Large corporations are using Flask. Flask is now a Python framework that is available under the BSD license.&lt;/p&gt;&lt;p&gt;Its prominence emanates from its simplification: it allows you to go and get up and running quickly. Flask will be here to stay, as evidenced by its extensive documentation and active community support.&lt;/p&gt;

&lt;h3&gt;
Features of Flask:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;&lt;li&gt;Support for integrated unit testing (code with quality).&lt;/li&gt;&lt;li&gt;Jinja2 templating (tags, filters, macros, and more) is used.&lt;/li&gt;&lt;li&gt;WSGI 1.0 is compliant with the letter.&lt;/li&gt;&lt;li&gt;The community has provided several extensions to help incorporate advanced functionalities.&lt;/li&gt;&lt;li&gt;Integrated development server and debugger.&lt;/li&gt;&lt;li&gt;Request dispatching via REST.&lt;/li&gt;

 &lt;/ul&gt;

&lt;h2&gt;
6. TurboGears:
&lt;/h2&gt;

&lt;p&gt;TurboGears is a Python framework for building data-driven full-stack web applications. It is intended to address the shortcomings of various widely used web and mobile app development frameworks. TurboGears seems to be a framework that straddles the line between a full-fledged framework and an add-on library. Furthermore, its architectural style, which makes scalability and ease of maintenance possible, is one of its big selling points.&lt;/p&gt;&lt;p&gt;The framework adheres to an MVC (Model-View-Controller) design and incorporates robust formats, a fantastic Object Relational Mapper (ORM), and Ajax for the server and program.&lt;/p&gt;

&lt;h3&gt;
Features of TurboGears:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;&lt;li&gt;All of the features are implemented as function decorators.&lt;/li&gt;&lt;li&gt;Support for multiple databases.&lt;/li&gt;&lt;li&gt;Command-line tools are available.&lt;/li&gt;&lt;li&gt;Integration of the MochiKit JavaScript library.&lt;/li&gt;&lt;li&gt;MVC architecture with Paste Script templates&lt;/li&gt;&lt;li&gt;Tosca Widgets to help with frontend design and server deployment coordination.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
7.	Web2Py:
&lt;/h2&gt;
&lt;p&gt;A web server, SQL database, and an online interface simplify the Python app development process. Clients can use web browsers to construct, rewrite, implement, and manage web applications. Web2py includes a debugger, code editor, and deployment tool to help you build and debug code and also allows the user to monitor web applications.&lt;br /&gt;Web2py&#39;s main component is a ticketing framework, which generates a ticket when an error occurs. The above encourages the individual to keep track of the error and its status.&lt;/p&gt;

&lt;h3&gt;Features of Web2Py:&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;/li&gt;&lt;li&gt;It includes Useful Batteries for quickly building a variety of web apps without the need for third-party tools and services.&lt;/li&gt;&lt;li&gt;Maintain web applications&#39; security by attempting to address top security flaws and issues.&lt;/li&gt;&lt;li&gt;Supports configuration agreements and enables rapid web development.&lt;/li&gt;&lt;li&gt;Claims to support MVC architecture to make web development easier.&lt;/li&gt;&lt;li&gt;Allows developers to use widely utilized relational and NoSQL databases.&lt;/li&gt;&lt;li&gt;It is a web-based IDE for web development projects such as cleaning temporary files, proofreading app files, running trials, and browsing previous tickets.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
8.	Bottle:&lt;/h2&gt;

&lt;p&gt;You can use Bottle with no knowledge of web programming if you want to add a few high-speed prototyping capabilities or probably create a landing page quickly. The Bottle is a top Python web framework that falls into the category of small-scale frameworks, and it was initially designed for creating web APIs. The Bottle also attempts to start executing it all in a single site document, which only depends on the Python Standard Library.&lt;/p&gt;&lt;p&gt;Flask&#39;s features may be better suited to more complex web applications. On the other hand, Bottle is worth considering if code readability and simplicity are essential to you.&lt;/p&gt;

&lt;h3&gt;Features of Bottle:&lt;/h3&gt;
&lt;ul&gt;

&lt;li&gt;&lt;/li&gt;&lt;li&gt;The simple syntax allows for spotless and dynamic URL routes for mapping.&lt;/li&gt;&lt;li&gt;Constructed template engine and backing that is quick and pythonic.&lt;/li&gt;&lt;li&gt;Using the WSGI framework with CGI and the WSGI internals is simple.&lt;/li&gt;&lt;li&gt;Bottle allows convenient access to data, cookies, file uploads, and other HTTP-related metadata.&lt;/li&gt;&lt;li&gt;Bottle works as an HTTP server and as a backend for glue, fapws3, flip, or another WSGI-capable HTTP server.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
9.	Quixote:
&lt;/h2&gt;
&lt;p&gt;The Quixote framework is used to create Web-based applications in Python. Its goals are adaptability and improved performance, in that order. Traditional technology is used to create Quixote applications. There are three major versions of Don &lt;a href=&quot;http://quixote.ca/&quot; target=&quot;_blank&quot;&gt;Quixote&lt;/a&gt;. Versions 1 and 2 look similar but are very different. Version 1 is no longer effectively maintained. Version 3 requires Python 3, as does Quixote 2. Versions 2 and 3 are effectively maintained and used by a variety of public sites.&lt;/p&gt;

&lt;p&gt;Traditional technology is used to create Quixote applications. As a result, if a Python developer needs to pursue or gain knowledge of the real programming language,&#39; Quixote is really for them.&lt;/p&gt;

&lt;h3&gt;Features of Quixote:&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It is compatible with just about any web server which supports CGI or Fast CGI. &lt;/li&gt;
&lt;li&gt;Mod python is supported by Apache. &lt;/li&gt;
&lt;li&gt;SCGI protocol support is also available. &lt;/li&gt;
&lt;li&gt;With session management API, the design is simple and flexible. &lt;/li&gt;
&lt;li&gt;A function library to help with the development and assessment of an HTML form. &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
Toptal has recently launched a Web Developer Checklist that provides a series of website launch steps that are critical for a successful project including best practices, security, tagging, analytics, and more.

Here&#39;s the link for your reference:&lt;a href=&quot;https://www.toptal.com/developers/webdevchecklist&quot; target=&quot;_blank&quot;&gt; https://www.toptal.com/developers/webdevchecklist&lt;/a&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;
  
&lt;p&gt;
Python&#39;s popularity has grown over time. Because it is a free and open-source language, anyone can modify and use it. Python is the preferred programming language for 67.8% of web developers. The appropriate web framework must be chosen based on the project&#39;s scope, communication requirements, level of customization required, and everything else. Each Python developer has a unique coding style and set of preferences, and they will assess each framework in light of the requirements of each task. Which will you employ in your next project? Alternatively, what are your favourite Python Frameworks for Web Development? Do let us know in the comment section.&lt;/p&gt;

&lt;h2&gt;Author Bio: &lt;/h2&gt;


&lt;p&gt;&lt;a href=&quot;https://www.linkedin.com/in/amruddin-shaik-6bab341bb/&quot;&gt;Amruddin
Shaik&lt;/a&gt; is a Digital Marketer and Content Contributor, Who is working with&amp;nbsp;&lt;a href=&quot;https://mindmajix.com/&quot;&gt;MindMajix,&lt;/a&gt; a top global
online training provider. I’m a tech enthusiast and have a great understanding
of today’s technology. Having an in-depth knowledge of IT and demanding
technologies such as Python, SQL, Linux, Java, Power BI etc.&lt;/p&gt;



</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/7180859823789334058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/05/python-frameworks-for-web-development.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/7180859823789334058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/7180859823789334058'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/05/python-frameworks-for-web-development.html' title='Top 9 Python Frameworks for Web Development 2022'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvdmi8dG9rEJbgTTrVqNCTWsw0-NwbHXf1QkvZlw38kp7HJL3UVOMc7GRCuedWYqedSZ_WksKMte8N0IPS2byExnodJiS3G6qYs81zAQ_B3CVl07gz9X_QUfBh8pFzuox0wGmhX29OS_F41wqEY_ptD_be5FV-BVFXZjl-ME_KeNRgzeuvCXDi_v16/s72-w320-h320-c/TOP%20PYTHON%20FRAMEWORKS%20FOR%20WEB%20DEVELOPMENT%202022.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-4240137499797346027</id><published>2022-04-26T15:10:00.011+05:30</published><updated>2022-10-21T12:42:32.256+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Prime Number Program in Python using while loop</title><content type='html'>&lt;p&gt;In this program, we have a number given by the user. We have to print whether that number is prime or not.&lt;/p&gt;
&lt;div class=&quot;mbtTOC&quot;&gt; 
    &lt;button onclick=&quot;mbtToggle()&quot;&gt;Table Of Contents&lt;/button&gt; 
    &lt;ul id=&quot;mbtTOC&quot;&gt;&lt;/ul&gt; 

    &lt;/div&gt;
&lt;h2&gt;Prime Number Program in Python using while loop&lt;/h2&gt;
&lt;p&gt;In this program, we will find whether the given number is prime or not. We will use the while loop to check that the given number is divisible by any number between 2 and the square root of the given number. It will reduce our time complexity from O(n) to O(sqrt(n)).&lt;/p&gt;
&lt;pre class=&quot;prettyprint language-py&quot;&gt;num=int(input(&quot;Enter a number: &quot;))
check=True
i=2;
while i*i&amp;lt;=num:
    if(num%i==0):
        check=False
        break
    i+=1

if(check and num!=1):
    print(str(num)+&quot; is a Prime Number&quot;)
else:
    print(str(num)+&quot; is not a Prime Number&quot;)
&lt;/pre&gt;


&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;

Enter a number: 16&lt;br /&gt;
16 is not a Prime Number&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;div&gt;Read also: &lt;a href=&quot;https://www.codingwithsid.in/p/python-programs-for-practice.html&quot;&gt;Python Programs for Practice&lt;/a&gt;&lt;/div&gt;
&lt;h2&gt;Prime Number Program in Python using for loop&lt;/h2&gt;
&lt;p&gt;
In this program, we will make a python program to check prime numbers. It will print whether the given number is prime or not.&lt;/p&gt;

&lt;pre class=&quot;prettyprint language-py&quot;&gt;# check given number is prime or not
num=int(input(&quot;Enter a number: &quot;))
check=True

for i in range(2,num):
    if(num%i==0):
        check=False
        break

if(check and num!=1):
    print(str(num)+&quot; is a Prime Number&quot;)
else:
    print(str(num)+&quot; is not a Prime Number&quot;)
&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;

Enter a number: 997&lt;br /&gt;
997 is a Prime Number&lt;br /&gt;

Enter a number: 15&lt;br /&gt;
15 is not a Prime Number&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;h2&gt;Prime number checker in python using function&lt;/h2&gt;
&lt;pre&gt;
def prime_checker(number):
    f=1
    for i in range (2,number):
        if(number%i==0):
            f=0
            break
    
    if f:
        print(&quot;It&#39;s a prime number.&quot;)
    else:
        print(&quot;It&#39;s not a prime number.&quot;)

n = int(input(&quot;Check this number: &quot;))
prime_checker(number=n)
&lt;/pre&gt;

&lt;h2&gt;Approach for Python program to check prime number:&lt;/h2&gt;
&lt;div&gt;&lt;div&gt;We will write a python program to find whether a given number is prime or not.&lt;/div&gt;&lt;div&gt;Prime Number is a number that is divisible only by one and itself.&lt;/div&gt;&lt;div&gt;Let&#39;s take a number here, so let&#39;s say 11:&lt;/div&gt;&lt;br /&gt;&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/SpTAxH_Geow&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;

We will try to divide this number by two because all the numbers are divisible by one, so we will start with 2. We will check if 11 can be divided by two; if yes, then it&#39;s not a prime number; if it&#39;s not divisible by &quot;2,&quot; then we&#39;ll go for three, then we&#39;ll go for four, and so on till 10. &lt;br /&gt;
  &lt;div&gt;&lt;br /&gt;Read also: &lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot;&gt;Factorial Program in Python&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;We start from 2, and we&#39;ll end with the given number minus 1. For example: if we take a number that is 17, then we will end at 16.&lt;br /&gt;&lt;br /&gt;
Every time you have to check if you find the number which is divisible by any other number between 2 &amp;amp; one less than the given number, then the given number is not a prime number. We can print that the given number is a prime number when we find that the given number is not divisible by the last number (which is number-1).&amp;nbsp;&amp;nbsp;
&lt;/div&gt;
&lt;h3&gt;About this post:&lt;/h3&gt;
&lt;div&gt;
  This post is all about the prime number program in python. If you have doubts related to this program, let me know in the comment section.
  &lt;script&gt;mbtTOC();&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/4240137499797346027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/04/prime-number-program-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4240137499797346027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/4240137499797346027'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/04/prime-number-program-in-python.html' title='Prime Number Program in Python using while loop'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/SpTAxH_Geow/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-1524464532519449482</id><published>2022-04-09T23:58:00.005+05:30</published><updated>2022-06-27T01:25:39.981+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Python Program to Convert Celsius to Fahrenheit</title><content type='html'>&lt;p&gt;In this post, we are going to make a&amp;nbsp;&lt;b&gt;Python Program to Convert Celsius to Fahrenheit.&lt;/b&gt;&amp;nbsp;
  C° to F°: Formula to convert Celsius to Fahrenheit&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;div style=&quot;text-align: center;&quot;&gt;F=1.8C+32&lt;/div&gt;&lt;p&gt;Multiply the given degree Celsius temperature by 1.8 and add 32.&lt;/p&gt;
  For example: let the temperature is 50-degree Celsius.&lt;br /&gt;
  (50°C × 1.8) + 32 = 122°F&lt;h2&gt;Python Program to Convert Celsius to Fahrenheit&lt;/h2&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;celsius=input(&quot;Enter Temperature in Degree Celsius: &quot;)
celsius=int(celsius)
fahrenheit=(1.8*celsius)+32
print(&quot;Temperature in Fahrenheit: &quot;,fahrenheit)&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter Temperature in Degree Celsius: 33&lt;br /&gt;Temperature in Fahrenheit:  91.4&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/_fxLlOO0Pts&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;Conclusion:&lt;/h2&gt;
&lt;div&gt;In this post, we made a python program to convert the given degree Celsius temperature to Fahrenheit. If you have any doubts let me know in the comment section or you can dm to our Instagram account.&lt;/div&gt;&lt;p&gt;Related Post:&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2021/04/fibonacci-series-in-python-using-recursion.html&quot;&gt;Python program for Fibonacci series&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2021/03/python-program-to-calculate-simple-interest-and-compound-interest.html&quot;&gt;Python program for simple interest&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/1524464532519449482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/04/python-program-to-convert-celsius-to-fahrenheit.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/1524464532519449482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/1524464532519449482'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/04/python-program-to-convert-celsius-to-fahrenheit.html' title='Python Program to Convert Celsius to Fahrenheit'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/_fxLlOO0Pts/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-8755059737965360194</id><published>2022-03-21T10:19:00.002+05:30</published><updated>2022-03-21T12:22:05.907+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="CPP"/><category scheme="http://www.blogger.com/atom/ns#" term="Strings"/><category scheme="http://www.blogger.com/atom/ns#" term="While-loop"/><title type='text'>Multiply Strings in C++</title><content type='html'>&lt;p&gt;In this program, we are going to multiply two strings in c++. We will not use any built-in function to convert a string to an integer.&lt;/p&gt;

&lt;div&gt;Pre-requisite:
&lt;ul&gt;
  &lt;li&gt;Loops&lt;/li&gt;
  &lt;li&gt;Add Strings&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;


&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Input: num1 = &quot;80&quot;, num2 = &quot;2&quot;&lt;br /&gt;
Output: &quot;160&quot;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Multiply Strings in C++&lt;/h2&gt;
&lt;p&gt;In this program, we have performed simple multiplication of two strings. We picked up the last character of the second number and multiplied it with each character of the first number and pushed that multiplication result in a vector of sum. Then we performed the addition of all the strings in the vector of sum.&lt;/p&gt; 
&lt;pre class=&quot;prettyprint language-cpp&quot;&gt;#include &amp;lt;bits/stdc++.h&amp;gt;
using namespace std;
class Solution
{
public:
    string addStrings(string &amp;amp;num1, string &amp;amp;num2)
    {
        int n = num1.size() - 1;
        int m = num2.size() - 1;
        string s;
        int carry = 0;
        int x1, x2, value;
        while (n &amp;gt;= 0 || m &amp;gt;= 0)
        {
            if (n &amp;gt;= 0)
            {
                x1 = num1[n] - &#39;0&#39;;
            }
            else
                x1 = 0;
            if (m &amp;gt;= 0)
            {
                x2 = num2[m] - &#39;0&#39;;
            }
            else
                x2 = 0;

            value = (x1 + x2 + carry) % 10;
            carry = (x1 + x2 + carry) / 10;
            s.push_back(value + &#39;0&#39;);
            n--;
            m--;
        }
        if (carry != 0)
            s.push_back(carry + &#39;0&#39;);
        reverse(s.begin(), s.end());
        return s;
    }
    string multiply(string num1, string num2)
    {
        vector&amp;lt;string&amp;gt; sum;

        int m = num2.size() - 1;
        int last = 0;
        while (m &amp;gt;= 0)
        {
            string s;
            int carry = 0;
            int x1, x2, value;
            int n = num1.size() - 1;
            while (n &amp;gt;= 0)
            {
                x1=num1[n]-&#39;0&#39;;
                x2=num2[m]-&#39;0&#39;;

                value = (x1 * x2 + carry) % 10;
                carry = (x1 * x2 + carry) / 10;
                s.push_back(value + &#39;0&#39;);
                n--;
            }
            if (carry != 0)
                s.push_back(carry + &#39;0&#39;);

            reverse(s.begin(), s.end());
            int temp = last;
            while (temp--)
                s.push_back(&#39;0&#39;);
            last++;
            sum.push_back(s);
            m--;
        }
        string ans = &quot;0&quot;;
        for (auto str : sum)
        {
            ans = addStrings(ans, str);
        }

        if (ans[0] == &#39;0&#39;)
        {
            int i = 1;
            while (i &amp;lt; ans.size() &amp;amp;&amp;amp; ans[i] == &#39;0&#39;)
            {
                ans.erase(ans.begin() + i);
                // i++;
            }
        }

        return ans;
    }
};
int main()
{
    Solution s;
    string str1,str2;
    cout&amp;lt;&amp;lt;&quot;Enter First String:&quot;;
    cin&amp;gt;&amp;gt;str1;
    cout&amp;lt;&amp;lt;&quot;Enter Second String:&quot;;
    cin&amp;gt;&amp;gt;str2;
    cout&amp;lt;&amp;lt;s.multiply(str1,str2)&amp;lt;&amp;lt;endl;
}

&lt;/pre&gt;

&lt;h2&gt;Multiply Strings | Leetcode 43 Solution&lt;/h2&gt;

&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/5NdhK3tZViQ&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;

&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In my childhood, my grandfather used to give me multiplication of numbers that have more than 10 digits so that I can&#39;t cheat. He knows a trick to verify the answer of multiplication without actually multiplying them. So, I had to multiply them without any cheating. Today, I made a program that can multiply any two numbers, regardless of digits.
&lt;/div&gt;

&lt;div&gt;Related Posts:&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2022/01/reverse-linked-list-using-recursion.html&quot;&gt;Reverse a Linked List using Recursion in C++&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2021/12/minimum-in-subarray-segment-tree.html&quot;&gt;Minimum In Subarray Segment Tree&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/8755059737965360194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/03/multiply-strings-cpp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8755059737965360194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/8755059737965360194'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/03/multiply-strings-cpp.html' title='Multiply Strings in C++'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/5NdhK3tZViQ/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-2999973191468667629</id><published>2022-03-04T00:23:00.002+05:30</published><updated>2022-07-15T09:49:44.416+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Recursion"/><title type='text'>GCD of two numbers in Python using recursion</title><content type='html'>&lt;p&gt;&amp;nbsp;In this program, we will make a python program to calculate the GCD of two numbers using recursion.&amp;nbsp;&lt;/p&gt;&lt;p&gt;GCD stands for the greatest common divisor. Sometimes, they can ask you to write a program for HCF of two numbers, so don&#39;t worry about this because they are the same thing.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Ex: GCD of 6 &amp;amp; 9 is 3&amp;nbsp;&lt;/p&gt;

&lt;h2 style=&quot;text-align: left;&quot;&gt;Write a Program to find the gcd of two numbers in python using Recursion.&lt;/h2&gt;


&lt;pre&gt;def gcd(a,b):
    if(b==0):
        return a;
    return gcd(b,a%b);

str = input(&quot;Enter Two Numbers:&quot;)
a, b = str.split()
a=int(a)
b=int(b)
print(gcd(a,b));
&lt;/pre&gt;

  &lt;div&gt;Output for gcd of two numbers in python:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter Two Numbers:500 1000&lt;br /&gt;
500&lt;br /&gt;

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/Euclidean_algorithm&quot; target=&quot;_blank&quot;&gt;Euclid algorithm&lt;/a&gt;,&amp;nbsp; GCD(a,b)=GCD(b,a%b). The base case for our recursive function is if b is zero, then we will return a.&lt;/p&gt;&lt;p&gt;The time complexity of GCD of two numbers in Python using Recursion is O(log(max(a,b)).&lt;/p&gt;
&lt;h2&gt;GCD of Two numbers in Python&lt;/h2&gt;
&lt;p&gt;In this approach, we are simply iterating from 1 to a minimum of A &amp;amp; B, and when we find a number, that is a factor of both A and B. Then, we store it in the answer variable. This way, we get the highest common factor of A and B.&lt;/p&gt;
&lt;pre&gt;def gcd(self, A, B):
        # code here
        mn=min(A,B)
	    ans=1
	    for i in range(1,mn+1):
	        if(A%i==0 and B%i==0):
	            ans=i;
	    
	    return ans;
&lt;/pre&gt;

&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiyGK9E0Wth7ETXq_KgS4dfVG6uhe8kCmS3m8Tr96aevmIaUM0Gm2paqGmd756Zk2YjiYBHsXFvl3yuJ1m9dqXstiTQCvF-tIuZry7Dl5RZdA71cZSzj2J8V1p3zE73DB03TTW8cWnX9JSIexRu2H-dWG1XVPuRpFKLXHpqLza73Owf90MsKOqBhg7C&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;GCD of Two numbers in Python&quot; data-original-height=&quot;608&quot; data-original-width=&quot;1357&quot; height=&quot;286&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiyGK9E0Wth7ETXq_KgS4dfVG6uhe8kCmS3m8Tr96aevmIaUM0Gm2paqGmd756Zk2YjiYBHsXFvl3yuJ1m9dqXstiTQCvF-tIuZry7Dl5RZdA71cZSzj2J8V1p3zE73DB03TTW8cWnX9JSIexRu2H-dWG1XVPuRpFKLXHpqLza73Owf90MsKOqBhg7C=w640-h286&quot; title=&quot;TLE in GCD of Two numbers in Python using O(min(A,B))&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The time complexity of this approach is O(min(A, B)), which is slower than our previous log(n) approach. It gives a time limit exceeded when&amp;nbsp;&lt;span face=&quot;urw-din, sans-serif&quot; style=&quot;background-color: white; color: #333333; font-size: 18px;&quot;&gt;1 ≤ A, B ≤ 10&lt;/span&gt;&lt;span face=&quot;urw-din, sans-serif&quot; style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-size: 13.5px; line-height: 0; position: relative; top: -0.5em; vertical-align: baseline;&quot;&gt;9&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span face=&quot;urw-din, sans-serif&quot; style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-size: 13.5px; line-height: 0; position: relative; top: -0.5em; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span face=&quot;urw-din, sans-serif&quot; style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-size: 13.5px; line-height: 0; position: relative; top: -0.5em; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;


&lt;h2&gt;How to find gcd of two numbers in python&lt;/h2&gt;
&lt;p&gt;Here, I include the video of code with harry to find the gcd of two numbers in Python for a better understanding of this question.&lt;/p&gt;

&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/DePWIOK1STg&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;


&lt;p&gt;Related Posts:&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2022/02/simple-python-program-to-add-two-numbers.html&quot;&gt;Simple Python Program to Add Two Numbers&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/12/python-program-to-find-factorial-of-a-number.html&quot; target=&quot;_blank&quot;&gt;Python Program to Find Factorial of a Number using for loop&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/2999973191468667629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/03/gcd-of-two-numbers-in-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/2999973191468667629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/2999973191468667629'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/03/gcd-of-two-numbers-in-python.html' title='GCD of two numbers in Python using recursion'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEiyGK9E0Wth7ETXq_KgS4dfVG6uhe8kCmS3m8Tr96aevmIaUM0Gm2paqGmd756Zk2YjiYBHsXFvl3yuJ1m9dqXstiTQCvF-tIuZry7Dl5RZdA71cZSzj2J8V1p3zE73DB03TTW8cWnX9JSIexRu2H-dWG1XVPuRpFKLXHpqLza73Owf90MsKOqBhg7C=s72-w640-h286-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-6109591553705213635</id><published>2022-02-03T16:32:00.006+05:30</published><updated>2022-09-19T18:11:11.571+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Simple Python Program to Add Two Numbers</title><content type='html'>&lt;p&gt;&amp;nbsp;In this program, we are going to make a simple python program that will add two numbers&amp;nbsp;with user input. We will take numbers from users or else we can also hard code values.&lt;/p&gt;&lt;p&gt;Pre-requisite: Syntax to &lt;a href=&quot;https://www.codingwithsid.in/2021/03/python-program-to-print-hello-world.html&quot; target=&quot;_blank&quot;&gt;print Output in python&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I am using &lt;a href=&quot;https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;f-string&lt;/a&gt; to print our result. f-string is a simple print statement that helps us to print variables along with string. We have to just use curly braces to print variables. It starts with the prefix f.&lt;br /&gt;For example:  &lt;/p&gt;
  &lt;pre class=&quot;prettyprint-python&quot;&gt;  
  A=7
  print(f&quot;Number A is {A}&quot;)
  &lt;/pre&gt;

&lt;details class=&quot;sp toc&quot;&gt;
  &lt;summary data-hide=&quot;Hide all&quot; data-show=&quot;Show all&quot;&gt;Table of Contents&lt;/summary&gt;  
  &lt;div class=&quot;toC&quot; id=&quot;toContent&quot;&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2&gt;How to write a program to add two numbers in python with user input&lt;/h2&gt;
&lt;div&gt;In this example, we take input from the user which is by default of string type so we will typecast them to int. Then we will add and print them.&lt;/div&gt;
&lt;pre class=&quot;prettyprint-python&quot;&gt;first=int(input(&quot;Enter first Number: &quot;))
second=int(input(&quot;Enter Second Number: &quot;))

sum=first+second
print(f&quot;{first} + {second} = {sum}&quot;)
&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter first Number: 56&lt;br /&gt;
Enter Second Number: 44&lt;br /&gt;
56 + 44 = 100&lt;br /&gt;
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Simple Python Program to Add Two Numbers&lt;/h2&gt;
&lt;div&gt;In this example, we will add two numbers in python and print their sum.&lt;/div&gt;
&lt;pre class=&quot;prettyprint-python&quot;&gt;a=5
b=10
sum=a+b
print(f&quot;{a} + {b} = {sum}&quot;)
&lt;/pre&gt;
&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
5 + 10 = 15

&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2&gt;Program to Add Two numbers without using Addition Operator&lt;/h2&gt;
&lt;pre class=&quot;prettyprint-python&quot;&gt;first=int(input(&quot;Enter first Number: &quot;))
num=first
second=int(input(&quot;Enter Second Number: &quot;))
num2=second

while second != 0:
    
    temp = first &amp;amp; second
    first = first ^ second
    second = temp &amp;lt;&amp;lt; 1
print(f&quot;{num} + {num2} = {first}&quot;)
&lt;/pre&gt;

&lt;div&gt;Output:
&lt;p style=&quot;background-color: #383b40; color: white; padding: 5px;&quot;&gt;
&lt;samp&gt;
Enter first Number: 57&lt;br /&gt;
Enter Second Number: 87&lt;br /&gt;
57 + 87 = 144&lt;br /&gt;
&lt;/samp&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;div style=&quot;text-align: center;&quot;&gt;&lt;iframe allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/WYf7bNlw_4Y&quot; title=&quot;YouTube video player&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;h2&gt;Python Program to Add Two Numbers using function&lt;/h2&gt;
&lt;div&gt;In this example, we will make a function that will return the addition of two numbers. It takes two numbers in arguments. We can also print the sum of numbers in our function.&lt;/div&gt;
&lt;pre class=&quot;prettyprint-python&quot; style=&quot;text-align: left;&quot;&gt;def addition(num1,num2):
    return num1+num2

num1=int(input(&quot;Enter first Number: &quot;))
num2=int(input(&quot;Enter Second Number: &quot;))

print(f&quot;{num1} + {num2} = {addition(num1,num2)}&quot;)&lt;/pre&gt;
&lt;h2&gt;Python program to add two numbers using class&lt;/h2&gt;
&lt;pre class=&quot;prettyprint-python&quot;&gt;class Add:
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.sum()

    def sum(self):
        print(f&quot;The sum of {self.a} &amp;amp; {self.b} is {self.a+self.b}&quot;)


num1 = int(input(&quot;Enter first Number: &quot;))
num2 = int(input(&quot;Enter Second Number: &quot;))

num = Add(num1, num2)
&lt;/pre&gt;
&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiclhuvojXDzoiGW1FTNOWCuA0iejqUeXhUMJzxHJtDmNsRdYbNfVCz3ZHW_uwq9AcEvbizx27e5IKOQlHoMOblfktMUjWagN-qPXjzMSbNKHLGOgmfOtNRiVc-R3bNTVMZS9JODRvflwFuEJGnjQueBeSOwh1Ueb4QAMNQCB1BjpbJIUjnM-VtF46i&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Python program to add two numbers using class&quot; data-original-height=&quot;566&quot; data-original-width=&quot;1161&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEiclhuvojXDzoiGW1FTNOWCuA0iejqUeXhUMJzxHJtDmNsRdYbNfVCz3ZHW_uwq9AcEvbizx27e5IKOQlHoMOblfktMUjWagN-qPXjzMSbNKHLGOgmfOtNRiVc-R3bNTVMZS9JODRvflwFuEJGnjQueBeSOwh1Ueb4QAMNQCB1BjpbJIUjnM-VtF46i=w640-h312&quot; title=&quot;Python program to add two numbers using class&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;About this post:&lt;br /&gt;
This is all about the python program to print the sum of two numbers. Please try to make a &lt;a href=&quot;https://www.codingwithsid.in/2021/03/calculator-program-in-python.html&quot;&gt;calculator program in python&lt;/a&gt;&amp;nbsp;that provides users with many options like addition, subtraction, multiplication and division. Then the user will choose from these options and your program should print the appropriate result.
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you have any doubts or you are reading till here please comment below your thoughts.
&lt;script&gt;document.addEventListener(&#39;DOMContentLoaded&#39;, () =&gt;
  new TableOfContents({
      from: document.querySelector(&#39;#postBody&#39;),
      to: document.querySelector(&#39;#toContent&#39;)
  }).generateToc()
);&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/6109591553705213635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/02/simple-python-program-to-add-two-numbers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6109591553705213635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/6109591553705213635'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/02/simple-python-program-to-add-two-numbers.html' title='Simple Python Program to Add Two Numbers'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/WYf7bNlw_4Y/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1961538785934969307.post-7691356490765529344</id><published>2022-01-04T15:11:00.008+05:30</published><updated>2022-01-07T13:57:45.726+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="C-Programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Pattern-Programs"/><title type='text'>Pattern In C Programming | C Program To Print Simple Pattern</title><content type='html'>&lt;!--wp:paragraph--&gt;
&lt;p&gt;In this program, we are going to make pattern in c programming using loops. It gives us a better understanding of the implementation of loops.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;Pre-requisite: For/While loop&lt;br /&gt;&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Half Pyramid Pattern in C&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In this program, we will print half pyramid of numbers. &lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:quote
&lt;blockquote class=&quot;wp-block-quote&quot;&gt;&lt;p&gt;1&lt;/p&gt;&lt;p&gt;1 2&lt;/p&gt;&lt;p&gt;1 2 3&lt;/p&gt;&lt;p&gt;1 2 3 4&lt;/p&gt;&lt;/blockquote&gt;--&gt;
&lt;samp&gt;
1&lt;br /&gt;
1 2&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3 4&lt;br /&gt;
&lt;/samp&gt;
&lt;!--/wp:quote--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In the above pattern. we can observe that there are four rows and ith row has i columns.  We will use 2 loops, the outer loop will iterate through rows and the inner loop will print numbers. It is also known as the triangular pattern in c.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:code--&gt;
&lt;pre class=&quot;wp-block-code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    
    int i=1;
    while(i&amp;lt;=4)
    {
        int j=1;
        while(j&amp;lt;=i){
            printf(&quot;%d &quot;,j);
            j++;
        }
        
        printf(&quot;\n&quot;);
        i++;
        
    }
    
    return 0;
}&lt;/pre&gt;
&lt;!--/wp:code--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Right Triangle Star Pattern in C&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg2wKAqVFKg1T_NaSO6kWDJBL9NCzgGEQ9PKziyT1hdIhl6NIMnw-xVeTvDFjvHYMGrbzopYX3Z48awsB7GBezsGmgBnwUJubpq436wO91Ke_0TAnZTGkACa--WbQqE1Ay9osEtOiS14nnvu_4q44gCK6_C3z6ivffmV_JV5Fr5JP8UDlQ6rNwt091b=s1080&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Pattern In C Programming&quot; border=&quot;0&quot; data-original-height=&quot;1080&quot; data-original-width=&quot;1080&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg2wKAqVFKg1T_NaSO6kWDJBL9NCzgGEQ9PKziyT1hdIhl6NIMnw-xVeTvDFjvHYMGrbzopYX3Z48awsB7GBezsGmgBnwUJubpq436wO91Ke_0TAnZTGkACa--WbQqE1Ay9osEtOiS14nnvu_4q44gCK6_C3z6ivffmV_JV5Fr5JP8UDlQ6rNwt091b=w320-h320&quot; title=&quot;Pattern In C Programming&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;In this program, we have to just print star &quot;*&quot; at the place of numbers.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:quote
&lt;blockquote class=&quot;wp-block-quote&quot;&gt;&lt;p&gt;*&lt;br&gt;* *&lt;br&gt;* * *&lt;br&gt;* * * *&lt;/p&gt;&lt;/blockquote&gt;--&gt;
&lt;!--/wp:quote--&gt;
&lt;samp&gt;
*&lt;br /&gt;
* *&lt;br /&gt;
* * *&lt;br /&gt;
* * * *&lt;br /&gt;
&lt;/samp&gt;
&lt;!--wp:heading {&quot;level&quot;:3}--&gt;
&lt;h3&gt;Pattern Program in C using for loop&lt;/h3&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:code--&gt;
&lt;pre class=&quot;wp-block-code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    
    int n=4;
    int i=1;
    
    for(int i=1;i&amp;lt;=n;i++)
    {
       for(int j=1;j&amp;lt;=i;j++)
       printf(&quot;* &quot;);
       printf(&quot;\n&quot;);
    }
    
    return 0;
}&lt;/pre&gt;
&lt;!--/wp:code--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Square Pattern Program in c using while loop&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In this program, we will print a square pattern in c using while loop. We will run two loops as usual one for rows and another one is to print star in columns.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;
&lt;samp&gt;
 * * * *&lt;br /&gt;
  
 * * * *&lt;br /&gt;
  
 * * * *&lt;br /&gt;
  
 * * * *&lt;br /&gt;
&lt;/samp&gt;

&lt;!--wp:code--&gt;
&lt;pre class=&quot;wp-block-code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    
    int n=4;
    int i=1;
    while(i&amp;lt;=n)
    {
        int j=1;
        while(j&amp;lt;=n){
            printf(&quot;* &quot;);
            j++;
        }
        
        printf(&quot;\n&quot;);
        i++;
        
    }
    
    return 0;
}&lt;/pre&gt;
&lt;!--/wp:code--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;C program to print alphabet pattern&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;This program is similar to a triangular pattern of numbers. In this example, we will print characters instead of numbers.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:paragraph--&gt;
&lt;samp&gt;
a&lt;br /&gt;
a b&lt;br /&gt;
a b c&lt;br /&gt;
a b c d&lt;br /&gt;
&lt;/samp&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:code--&gt;
&lt;pre class=&quot;wp-block-code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;

int main() {
    
    int n=4;
    int i=1;
    
    while(i&amp;lt;=n)
    {
        int j=1;
        char ch=&#39;a&#39;;
        while(j&amp;lt;=i){
            printf(&quot;%c &quot;,ch);
            ch++;
            j++;
        }
        
        printf(&quot;\n&quot;);
        i++;
        
    }
    
    return 0;
}&lt;/pre&gt;
&lt;!--/wp:code--&gt;
&lt;h2&gt; Triangular Pattern in c&lt;/h2&gt;

&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int i, j;
    for (i = 1; i &amp;lt;= 5; i++)
    {
        for (j = 1; j &amp;lt;= 9; j++)
        {
            if ((j &amp;lt;= 5 - i) || (j &amp;gt;= 5 + i))
            {
                printf(&quot; &quot;);
            }
            else
            {
                printf(&quot;*&quot;);
            }
        }
        printf(&quot;\n&quot;);
    }&lt;/pre&gt;&lt;div&gt;Output:&lt;/div&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; * &lt;br /&gt;&amp;nbsp; &amp;nbsp; *** &lt;br /&gt;&amp;nbsp; ***** &lt;br /&gt;&amp;nbsp;******* &lt;br /&gt;*********&lt;/p&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;About This C Program To Print Simple Pattern:&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;In conclusion, we made different pattern in c programming using for loop and while loop. However, if you have doubt or need code for a different pattern let me know in the comment section.&amp;nbsp; These programs give us a better clarity of loops, iterating through rows and columns.&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;

&lt;!--wp:heading--&gt;
&lt;h2&gt;Related Posts:&lt;/h2&gt;
&lt;!--/wp:heading--&gt;

&lt;!--wp:paragraph--&gt;
&lt;p&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/03/c-program-to-print-x-pattern.html&quot;&gt;C Program to Print X Pattern&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://www.codingwithsid.in/2020/03/c-program-to-print-diamond-pattern.html&quot;&gt;C program to print diamond pattern of numbers&lt;/a&gt;&lt;/p&gt;
&lt;!--/wp:paragraph--&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.codingwithsid.in/feeds/7691356490765529344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.codingwithsid.in/2022/01/pattern-in-c-programming.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/7691356490765529344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1961538785934969307/posts/default/7691356490765529344'/><link rel='alternate' type='text/html' href='http://www.codingwithsid.in/2022/01/pattern-in-c-programming.html' title='Pattern In C Programming | C Program To Print Simple Pattern'/><author><name>Siddharth Jha</name><uri>http://www.blogger.com/profile/08547574128078940880</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkx0NDgCko1gcwkai6IIkn6t8Xnxq3H1Y9CZdoDfRye2v7xBwRjJFUYnKUpVYAdnX2V6KoXg-OVLZb9RR6r2ZKnO-gqp56Ed-gZYMAIj1ErV0mMJhml4dHm7AlXnP0cw/s113/instpic.png'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEg2wKAqVFKg1T_NaSO6kWDJBL9NCzgGEQ9PKziyT1hdIhl6NIMnw-xVeTvDFjvHYMGrbzopYX3Z48awsB7GBezsGmgBnwUJubpq436wO91Ke_0TAnZTGkACa--WbQqE1Ay9osEtOiS14nnvu_4q44gCK6_C3z6ivffmV_JV5Fr5JP8UDlQ6rNwt091b=s72-w320-h320-c" height="72" width="72"/><thr:total>1</thr:total></entry></feed>