1// Print numbers from 1 to 10
2#include <stdio.h>
3
4int main() {
5 int i;
6
7 for (i = 1; i < 11; ++i)
8 {
9 printf("%d ", i);
10 }
11 return 0;
12}
1for(int i = 0; i<n ;i++) //i is the number of iterations that occur
2{ //n is the total number of iterations
3 //code here
4}
1int i;
2for (i = 0; i < n; ++i) { // n is the number of iterations
3 // Code here
4}
1//Sample for loop in c
2//Prints the contents of the array in new lines
3#include <stdio.h>
4int main(){
5 int a, b[5] = {2, 4, 5, 7, 9};
6 for (a = 0; a<5; a++){
7 printf("%d\n", b[a]);
8 }
9
10
11}
1// Program to calculate the sum of first n natural numbers
2// Positive integers 1,2,3...n are known as natural numbers
3
4#include <stdio.h>
5int main()
6{
7 int num, count, sum = 0;
8
9 printf("Enter a positive integer: ");
10 scanf("%d", &num);
11
12 // for loop terminates when num is less than count
13 for(count = 1; count <= num; ++count)
14 {
15 sum += count;
16 }
17
18 printf("Sum = %d", sum);
19
20 return 0;
21}