winternsa.blogg.se

C program to print n consecutive numbers using for loop
C program to print n consecutive numbers using for loop











For each repetition print the value of i. * end (i<=end), increment the loop count by 1 to get * Start loop counter from start (i=start) and go till Printf("Natural numbers from %d to %d : \n", start, end)

c program to print n consecutive numbers using for loop

The loop structure should look like for(i=start i Initialize loop from start that runs till end. Store it in some another variable say end. Using above logic you can easily find a way to print natural numbers in range. * For each repetition print the value of i.ġ0 Logic to print natural numbers in range * increment the loop count by 1 to get the next value.

c program to print n consecutive numbers using for loop

* Start loop counter from 1 (i=1) and go till n (i<=n) Printf("Natural numbers from 1 to %d : \n", n) * C program to print all natural numbers from 1 to n Program to print natural numbers from 1 to n /** So to print from 1 to N print the value of i. You might think, why print value of i inside loop? Because we need to print natural numbers from 1 to N and from loop structure it is clear that i will iterate from 1 to N.

  • Inside the loop body print the value of i.
  • Therefore if n is one natural number then next natural number is given by n+1. Why increment loop counter by 1? Because difference between two natural numbers is 1. Why going till N? Because we need to print natural numbers up to N.













    C program to print n consecutive numbers using for loop