Author name: Tutorials

C ++ – Variables

C++ Variables: Rules to create: Integer variable: #include <iostream>using namespace std; int main() {            int num = 10; // integer variable            cout << “The value of num is: ” << num << endl;            return 0;} Floating point variable: #include <iostream>using namespace std; int main() {            float num = 3.14; // floating point variable            cout << “The value …

C ++ – Variables Read More »

Python – Digit based Programs

Count digits in the given number: n = int(input(“enter num : “))count=0while(n!=0):            n=n//10            count=count+1print(“Digits count : “, count)

Python – While – Menu Driven program

Menu Driven Program to perform all arithmetic operations: while(True):            print(“1. Add”)            print(“2. Subtract”)            print(“3. Multiply”)            print(“4. Divide”)            print(“5. Quit”)             ch = int(input(“enter choice :”))            if(ch==1):                        print(“Enter 2 numbers:”)                        a=int(input())                        b=int(input())                        print(“Res : “, a+b)            elif(ch==2):                        print(“Enter 2 numbers:”)                        a=int(input())                        b=int(input())                        print(“Res : “, a-b)            elif(ch==3):                        print(“Enter 2 numbers:”)                        a=int(input())                        b=int(input())                        print(“Res : “, a*b)            …

Python – While – Menu Driven program Read More »

Python – While Loop

while loop: Syntax:             while(condition):                        statements; Check the even numbers until user quits: while(True):            n = int(input(“enter num : “))            if(n%2==0):                        print(n,”is even”)            else:                        print(n,”is odd”)             print(“Do you check another num(y/n) :”)            ch = input()            if(ch==’n’):                        break Display Multiplication tables until user quits: while(True):            n = int(input(“Enter table num : “))            for i in range(1,11):                        print(n,’*’,i,’=’,n*i)             …

Python – While Loop Read More »

Python – Range based programs

Multiplication tables in the given range:. for n in range(5, 11):       for i in range(1,11):        print(n,’*’,i,’=’,n*i) Factorials in the Given range: for n in range(1,8):     fact=1    for i in range(1,n+1):        fact=fact*i    print(“factorial of”,n,”is”,fact) Prime numbers in given range: for n in range(1,51):     factors=0    for i in range(1,n+1):        if(n%i==0):            factors=factors+1     if(factors==2):        print(n,”is prime”) Perfect numbers in …

Python – Range based programs Read More »

Python – for Loop programs

Sum of First N numbers: n = int(input(“Enter a positive integer: “))sum = 0for i in range(1, n+1):    sum += iprint(“The sum of the first”, n, “natural numbers is:”, sum) Find factorial for given number: n = int(input(“Enter a positive integer: “))factorial = 1for i in range(1, n+1):            factorial *= iprint(“The factorial of”, n, “is:”, …

Python – for Loop programs Read More »

Python – for Loop

for loop: range(): Print the numbers from 0 to 9:for i in range(10):            print(i) Print the numbers from 3 to 8:for i in range(3,9):            print(i) Print the numbers from 10 to 1:for i in range(10, 0, -1):            print(i) Print every third number from 0 to 20:for i in range(0, 21, 3):            print(i) Print the even numbers from 0 to …

Python – for Loop Read More »

Python – Shift Operators

Shift operators: >>> x=8>>> x>>22>>> x<<232 Right shift: n/2^s à 8/2^2 à 8/4 à 2 Left shift : n*2^s à 8*2^2 à 8*4 à 32

Scroll to Top