Posts

Write a program to input few numbers from command line and show sum of all given values in C/C++, Java & Python.

 /* C Language */ #include<stdio.h> main(int argc, char *argv[]){ if(argc>1){ int i,s=0; for(i=1;i<argc;i++) s=s+atoi(argv[i]); printf("Sum is %d",s); } else printf("Please provide few numbers"); } // C++ Language #include<iostream> #include<stdlib.h> main(int argc, char *argv[]){ if(argc>1){ int i,s=0; for(i=1;i<argc;i++) s=s+atoi(argv[i]); std::cout <<"Sum is " << s; } else std::cerr << "Please provide few numbers"; } # Python import sys sum = 0 for i in range(1, len(sys.argv)):     sum += int(sys.argv[i]) print(f'Sum is : {sum}')

What is an Algorithm?

  An introduction to Algorithms A set of steps or instructions to complete a task is called an  algorithm Algorithm must have a clearly defined problem statement , input and output The   steps in the algorithm need to be in specific order The steps should also be distinct Algorithms should complete in a finite amount of time Algorithms should produce a result Properties of Algorithms   Correctness Efficiency Efficiency is measured based on two parameters Time Complexity Measures how long it takes an algorithm to run or complete a task Space Complexity It deals with the amount of memory consumed