Articles on Trending Technologies

Technical articles with clear explanations and examples

C Program for Print individual digits as words without using if or switch.

Sunidhi Bansal
Sunidhi Bansal
Updated on 08-Aug-2019 398 Views

Print the given numeric value as words. It’s easy to do with switch using cases from 0-9 but challenge is without using them.Input  − N=900Output − NINE ZERO ZEROIt is possible by creating array of pointers that contains 0-9 in words.AlgorithmSTART Step 1 -> declare int variables num, i and array of pointer char *alpha with values {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"} Step 2 -> declare char array str[20] Step 3 -> call function itoa with parameters num, str, 10 Step 4 -> Loop For i=0 and str[i]!=’\o’ and i++    Print alpha[str[i] - '0'] ...

Read More

Print first k digits of 1/n where n is a positive integer in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 08-Aug-2019 232 Views

Input number N such that 1/N will return the output generated as decimal specified till the limit.It is easy with Floating Point numbers but the challenge is without using them.Input − n=5 k=5Output − 20000It means if n=5 and k=5 than after dividing 1/5 the output should be displayed till 5 decimal points.AlgorithmStart Step 1 -> Declare int variable n to 9 and k to 7 and remain to 1 and i Step 2-> Loop for i to 0 and i end Loop For StopExample#include int main() {    int n = 9, k = 7, remain=1, i ; // taking n ...

Read More

Print multiples of Unit Digit of Given Number in C Program

Sunidhi Bansal
Sunidhi Bansal
Updated on 08-Aug-2019 5K+ Views

Input number N and fetch the unit digit of a given number and display the multiples of that number.Input − N=326Output − unit digit is 6 and its multiples are 2 and 3Note − Unit digit of any number can be fetched by calculating the %10 with that numberFor example − if your’re given with a number N and you need to find its unit digit thatyou can use N%10 it will return you unit digit of number NALGORITHMSTART Step 1 -> Declare start variables num, num2 and i Step 2 -> input number num Step 3 -> store num%10 in num2 ...

Read More

C vs BASH Fork bomb?

sudhir sharma
sudhir sharma
Updated on 08-Aug-2019 340 Views

Fork() bomb is a Dos (Denial Of Service) attack against the linux based system. This calls the Fork() system infinite number of times that fills the memory of the program and intends to harm the system.Bash script for fork bomb:(){ :|: & };:The code explained as :( ) is function definition, { } defines the body of the loop. :|:& create a memory location and does not allow it to get deallocated. This program call itself multiple number of time again and again. Thus calling infinite calls.C Fork bomb is also the same type of Dos but it can be ...

Read More

Sum of squares of first n natural numbers in C Program?

sudhir sharma
sudhir sharma
Updated on 08-Aug-2019 14K+ Views

The sum of squares of the first n natural numbers is found by adding up all the squares.Input - 5Output - 55Explanation - 12 + 22 + 32 + 42 + 52There are two methods to find the Sum of squares of first n natural numbers −Using Loops − the code loops through the digits until n and find their square, then add this to a sum variable that outputs the sum.Example#include using namespace std; int main() {    int n = 5;    int sum = 0;    for (int i = 1; i >= n; i++)       sum += (i * i);    cout

Read More

C++ Programming for Smallest K digit number divisible by X?

sudhir sharma
sudhir sharma
Updated on 08-Aug-2019 165 Views

Smallest K digit number that divisible by X is found using the formula by checking divisible by X. The formula works in the following way −Compute minimum K digit number [min] for example: 10/100/1000 etc.Now find if min is divisible by X. if yes, then this is the answer.If not, then min+X - ([min+X]%k) is the answer.Example#include #include using namespace std; int main() {    int X = 83;    int K = 5;    cout

Read More

Write you own Power without using multiplication(*) and division(/) operators in C Program

sudhir sharma
sudhir sharma
Updated on 08-Aug-2019 531 Views

Power function is calculated using the times multiple i.e. 5n is 5*5*5… n times. For this function, to work properly without using multiplication(*) and division(/) operators we will use nested loops that add the numbers n number of time.Example#include using namespace std; int main() {    int a= 4 , b = 2;    if (b == 0)       cout

Read More

Sum of squares of the first n even numbers in C Program

sudhir sharma
sudhir sharma
Updated on 08-Aug-2019 2K+ Views

The sum of squares of the first n even numbers means that, we first find the square and add all them to give the sum.There are two methods to find the sum of squares of the first n even numberUsing LoopsWe can use loops to iterate from 1 to n increase number by 1 each time find the square and add it to the sum variable −Example#include using namespace std; int main() {    int sum = 0, n =12;    for (int i = 1; i

Read More

howdoi in Python

Pradeep Elance
Pradeep Elance
Updated on 08-Aug-2019 340 Views

Create a Python ListExampleC:\Py3Project>howdoi create a python listOutputRunning the above code gives us the following result −>>> l = [None] * 10 >>> l [None, None, None, None, None, None, None, None, None, None]Printing Today’s DateExamplec:\python3>howdoi print today's date in pythonOutputRunning the above code gives us the following result −for date in mylist : print str(date)Examplec:\python3>howdoi create fibonnaci series in pythonOutputRunning the above code gives us the following result −def F(n):    if n == 0: return 0    elif n == 1: return 1    else: return F(n-1)+F(n-2)Examplec:\python3>howdoi use calendar in javascriptOutputRunning the above code gives us the following ...

Read More

How to print without newline in Python?

Pradeep Elance
Pradeep Elance
Updated on 08-Aug-2019 1K+ Views

In python the print statement adds a new line character by default. So when we have multiple print statements the output from each of them is printed in multiple lines as you can see in the example below. Our goal is to print them in a single line and use some special parameters to the print function to achieve that.Normal Print()The below example prints multiple statements with new lines in each of them.Exampleprint("Apple") print("Mango") print("Banana")OutputRunning the above code gives us the following result −Apple Mango BananaUsing end ParameterWe can use the end parameter to use a specific character at the ...

Read More
Showing 55641–55650 of 61,248 articles
Advertisements