In this post, we are going to provide a salary breakup of a software developer engineer at Amazon India. All the components like base salary, relocation bonus, stocks and insurance are mentioned.

Company | Amazon |

Title | Software Development Engineer Intern |

Location | Banglore / Hyderabad / Gurgaon |

Stipend | Rs 1,10,000 per month + Rs 1,100 per month [Meal card] |

Relocation Bonus | 400 Euro |

Total compensation (Stipend + Bonus) | Rs 1,45,100 |

Sources: Leetcode and student of the 2024 batch.

Company | Amazon |

Title | Software Development Engineer-1 |

Location | Banglore / Hyderabad / Gurgaon |

Base Salary | INR 15.5 LPA |

Joining Bonus | 1st Year: 9.5 lakhs 2nd Year: 6 lakhs |

Stocks/RSU | 13 Lakhs [1st Year: 5%, 2nd Year: 15%, 2.5 Year: 20%, 3rd Year: 20%, 3.5 Year: 20%, 4th Year: 20%] |

Relocation Bonus | 1.5 lakhs |

Other Benefits | 1100 - Meal Coupons 1250 - Internet reimbursement 5 Lakhs - Medical Insurance 4x base - Life Insurance 3x base - Accidental Insurance (1500-4000) - Travel Allowance |

Total Compensation | 45.5 LPA |

This is all about Amazon Software Engineer Salary for Freshers. If you have any doubts let me know in the comment section

number=input("Enter any number :")

i=0

for i in range(len(number)):

if number[i]!=number[-1-i]:

print('It is not a palindrome')

break

else:

print('It is a palindrome')

Output:

`Enter any number:5665It is a palindrome`

In this program, we will take two pointers i and j. Variable "i" will point to the leftmost characters of the string and "j" will point to the rightmost character. If they are the same then will increase "i" 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. ## Using an inbuilt reversed function

### Approach to check whether the given string is palindrome or not using an inbuilt reversed function:

## Valid Palindrome leetcode accepted solution in python

## Q. What is a palindrome number in python?

** ****About this Palindrome Program in Python using for loop**

]]>str=input("Enter String: ")

i=0

j=len(str)-1

isPalindrome=True

while i<=j:

if(str[i]!=str[j]):

isPalindrome=False

break

i+=1

j-=1

if isPalindrome:

print(f"{str} is Palindrome.")

else:

print(f"{str} is not a Palindrome.")

Output:

`Enter String: racecarracecar is Palindrome. `

word=input("Enter any word :")

rev=reversed(word)

if list(word)==list(rev):

print('It is a palindrome')

else:

print('It is not a palindrome')

Output:

`Enter any word: madamIt is a palindrome`

- First, we input the string using the input() function.
- Using the reversed() function, we reverse the word entered by the user and assign it to a new variable called rev.
- Using the if statement, we compare the list(word) & list(rev). If they are the same, then we will print "it is a palindrome", and if they are not the same, we will print "it is not a palindrome".

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.

Prolem Link

import re

class Solution:

def isPalindrome(self, s: str) -> bool:

str1="".join(re.split("[^a-zA-Z0-9]*",s)).lower()

i=0

j=len(str1)-1

isPalindrome=True

while i<=j:

if str1[i]!=str1[j]:

isPalindrome=False

break

i+=1

j-=1

return isPalindrome

A number is a palindrome when its reverse is also the same as the original number.

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.

for example:8558, is a palindrome

Q. How do you write a palindrome program in python using for loop?

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.

Programs you may like:

Menu-driven program in python using while loop

Factorial Program in Python using for loop

Menu-driven program in python using while loop

Factorial Program in Python using for loop

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 progate app. You can download it via the google play store.

You can comment below or contact us if you have any queries related to this program. Thanks for reading this Palindrome program in python.

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't hesitate to contact me.

In this post, we will make a python program to check whether the given year is a leap year or not.

Leap Year: One year in every four has 366 days [February has 29 days instead of 28]. The reason why we have leap years is really fascinating, this video does more justice: Video Link

- Every year that is divisible by 4 and not divisible by 100.
- A year that is divisible by 4 and also divisible by 400.

In this program, we will check for leap year using simple if-else conditions.

year = int(input("Which year do you want to check? "))

if (year%4==0 and year%100!=0) or (year%4==0 and year%400==0):

print("Leap year.")

else:

print("Not leap year.")

Output:

`Which year do you want to check? 2022Not leap year.`

In this program, we will code solution for the leap year question at hackerrank.

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))

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 newsletter. Thank you so much for reading.

]]>In this program, we are going to make a python program to check even or odd number.

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.

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.

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.

number = int(input("Which number do you want to check? "))

if number%2==0:

print(f"{number} is an even number.")

else:

print(f"{number} is an odd number.")

Related Post: Prime Number Program in Python using while loop

Last bit of every odd number is set, so if we perform "&" operation between odd number and 1(whose last bit is set "001") it comes out to a one otherwise it is zero.

number = int(input("Which number do you want to check? "))

if number&1:

print("This is an odd number.")

else:

print("This is an even number.")

This is all about this post, if you have doubts let me know in the comment section. Please rate well in feedback form.

]]>Dwight is always bragging about how amazing he is at solving complicated problems with much ease. Jim got tired of this and gave him an interesting problem to solve.

Jim gave Dwight a sequence of integers a1, a2, ..., an and q queries x1, x2, ..., xq on it. For each query xi Dwight has to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and GCD(al, al + 1, ..., ar) = xi. Dwight is feeling out of his depth here and asked you to be his Secret Assistant to the Regional Manager. Your first task is to help him solve the problem. Are you up to it?

Given a sequence of integers a1, ..., an and q queries x1, ..., xq on it. For each query xi, you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(al, al + 1, ..., ar) = xi. The GCD Dillema.

#include <iostream>Minimum In Subarray Segment Tree

#include <map>

#include <vector>

using namespace std;

int gcd(int a, int b) {

if (a % b == 0) return b;

return gcd(b, a % b);

}

int main() {

ios_base::sync_with_stdio(false);

int n; cin >> n;

vector<int> v(n);

for(int i=0;i<n;i++)

cin>>v[i];

map<int, long long> results;

map<int, int> divisors;

map<int, int> nextDivisors;

for (int i = 0 ; i < n ; i++)

{

nextDivisors.clear();

for (auto &p : divisors)

{

nextDivisors[gcd(p.first, v[i])] += p.second;

}

nextDivisors[v[i]]++;

swap(nextDivisors, divisors);

for (auto &p : divisors)

results[p.first] += p.second;

}

int q; cin >> q;

while (q --> 0) {

int x; cin >> x;

cout << results[x] << endl;

}

}

Palindrome Partitioning GFG Solution]]>

In this post, we will provide solutions for Day 1 striver sde sheet.

class Solution {

public:

void setZeroes(vector<vector <int>>& matrix) {

int r=matrix.size(),c=matrix[0].size();

vector<int> rows(r,0),cols(c,0);

for(int i=0;i<r;i++)

{

for(int j=0;j<c;j++)

{

if(matrix[i][j]==0)

{

rows[i]=1;

cols[j]=1;

}

}

}

for(int i=0;i<r;i++)

{

for(int j=0;j<c;j++)

{

if(cols[j]==1||rows[i]==1)

{

matrix[i][j]=0;

}

}

}

}

};

class Solution {

public:

vector<vector<int>> generate(int numRows) {

vector<vector<int>> ans(numRows);

for(int i=0;i<numRows;i++)

{

ans[i].resize(i+1,1);

for(int j=0;j<=i;j++)

{

if(j==0||j==i) continue;

ans[i][j]=ans[i-1][j-1]+ans[i-1][j];

}

}

return ans;

}

};

In this program, we are going to make a c++ program for next permutation.

Credits: Striver SDE Sheet

A man named Narayana Pandita presented the following algorithm to solve the next permutation problem in the 14th century.

- Find the largest index "ind" such that nums[ind]<nums[ind+1]. If there is no such index exist just reverse the array and return.
- Find the largest index j>ind such that nums[ind]<nums[j].
- Swap (nums[ind],nums[j]);
- Reverse the subarray on the right side of nums[ind]. {reverse(nums.begin()+ind+1,nums.end());}

class Solution {

public:

void nextPermutation(vector<int>& nums) {

int n=nums.size();

int ind=-1;

for(int i=n-2;i>=0;i--)

{

if(nums[i]<nums[i+1])

{

ind=i;

break;

}

}

if(ind==-1) {

reverse(nums.begin(),nums.end());

return;

}

for(int j=n-1;j>ind;j--)

{

if(nums[j]>nums[ind])

{

swap(nums[j],nums[ind]);

break;

}

}

reverse(nums.begin()+ind+1,nums.end());

}

};

In this program, we just coded the algorithm for next permutation given by Narayana Pandita.

In this question, we have to return the maximum subarray sum.

class Solution {

public:

int maxSubArray(vector<int>& nums) {

int curr=0,ans=INT_MIN;

for(auto it:nums)

{

curr+=it;

ans=max(ans,curr);

if(curr<0)

curr=0;

}

return ans;

}

};

void sortColors(vector<int>& nums) {

int i=0,j=0,k=nums.size()-1;

while(j<=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]);

}

}

int maxProfit(vector<int>& prices) {

int mn=prices[0],ans=0;

for(auto it:prices)

{

ans=max(ans,it-mn);

mn=min(it,mn);

}

return ans;

}

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. [course]

]]>In this post, I will share information about the giveaway of web development course by Angela Yu.

Course: The Complete 2022 Web Development Bootcamp on Udemy

Become a Full-Stack Web Developer with just ONE course. HTML, CSS, JavaScript, Node, React, MongoDB, Web3 and DApps

Steps to take part in this giveaway:

- Comment below, why do you need this course and your Instagram account.
- Follow Our Instagram account: CodingwithSid
- Subscribe to our newsletter

Send your giveaway entries at https://instagram.com/codingwithsid_. Good luck :)

]]>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.

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.

Problem link: Leetcode

int subarraySum(vector<int>& nums, int k) {

int sum=0,ans=0;

unordered_map<int,int> mp;

mp[0] = 1; // we always have 1 sum of zero, which is sum of none.

for(int i=0;i<nums.size();i++)

{

sum+=nums[i];

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

}

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.

Time complexity for finding the number of subarrays sum equals k: O()N^{3}

#include<iostream>

using namespace std;

int main()

{

int arr[1000], k, n, ksum, currentsum, count = 0;

cout<<"\n Enter number of elements:";

cin>>n;

cout<<"\n Enter array elements:";

for (int i = 0; i < n; i++)

{

cin>>arr[i];

}

cout<<"\n Subarray sum equals:";

cin>>ksum;

for (int i=0; i<n; i++)

{

for(int j = i; j < n; j++)

{

currentsum=0;

for(int k = i; k <= j; k++)

{

currentsum+= arr[k];

}

if ( currentsum == ksum)

count++;

}

}

cout<<"Total no. of subarray sum equals "<<ksum<<" is ";

cout<<count;

return 0;

}

Output:

`Enter the number of elements:9Enter array elements:-4 1 3 -2 6 2 -1 -4 -7Subarray sum equals:10Total no. of subarray sum equals ten is 1`

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.

We used three nested loops in the last method, and the processor will do work that is proportional to *N*^{ 3}. 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 *N*^{ 2}.

The time complexity for finding the count of subarrays sum equals k using cumulative sum: O()N^{ 2}

#include<iostream>

using namespace std;

int main()

{

int arr[1000], k, n, ksum, currentsum, count = 0,cumulativesum[1000]={0};

cout<<"\n Enter number of elements:";

cin>>n;

cout<<"\n Enter array elements:";

cin>>arr[0];

cumulativesum[0]=arr[0];

for (int i = 1; i < n; i++)

{

cin>>arr[i];

cumulativesum[i] = cumulativesum[i-1] + arr[i];

}

cout<<"\n Subarray sum equals:";

cin>>ksum;

for (int i=0; i<n; i++)

{

for(int j = i; j < n; j++)

{

currentsum=0;

currentsum = cumulativesum[j] - cumulativesum[i-1];

if ( currentsum == ksum)

count++;

}

}

cout<<"Total no. of subarray sum equals "<<ksum<<" is ";

cout<<count;

return 0;

}

Related posts:

]]>

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.

In this program, we will take the input number from the user. We will take another variable which will store the reverse number.

We will take the modulus of the current number by 10, which gives the unit digit of the current number. We will multiply the "reversed number" by ten and add the unit digit. At last, we will divide the current number by 10.

We will do this process till the current number is greater than zero.

#include<stdio.h>

int main()

{

int i, n, remainder, rev=0;

printf("\n Enter a number:");

scanf("%d",&n);

for(i=n;i>0;i=i/10)

{

remainder=i%10;

rev=rev*10+remainder;

}

if(rev==n)

printf("\n It is a palindrome");

else

printf("\n It is not a palindrome");

return 0;

}

Related Post: String palindrome program in c

#include<stdio.h>

int main()

{

int i, n, r, s = 0;

printf("\n Enter a number:");

scanf("%d", &n);

i = n;

while (i > 0)

{

r = i % 10;

s = (s * 10) + r;

i = i / 10;

}

if (s == n)

printf("\n It is a palindrome");

else

printf("\n It is not a palindrome");

return 0;

}

#include<stdio.h>Output:

int palindrome(int a);

int main()

{

int b, c;

printf("\n Enter a number:");

scanf("%d", &b);

c = b;

c = palindrome(c);

if (b == c)

printf("%d is a palindrome", b);

else

printf("%d is not a palindrome", b);

return 0;

}

int palindrome(int a)

{

int i, r, s = 0;

i = a;

while (i > 0)

{

r = i % 10;

s = (s * 10) + r;

i = i / 10;

}

return s;

}

To check palindrome, we have to check its reverse should also equal to it.

For example:7227 is a palindrome as its reverse is also 7227.

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.

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 & if they are not identical, then we print the number entered by the user as not a palindrome.

String palindrome program in c

Related Posts:

C program to find the greatest number among three numbers

Odd and even number program in c

C program to find the greatest number among three numbers

Odd and even number program in c

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.

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.

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.

#include <stdio.h>

#include <string.h>

int main()

{

char str[30];

int n = 0, flag = 0, i = 0, j = 0;

printf("Enter String:");

scanf("%s", &str);

n = strlen(str);

for (i = 0, j = n - 1; i <= j; i++, j--)

{

if (str[i] != str[j])

{

flag = 1;

break;

}

}

if (flag == 1)

printf("No, it is not a palindrome");

else

printf("Yes, it is a palindrome");

return 0;

}

Output:

`Enter String: saippuakivikauppiasYes, it is a palindrome Enter String: codingwithsidNo, it is not a palindrome `

- Input string from user and store it in a character array.
- Using for loop, we compare the corresponding elements of the character array. For this, we use the following statement.str[i]==str[j];
- We will compare the first letter with the last letter, and second letter with the last-second letter and so on.
- If they mismatch, we break the loop and mark the flag with one.
- Now, if the flag's value is one, we will print it is not a palindrome; otherwise, the given string is a palindrome.

In this program, we will check whether the given string is palindrome or not.

#include <stdio.h>

#include <string.h>

int main()

{

char str[30];

int n = 0, isPalindrome = 1, i = 0, j;

printf("Enter String:");

scanf("%s", &str);

n = strlen(str);

j=n-1;

while(i<j)

{

if(str[i]!=str[j])

{

isPalindrome=0;

break;

}

i++;

j--;

}

if (isPalindrome == 0)

printf("%s is not a palindrome",str);

else

printf("%s is a palindrome",str);

return 0;

}

Output:

`Enter String: racecarracecar is a palindrome Enter String: souravjoshisouravjoshi is not a palindrome `

How do you check if a String is a palindrome in c?

To check whether the string is a palindrome or not, you can use a for loop statement which is given below

for (i = 0, j = n - 1; i <= j; i++, j--)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.

{

if (str[i] != str[j])

{

flag = 1;

break;

}

}

Madam

c[0]=c[4]; c[1]=c[3]; c[2]=c[2];

It is a program to check whether the number is a palindrome.

To check palindrome, we have to check its reverse should also equal it.

for example:7227 is a palindrome as its reverse is also 7227 check out this post- palindrome program in c

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.

]]>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.

Related posts:

If you are unable to run this program or getting an error, let me know in the comment section. You can also message us on our Instagram account.

- Menu-Driven Program for Array Operations in C++
- Menu-driven program in c++ using switch case and do-while loop
- Calculator program in C using Switch Case

#include<stdio.h>

int main()

{

int choice, radius, length, breadth, side;

float area;

printf("\n Press 1 to calculate area of Circle \n Press 2 to calculate area of Rectangle \n Press 3 to calculate area of Square \n Press 4 to Exit");

printf("\n Enter your choice:");

scanf("%d",&choice);

switch(choice)

{

case 1: printf("\n Enter radius:");

scanf("%d",&radius);

area=3.14*radius*radius;

printf("\n Area of circle: %f",area);

break;

case 2: printf("\n Enter length:");

scanf("%d",&length);

printf("\n Enter breadth:");

scanf("%d",&breadth);

printf("\n Area of rectangle: %d",length*breadth);

break;

case 3: printf("\n Enter Side:");

scanf("%d",&side);

printf("\n Area of square: %d",side*side);

break;

case 4: return 0;

default: printf("\n wrong choice");

}

return 0;

}

Output:

` Press 1 to calculate the area of Circle Press 2 to calculate the area of RectanglePress 3 to calculate the area of Square Press 4 to ExitEnter your choice:1Enter radius:5Area of circle: 78.500000 `

Menu-driven program in c using switch case and do-while loop which performs the following operations:

#include<stdio.h>

int main()

{

char fav; int num=0,choice=1,fact=1,i;

printf("\n Enter a Number:");

scanf("%d",&num);

do

{

printf("\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"); printf("\n Enter your choice:");

scanf("%d",&choice);

switch(choice)

{

case 1: for(i=num;i>1;i--)

fact*=i;

printf("\n Factorial of %d",num);

printf(" is %d",fact);

break;

case 2:for(i=2;i<num;i++)

{

if(num%i==0)

{

printf(" \n %d is not a prime number",num);

break;

}

}

if(num==i)

printf("%d is a prime number",num);

break;

case 3: if(num%2==0)

printf("%d is an even number",num);

else

printf("\n %d is an odd number",num);

break;

case 4: return 0;

default: printf("\n wrong choice");

}

printf("\n Do you want to continue?(y/n)\n");

scanf("\n %c",&fav);

}while(fav=='y');

return 0;

}

- Initialize
*three int variables*and a*one-character variable*. - Now take the number from the user and store it in an
*int variable*. - Now print all the choices on the screen and take the choice of the user using another
*int variable*. - Using statement
*switch(choice)*, the*choice*is an*int variable*that contains the choice of the user. (you can write any valid identifier) - Make statements of
*case 1, case 2, case 3,*etc using for loop and if-else statement, and**at the end of every case statements write a break**. So that it doesn’t go for the next statement. - Write a
*default statement*in case the user enters the wrong choice. - Now display a message on the screen that do you want to continue?
- If the user wants to continue then they should press y.
- Take the input from the user in the character variable and
*don’t forget to press space between*and__“__in the scanf statement.__%__ - In the end, you have to write the testing statement for the do-while loop.

#include <stdio.h>If you are looking for a Menu-driven program for matrix operations in c using if-else, let me know in the comment section.

int main()

{

int C[10][10], A[10][10], B[10][10], i, j, ch, rows, cols,l;

printf("Menu-driven program for matrix operations in c");

printf("\n Enter Rows:");

scanf("%d", &rows);

printf("\n Enter Columns:");

scanf("%d", &cols);

printf("\n Matrix A\n");

printf("\n Enter the numbers you want to insert in the matrix A:");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

printf("\t");

scanf("%d", &A[i][j]);

}

}

printf("\n Matrix A:\n");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

printf("%d", A[i][j]);

printf("\t");

}

printf("\n");

}

printf("\n Enter the numbers you want to insert in the matrix B:");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

printf("\t");

scanf("%d", &B[i][j]);

}

}

printf("\n Matrix B:\n");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

printf("%d", B[i][j]);

printf("\t");

}

printf("\n");

}

printf("\n 1. Addition of Matrix A & B ");

printf("\n 2. Subtraction Of Matrix A and matrix B n");

printf("\n 3. Multiplication of Matrix A & B");

printf("\n Enter your choice (1 ,2,3):");

scanf("\n %d", &ch);

switch (ch)

{

case 1:

printf("\n A+B=\n");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

C[i][j] = A[i][j] + B[i][j];

printf("%d", C[i][j]);

printf("\t");

}

printf("\n");

}

break;

case 2:

printf("\n A-B=\n");

for (i = 0; i < rows; i++)

{

for (j = 0; j < cols; j++)

{

C[i][j] = A[i][j] - B[i][j];

printf("%d", C[i][j]);

printf("\t");

}

printf("\n");

}

break;

case 3:

printf("\n A*B=\n");

for (i = 0; i < rows; i++)

{

for (j = 0; j < rows; j++)

{

C[i][j] = 0;

for (l = 0; l < cols; l++)

{

C[i][j] = C[i][j] + A[i][l] * B[l][j];

}

printf("%d", C[i][j]);

printf("\t");

}

printf("\n");

}

break;

default:

printf("\n Wrong Choice");

}

return 0;

}

Output:

`Matrix A:1 23 4 Matrix B:1 23 4 1. Addition of Matrix A & B2. Subtraction Of Matrix A and matrix B3. Multiplication of Matrix A & BEnter your choice (1, 2, 3):1A+B=2 46 8 `

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. The second program is an answer to one of the most important questions that arise in the book "Let Us C" by Yashwant Singh Kandari.

If you like this then please comment below to support us and you can freely ask your doubts in the comment section.

This program will clear your concepts about switch case programs, do-while loop, for loop, if-else statement, and exit function.

Important note about taking the value of character from a user in c using scanf **press space between **__“__ and *%* means you have to use the following statement:

]]>scanf(“%c”,&ch)This is the wrong statement but this error is ignored by the compiler when you compile this statement in your program, it will not show any errors regarding this. Moreover, when you execute your program this statement will not be executed. Therefore you have to

scanf(“ %c”,&ch)

In this post, we are going to make the Prime number program in c in the most straightforward way to understand.

We will be using the while, for, and do-while loop.

At last, I made a program to check whether the number is prime or "not" using a function.

E.g. 2,3,5,7,11 etc.

In this program, we have used a function to check the Prime number in C. Return type of this function is bool type.

It will return 1 if the number is prime and 0 if the number is not prime.

In the "isPrime" function, we checked that this number is divisible by any number smaller than or equal to the square root of this number "n".

The **Time complexity** of this program is O(sqrt(n)).

#include<stdio.h>

#include<stdbool.h>

bool isPrime(int n){

if(n==1)

return false;

for(int i=2;i*i<=n;i++){

if(n%i==0)

return false;

}

return true;

}

int main() {

int n;

scanf("%d",&n);

printf("%d",isPrime(n));

return 0;

}

If you are unable to run this program or getting an error, let me know in the comment section.

If you need more optimized code for this topic, You can message us on our Instagram account. We will send you a meet link on Instagram and teach you each and every line of code for free of cost.

0

Read Also:

C++ program to print prime numbers up to n

Prime Number Program in C++

Factorial Program in c using for loop

In this program, we are going to check whether the number is prime or not using a while loop.

#include<stdio.h>

int main()

{

int num,i=2;

printf("\n Enter a number:");

scanf("%d",&num);

while(i<num)

{

if(num%i==0)

{

printf("\n %d is not a prime number",num);

break;

}

i++;

}

if(i==num)

printf("\n %d is a prime number",num);

return 0;

}

Output:

### Approach to check number entered by the user is a prime number or not using the while loop:

## C program to check whether a number is prime or not using a do-while loop

**Output:**

Enter a number:6

6 is not a prime number

### Approach to determine whether the number is prime or not using a do-while loop:

## Write a program to check if a given number is prime or not using for loop

**Output:**

Enter a number:11

11 is a prime number

### Approach to determine whether the number is prime or not using for loop:

## Prime number program in c using function

Output:

Enter a number:12

12 is not a prime number

### Approach to determine whether the number is prime or not using functions:

**About this post:**

This post is written by*Coding Wallah*. It is a bit difficult, 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.

If you are having issues with these programs please comment below.

Recommended post:

Odd and even numbers program in c

Simple calculator program in c using switch case

Matrix program in c using array

]]>- We will declare two integer numbers one is num and another is i.
- we will initialize i with 2 and the value of num is entered by the user.
- Using a while loop, we will compare the remainder when the num is divided by all those numbers which are lesser than that number.
- if num%i comes to zero it means that the number entered by the user is not a prime number.
- If the value of num is equal to i then it is a prime number.

#include<stdio.h>

#include<conio.h>

int main()

{

int num,i=2;

clrscr();

printf("\n Enter a number:");

scanf("%d",&num);

do

{

if(num%i==0)

{

printf("\n %d is not a prime number",num);

break;

}

i++;

}while(i<num);

if(i==num)

printf("\n %d is a prime number",num);

getch();

return 0;

}

Enter a number:6

6 is not a prime number

- We declare an integer number and initialize its value from the user.
- We are using a do-while loop to check whether the number is prime or not.
- 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, it means that the number is divisible by another number. Hence, it is not a prime number because it is divisible by another number.
- We print it is not the prime number.
- if the value of i equals the number entered by the user then we will print it as a prime number.

#include<stdio.h>

#include<conio.h>

int main()

{

int num,i;

clrscr();

printf("\n Enter a number:");

scanf("%d",&num);

for(i=2;i<num;i++)

{

if(num%i==0)

{

printf("\n %d is not a prime number",num);

break;

}

}

if(i==num)

printf("\n %d is a prime number",num);

getch();

return 0;

}

Enter a number:11

11 is a prime number

- First, we declare an integer number.
- Initialize its value from the user using scanf.
- Now we are using for loop to divide that number from all those below that number and check the remainder.
- Use the if statement to check the remainder. If the remainder comes to zero, it means that the number is divisible by another number.
- We have to print that the number entered by the user is not the prime number.
- If the value of i equals the number entered by the user then we will print it as a prime number.

#include<stdio.h>

#include<conio.h>

void prime(int a);

int main()

{

int num;

clrscr();

printf("\n Enter a number:");

scanf("%d",&num);

prime(num);

getch();

return 0;

}

void prime(int a)

{

int i=2;

while(i<a)

{

if(a%i==0)

{

printf("\n %d is not a prime number",a);

break;

}

i++;

}

if(i==a)

printf("\n %d is a prime number",a);

}

Output:

Enter a number:12

12 is not a prime number

- We declare an integer number and initialize its value from the user in the main function.
- We will call our function to check, whether the number is prime or not.
- In the prime function, we declare int i=2.
- Using a while loop, we will check number is prime or not.
- We will compare the remainder with zero when we divide that number by all those numbers which are less than that number and if the remainder is zero. It means that this number is also divisible by another number.
- Else it will print it is a prime number.

This post is written by

If you are having issues with these programs please comment below.

Recommended post:

Odd and even numbers program in c

Simple calculator program in c using switch case

Matrix program in c using array

In this program, we have a number given by the user and we have to print whether that number is prime or not.

In this program, we will find whether the number is prime or not. We will use while to check that the given number is divisible by any number between 2 and one less than the given number

num=int(input("Enter a number: "))

check=True

i=2;

while i<num:

if(num%i==0):

check=False

break

i+=1

if(check and num!=1):

print(str(num)+" is a Prime Number")

else:

print(str(num)+" is not a Prime Number")

Output:

` Enter a number: 1616 is not a Prime Number`

Read also: Python Programs for Practice

In this program, we are going to make a python program to check prime numbers. It will print whether the given number is prime or not.

# check given number is prime or not

num=int(input("Enter a number: "))

check=True

for i in range(2,num):

if(num%i==0):

check=False

break

if(check and num!=1):

print(str(num)+" is a Prime Number")

else:

print(str(num)+" is not a Prime Number")

Output:

` Enter a number: 997997 is a Prime Number Enter a number: 1515 is not a Prime Number `

we are going to write a python program to find whether a given number is prime or not.

Prime Number is a number which is divisible only by one and itself.

let's take a number here so let's say 11:

We will try to divide this number by 2 because all the numbers are divisible by 1 so let's start with 2 so we check if 11 can be divided by 2 if yes then it's not a prime number if it's not divisible then we'll go for 3 then we'll go for 4 and so on till 10.

Read also: Factorial Program in Python

We start from 2 and we'll end with minus 1 so example if we take a number which is 17 so you will end at 16.

Every time you have to check if you find the number if it is divisible you can simply print not a prime number. When we find that the given number is also not divisible by the last number (which is number-1). Then, we can print a prime number.

Prime Number is a number which is divisible only by one and itself.

let's take a number here so let's say 11:

We will try to divide this number by 2 because all the numbers are divisible by 1 so let's start with 2 so we check if 11 can be divided by 2 if yes then it's not a prime number if it's not divisible then we'll go for 3 then we'll go for 4 and so on till 10.

Read also: Factorial Program in Python

We start from 2 and we'll end with minus 1 so example if we take a number which is 17 so you will end at 16.

Every time you have to check if you find the number if it is divisible you can simply print not a prime number. When we find that the given number is also not divisible by the last number (which is number-1). Then, we can print a prime number.

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.

]]> **Excerpt:** Do you know which programming language the most recent and rapidly growing web development is? 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.

Python is a powerful programming language for data scientists, artificial intelligence (AI), machine learning (ML), and data scientific computing. Python is expected to surpass Java and C# shortly, implying far more.

Python has grown much more throughout the last five years, by 19.0%, as per the Popularity of Programming Language Index.

Python offers a wide range of frameworks to developers. It has played a significant role in web development for over two decades, from great web frameworks to micro-frameworks. 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 go over some of the best Python frameworks for 2022 that web developers and programmers should use to improve site speed and time-to-market.

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's ready-made components rather than trying to write similar code for each project. This mostly saves time and money, but it also shortens the time to market.

Python supports modules and packages, promoting methods and practices and the reusability of code. 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.

Looking forward to making a move to the Programming field? Take up the Python Online Training and begin your career as a professional Python programmer.

It's difficult to discuss web development frameworks without mentioning Django. Django, which was first released in 2005, is one of Python'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 build complex code and apps quickly. The Django framework aids in the development of high-quality web applications. It is one of the finest Python frameworks for developing APIs and web applications rapidly.

It was originally envisioned as an engine to assist developers in creating content-based websites. Nonetheless, developers have used this to power a wide range of applications and services ever since its official launch. 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.

- URL system that is both simple and powerful.
- Object-oriented programming language database with the best data storage and recovery capabilities.
- The automatic admin interface service allows for the customization of editing, adding, and deleting items.
- Integrated authentication system
- A cache framework is a collection of cache mechanisms

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 useful. Pyramid frameworks are adaptable and can be used for both simple and complex projects. Because of its clarity and measured quality, it's also the most appreciated web framework among many experienced Python developers.

One of Python's most valuable assets as a developer language is its community support, which is 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.

- URL surveying based on Routes configuration via URL dispatch and HTML structure
- validation and generation by Web Helpers.
- Complete templating and asset details
- Capability to work very well with larger and smaller applications
- Testing, support, and detailed data documentation
- Authentication and approval are both flexible.

CherryPy, now nearly ten years old, has proven to be incredibly fast and stable. It is a Python web development framework that includes its very own 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're an intermediate developer looking to try something new. Whereas advanced developers may discover its features insufficient, it allows beginners to gain experience with Python prior to going deep into more complex frameworks.

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.

CherryPy's main attraction would be that it makes it possible to run its code without relying on other people or services.

- It is simple to run multiple HTTP servers (for example, on multiple ports) at the same time.
- Python 2.7+, 3.5+, PyPy, Jython, and Android
- support Built-in tools for the encryption process, sessions, prefetching, authorization, static content, and more
- A robust configuration system for both developers and deployers.
- Profiling, coverage, and testing are all built-in.

Developers can select from a wide range of network and impartial libraries based on the task requirements. Grok'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.

- Grok constituent architecture assists developers in reducing development unpredictability.
- Establishes the basis and other assets required to create custom web applications for business needs.
- Provides a solid foundation for building powerful and versatile web applications.
- Allows web developers to take advantage of Zope 3's power.
- A robust object database for backups.
- Integrated security to protect your application and grant specific access to users

Flask has become one of Python's greatest major web frameworks, and it is also one of the language's most rapidly growing tools. Flask is easy to learn, elegant has a large 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.

Large corporations are using Flask. Flask is now a Python framework that is available under the BSD license.

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.

- Support for integrated unit testing (code with quality).
- Jinja2 templating is used (tags, filters, macros, and more).
- WSGI 1.0 is compliant with the letter.
- The community has provided several extensions to help incorporate advanced functionalities.
- Integrated development server and debugger.
- Request dispatching via REST.

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 it possible for scalability and ease of maintenance, is one of its big selling points.

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.

- All of the features are implemented as function decorators.
- Support for multiple databases.
- Command-line tools are available.
- Integration of the MochiKit JavaScript library.
- MVC architecture with Paste Script templates
- Tosca Widgets to help with frontend design and server deployment coordination.

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. Web2py'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.

- It includes Useful Batteries for quickly building a variety of web apps without the need for third-party tools and services.
- Maintains the security of web applications by attempting to address top security flaws and security issues.
- Supports configuration agreements and enables rapid web development.
- Claims to support MVC architecture to make web development easier.
- Allows developers to use widely utilized relational and NoSQL databases.
- Web-based IDE for web development projects such as cleaning temporary files, proofreading app files, running trials, and browsing previous tickets.

A bottle could be used out of another box with no knowledge of web programming if you want to add a few really fast 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 originally designed for creating web APIs. The Bottle also attempts to start executing it all in a single site document, and it is only dependent on the Python Standard Library.

Flask'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 important to you.

- The simple syntax allows for spotless and dynamic URL routes for mapping.
- Constructed template engine and backing that is quick and pythonic.
- It is simple to use the WSGI framework with CGI and the WSGI internals.
- Allows for convenient access to data, cookies, file uploads, and other HTTP-related metadata.
- Worked as an HTTP server and as a backend for glue, fapws3, flip, or another WSGI-capable HTTP server.

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 Quixote. 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.

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,' Quixote is really for them.

- It is compatible with just about any web server which supports CGI or Fast CGI.
- Mod python is supported by Apache.
- SCGI protocol support is also available.
- With session management API, the design is simple and flexible.
- A function library to help with the development and assessment of an HTML form.

Python'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 percent of web developers. The appropriate web framework must be chosen based on the project'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 favorite Python frameworks? Do let us know.

Amruddin Shaik is a Digital Marketer and Content Contributor, Who is working with MindMajix, 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.

]]>Resources will be mostly the videos playlist present on Youtube, and once you are done with the videos start solving questions of that topic on leetcode, so that you get a clear understanding of that topic.

- Array and Strings
- Multidimensional Arrays (2D)
- Recursion and Backtracking
- Sorting Algorithms
- Divide and Conquer (Binary Search and its Applications)
- Linked Lists
- Stacks and Queues
- Binary Trees and Binary Search Trees
- Priority Queues and Heaps (Implementation also)
- General Trees and Graphs
- Dynamic Programming.

Other Concepts:

- Hashmap
- Bit manipulation
- Greedy.
- Tries
- Number theory (Sieve, Prime factorization, etc)
- String Algorithm (KMP and Z algorithm)
- Sliding Window

For theory purposes, refer to courses from Coding Ninjas. (There are plenty of free alternatives also)

If you want to do a DSA course online, then you should enrol in the best dsa course by coding ninjas.

I would like 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 Click here to buy this course.

**Best Doubt solving**: You can ask as many doubts as you want. TA's will solve your doubt by chat, call and meeting(Screen sharing).**Awesome Teachers**: You will master all DSA topics by studying from them. Every topic has 10-15 problems that you will code yourself with the help of a TA (if needed).

Ankush Sir will teach you recursion and you will become an expert in that topic. Then, it will be a cakewalk for you to solve dynamic programming & graph questions.**Free Goodies**: You will get a coding ninjas bag & T-shirt after one-two month from the buying date. When you complete 90% of the course, then you may receive a coding ninjas bottle, diary and certificate.**Paid Internship Opportunity**: After completion of the dsa course, you can apply for the TA test. If you pass that coding test then you will become a Teaching Assistant at coding ninjas.**Topics have a deadline**: You have to complete your topics before the deadline. If you fail in doing so, your score will decrease.

But, they have a course pause option if you are struggling with deadlines. You can use this feature to extend the deadline. It will help you to complete the course successfully.

I would like to update you about the Sale. If you purchase a course today, you shall get a flat 40% discount (30% Early Bird + 10% from my side) on the course Click here to buy this course.

If you have any doubts let me know in the comment section. You can also ask your doubts on my Instagram account.

## How to get Coding Ninjas Courses for Free

]]>Coding ninjas conduct scholarship exams. If you are interested in their courses but did not enrol in it. Do the prices of our course seem high to you? They have the perfect opportunity!

The CNSAT gives you a chance to win a 100% Scholarship. If you win a 100% scholarship, then you will get Coding Ninjas Courses for Free.

For Practice:

- Beginners in problem-solving: Refer to CN Platform Codestudio (For Theory and Beginners Questions)
- Intermediate in problem-solving: You can refer to the DSA sheet prepared by Love Babbar (sheet link)(Side by side you can start giving contests on CP platforms- ATCODER, CODEFORCES, CODECHEF)
- You can also practice DSA questions on leetcode. It is an awesome website for practice purposes, you can also follow their study plan.

Related Posts:

In this post, we are going to make a **Python Program to Convert Celsius to Fahrenheit.** C° to F°: Formula to convert Celsius to Fahrenheit

F=1.8C+32

Multiply the given degree Celsius temperature by 1.8 and add 32.

For example: let the temperature is 50-degree Celsius.(50°C × 1.8) + 32 = 122°F

celsius=input("Enter Temperature in Degree Celsius: ")

celsius=int(celsius)

fahrenheit=(1.8*celsius)+32

print("Temperature in Fahrenheit: ",fahrenheit)

Output:

`Enter Temperature in Degree Celsius: 33Temperature in Fahrenheit: 91.4 `

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.

Related Post:

Python program for Fibonacci series

Python program for simple interest

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.

Pre-requisite:

- Loops
- Add Strings

Output:

`Input: num1 = "80", num2 = "2"Output: "160" `

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.

#include <bits/stdc++.h>

using namespace std;

class Solution

{

public:

string addStrings(string &num1, string &num2)

{

int n = num1.size() - 1;

int m = num2.size() - 1;

string s;

int carry = 0;

int x1, x2, value;

while (n >= 0 || m >= 0)

{

if (n >= 0)

{

x1 = num1[n] - '0';

}

else

x1 = 0;

if (m >= 0)

{

x2 = num2[m] - '0';

}

else

x2 = 0;

value = (x1 + x2 + carry) % 10;

carry = (x1 + x2 + carry) / 10;

s.push_back(value + '0');

n--;

m--;

}

if (carry != 0)

s.push_back(carry + '0');

reverse(s.begin(), s.end());

return s;

}

string multiply(string num1, string num2)

{

vector<string> sum;

int m = num2.size() - 1;

int last = 0;

while (m >= 0)

{

string s;

int carry = 0;

int x1, x2, value;

int n = num1.size() - 1;

while (n >= 0)

{

x1=num1[n]-'0';

x2=num2[m]-'0';

value = (x1 * x2 + carry) % 10;

carry = (x1 * x2 + carry) / 10;

s.push_back(value + '0');

n--;

}

if (carry != 0)

s.push_back(carry + '0');

reverse(s.begin(), s.end());

int temp = last;

while (temp--)

s.push_back('0');

last++;

sum.push_back(s);

m--;

}

string ans = "0";

for (auto str : sum)

{

ans = addStrings(ans, str);

}

if (ans[0] == '0')

{

int i = 1;

while (i < ans.size() && ans[i] == '0')

{

ans.erase(ans.begin() + i);

// i++;

}

}

return ans;

}

};

int main()

{

Solution s;

string str1,str2;

cout<<"Enter First String:";

cin>>str1;

cout<<"Enter Second String:";

cin>>str2;

cout<<s.multiply(str1,str2)<<endl;

}

In my childhood, my grandfather used to give me multiplication of numbers that have more than 10 digits so that I can'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.

]]>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.

Pre-requisite:

- Loops
- Add Strings

Output:

`Input: num1 = "80", num2 = "2"Output: "160" `

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.

#include <bits/stdc++.h>

using namespace std;

class Solution

{

public:

string addStrings(string &num1, string &num2)

{

int n = num1.size() - 1;

int m = num2.size() - 1;

string s;

int carry = 0;

int x1, x2, value;

while (n >= 0 || m >= 0)

{

if (n >= 0)

{

x1 = num1[n] - '0';

}

else

x1 = 0;

if (m >= 0)

{

x2 = num2[m] - '0';

}

else

x2 = 0;

value = (x1 + x2 + carry) % 10;

carry = (x1 + x2 + carry) / 10;

s.push_back(value + '0');

n--;

m--;

}

if (carry != 0)

s.push_back(carry + '0');

reverse(s.begin(), s.end());

return s;

}

string multiply(string num1, string num2)

{

vector<string> sum;

int m = num2.size() - 1;

int last = 0;

while (m >= 0)

{

string s;

int carry = 0;

int x1, x2, value;

int n = num1.size() - 1;

while (n >= 0)

{

x1=num1[n]-'0';

x2=num2[m]-'0';

value = (x1 * x2 + carry) % 10;

carry = (x1 * x2 + carry) / 10;

s.push_back(value + '0');

n--;

}

if (carry != 0)

s.push_back(carry + '0');

reverse(s.begin(), s.end());

int temp = last;

while (temp--)

s.push_back('0');

last++;

sum.push_back(s);

m--;

}

string ans = "0";

for (auto str : sum)

{

ans = addStrings(ans, str);

}

if (ans[0] == '0')

{

int i = 1;

while (i < ans.size() && ans[i] == '0')

{

ans.erase(ans.begin() + i);

// i++;

}

}

return ans;

}

};

int main()

{

Solution s;

string str1,str2;

cout<<"Enter First String:";

cin>>str1;

cout<<"Enter Second String:";

cin>>str2;

cout<<s.multiply(str1,str2)<<endl;

}

In my childhood, my grandfather used to give me multiplication of numbers that have more than 10 digits so that I can'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.

]]>In this Calculator program in C, we are going to perform arithmetic operations (i.e., addition, subtraction, multiplication, and division) between two numbers in c language using switch case and do-while loop

#include <stdio.h>

int main()

{

int a, b, ch;

char choice;

printf("\n Enter two numbers:");

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

do

{

printf("\n Press 1 to add %d and %d", a, b);

printf("\n Press 2 to subtract %d and %d", a, b);

printf("\n Press 3 to multiply %d and %d", a, b);

printf("\n Press 4 to divide %d and %d", a, b);

printf("\n Enter Your Choice: ");

scanf("%d", &ch);

switch (ch)

{

case 1:

printf("Sum: %d", a + b);

break;

case 2:

printf("Subtract :%d", a - b);

break;

case 3:

printf("Multiply :%d", a * b);

break;

case 4:

if (b == 0)

printf("\n Denominator cannot be zero");

else

printf("Divide :%d", a / b); // b should not be zero

break;

default:

printf("Wrong choice!");

}

printf("\n Do you want to continue? (Press y/n)");

scanf(" %c", &choice);

} while (choice == 'y');

return 0;

}

Output:

` Enter two numbers:5 3 Press 1 to add 5 and 3 Press 2 to subtract 5 and 3 Press 3 to multiply 5 and 3 Press 4 to divide 5 and 3 Enter Your Choice: 1 Sum: 8 Do you want to continue? (Press y/n)n`

Related post:

Menu-Driven Program for Array Operations in C++

Menu-Driven Program for Array Operations in C++

- Initialize three numbers, one number is for the choice of the user and we perform arithmetic operations on the other two numbers.
- Input two numbers on which we perform arithmetic operations.
- Print all the choices and input the choice of the user.
- Using the
, we write all four cases for addition, subtraction, multiplication, and division respectively.*switch keyword* - Do not forget to write a break at the end of the case statement.
- You can also write a default statement in case the user input the wrong choice
- for example: - default:printf("Wrong choice!");

In this program, we are going to make a menu-driven program in c for a simple calculator using a while loop and using an if-else statement instead of a switch-case statement. If you want the source code of the menu-driven program in c using the while loop and switch case, then let me know in the comment section.

#include<stdio.h>

#include<stdlib.h>

int main()

{

int num1, num2, choice;

while(1)

{

printf("\n Menu Driven Program in c");

printf("\n 1.Addition");

printf("\n 2.Subtraction");

printf("\n 3.Multiplication");

printf("\n 4.Division");

printf("\n 5.exit");

printf("\n Enter Choice:");

scanf("%d",&choice);

if(choice>0 && choice<6)

{

if (choice==1)

{

printf("\n Enter 1st number: ");

scanf("%d",&num1);

printf("\n Enter 2nd number: ");

scanf("%d",&num2);

printf("\n %d + %d = %d",num1,num2,num1+num2);

}

if (choice==2)

{

printf("\n Enter 1st number: ");

scanf("%d",&num1);

printf("\n Enter 2nd number: ");

scanf("%d",&num2);

printf("\n %d - %d = %d",num1,num2,num1-num2);

}

if (choice==3)

{

printf("\n Enter 1st number: ");

scanf("%d",&num1);

printf("\n Enter 2nd number: ");

scanf("%d",&num2);

printf("\n %d * %d = %d",num1,num2,num1*num2);

}

if (choice==4)

{

printf("\n Enter 1st number: ");

scanf("%d",&num1);

printf("\n Enter 2nd number: ");

scanf("%d",&num2);

if(num2==2)

printf("\n Denominator cannot be zero");

else

{

printf("\n %d / %d = ",num1,num2);

printf("%d",num1/num2);

}

}

if(choice==5)

exit(0);

}

else printf("\n Wrong choice");

}

return 0;

}

Output:

` 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. exit Enter Choice:1 Enter 1st number: 5 Enter 2nd number: 6 5 + 6 = 11 `

In conclusion, we have just gone through the different programs for calculators in c. It totally depends on your choice, but I will recommend you to make this program using a switch case. These types of programs are known as menu-driven programs.

]]>In this program, we are going to make a python program to calculate the GCD of two numbers using recursion.

GCD stands for the greatest common divisor. Sometimes, they can ask you to write a program for HCF of two numbers so don't worry about this because they both are the same thing.

GCD of 6 & 9 is 3

def gcd(a,b):

if(b==0):

return a;

return gcd(b,a%b);

str = input("Enter Two Numbers:")

a, b = str.split()

a=int(a)

b=int(b)

print(gcd(a,b));

Output for gcd of two numbers in python:

`Enter Two Numbers:500 1000500 `

According to Euclid algorithm, GCD(a,b)=GCD(b,a%b). The base case for our recursive function is if b is zero then we will return a.

The time complexity of GCD of two numbers in Python using recursion is O(log(max(a,b)).

Related Posts:

Simple Python Program to Add Two Numbers

Python Program to Find Factorial of a Number using for loop