Questions tagged [imperative-programming]

Imperative programming is a paradigm of expressing the logic of a computer program or computation by explicitly describing its control flow in terms of statements that change a program state.

From Wikipedia:

In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state. In much the same way that imperative mood in natural languages expresses commands to take action, imperative programs define sequences of commands for the computer to perform.

FAQ:

See also

143 questions
0
votes
4 answers

C program to find roots error

I am writing a function in C with the below specifications: float find_root(float a, float b, float c, float p, float q); find_root takes the coefficients a,b,c of a quadratic equation and an interval (p, q). It will return the root of this…
KLMM
  • 93
  • 1
  • 13
0
votes
0 answers

Cognitive Modeling Language (CML) vs Imperative Programming vs Declarative Programming

I'm reading this article by John Funge about Cognitive Modeling for Computer Games: http://www.qrg.northwestern.edu/resources/aigames.org/1999/fungegame99.pdf And some further detailed reading about it in this…
Achi Even-dar
  • 427
  • 1
  • 10
  • 20
0
votes
0 answers

How to make functional style absolutelly identical to imperative style in Scala

In a book on Scala programming I came around this example. They say that this example of imperative code def printArgs(args: Array[String]): Unit = { var i = 0 while (i < args.length) { println(args(i)) i += 1 } } Can…
henry
  • 607
  • 2
  • 8
  • 15
0
votes
2 answers

Exercise in C to calculate sum from x to y

My teacher wants the sum of all numbers from x to y... like x+(x+1)+(x+2)...until y. But I think I'm doing something wrong here! Can someone advice me what is wrong here? #include int sum_naturals(int n) { return (n-1) * n / 2; } int…
0
votes
1 answer

Implementing Karger's minimum cut algorithm in functional paradigm

I have no problem in implementing this algorithm in any imperative language, but I am struggling implementing it in Clojure or any other functional language. A lot of algorithms are described in terms of working with mutable data structures and…
0
votes
1 answer

For the grammar given, provide 3 valid example strings

today I got a homework on my 'Programming Languages' class and I'm having trouble. Here is the full question; For the grammars given below, draw transition diagram and transition table. Provide 3 valid example strings. And this is the one I'm…
cbt
  • 1,271
  • 1
  • 11
  • 20
0
votes
1 answer

Do objects and instances mean something else for an imperative language like C compared to an object-oriented?

I read that a running C program can be referred to as an "instance". Is this really correct? The word instance is usually used for OOP. And C also has "objects" hasn't it, but it's not the same as in OOP. An "object" in C is just something in memory…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
-1
votes
1 answer

OCaml loops: imperative vs recursion

I just stumbled upon some OCaml code that writes a loop like this: let r = ref (f 0) in for i = 1 to k - 1 do r := f i * !r done ; !r in Which is interesting as I normally see this done using recursive functions in OCaml…
-1
votes
6 answers

Finding the sum of numbers from x to y and the program prints the answer as "x+(x+1)....+y= (sum of # from x to y)"

For example, the sum of numbers from 1 to 3 would be printed as 1+2+3=6; the program prints the answer along with the numbers being added together. How would one do this? Any help is greatly appreciated as nothing I've tried has worked. I have been…
-1
votes
2 answers

Mutable and Immutable objects are implemented the same in all programming languages?

The main ideas of immutability are kept the same throughout the scope of OOP and functional programming or do, for example, Java and Python have their own versions of immutability. More specifically do the following hold in all languages? Mutable…
Ari
  • 324
  • 3
  • 13
-1
votes
2 answers

Is unix's 'cp' command declarative or imperative?

I'm having a discussion with a coworker, who insists cp is declarative. To me, it seems very imperative. It's an instruction we are asking the computer to do, not a definition or declaration. For it to be declarative, instead of: cp a.zip b.zip you…
Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156
-1
votes
2 answers

Functional Programming vs Imperative Programming: Computation Time

I've got a general question about functional programming vs imperative programming. I am a hobby programmer implementing some engineering problems with C#. You always here a lot concerning the benefits of functional programming. Maybe I get it…
Johannes
  • 161
  • 1
  • 6
-1
votes
2 answers

C and addition, integer first and later

I'm come from Java, i want to improve my skill in coding and knowledge of how it's work in deep and i figure that the best language for this is C the mother of all. I'm very excited about how it work c but now please raise me a doubt. Why in C first…
CivilEngine
  • 47
  • 1
  • 5
-1
votes
4 answers

Different fibonacci implementation in Haskell using lists

I have searched the blog for a Fibonacci implementation similar the the one I desire. Nothing came up although there were a lot of questions about Haskell's Fibonacci implementation. I want a recursive Fibonacci function (speed doesn't matter) that…
-1
votes
2 answers

How do you iterate in functional languages?

One reason that pushes me away from functional languages like Lisp is that I have no idea how to do a 'raw' array iteration. Say, I have an array in C that represents the screen pixels's RGB values. Changing colors is trivial with a for loop in C,…
kuniqs
  • 308
  • 1
  • 9
1 2 3
9
10