C Programming Lab Manual – 23

Write a C program to Control Statement Structure.

Function Main
    Declare Integer k
    Assign k = 1
    If k=1
        Output "t"
    End
    If k=0
        Output "F"
    Else
        Output "!f"
    End
    For k = 0 to 3
        Output ""&k
    End
    While k<5
        Output ""&k
        Assign k = k+1
    End
    Loop
        Assign k = k+1
        Output ""&k
    Do k<7
End

#include <stdio.h>
int main() {
  int k;
  if (1) {
    printf("t");
  }
  if (0) {
    printf("F");
  } else {
    printf("!f");
  }
  for (k = 0; k <= 3; k++) {
    printf("%i", k);
  }
  while (k < 5) {
    printf("%i", k);
    ++k;
  }
  do {
    printf("%i", k);
    k += 1;
  } while (k < 7);
}

t!f0123467

C Programming Lab Manual – 22

Write a C program to Create One Dimensional Array.

Function Main
    Declare Integer i, n
    
    Assign n = 12
    Declare Integer Array a[n]
    
    Assign a[0] = 1
    For i = 1 to n-1
        Assign a[i] = a[i-1] * 2
    End
    For i = 0 to n-1
        Output "a["&i&"] = " & a[i]
    End
End

#include <stdio.h>
int main() {
    //! showArray(a, cursors=[i,n], n=8, cw=32)
    int i, n = 12;
    int a[n];
    a[0] = 1;
    for (i = 1; i < n; i++) {
        a[i] = a[i - 1] * 2;
    }
    for (i = 0; i < n; i++) {
        printf("a[%i] = %i\n", i, a[i]);
    }
}

a[0] = 1
a[1] = 2
a[2] = 4
a[3] = 8
a[4] = 16
a[5] = 32
a[6] = 64
a[7] = 128
a[8] = 256
a[9] = 512
a[10] =1024
a[11] =2048

C Programming Lab Manual – 21

Write a C program to Create an Array of input and output.

Function Main
    Declare Integer Array values[5]
    Declare Integer i
    
    Output "Enter 5 integers: "
    For i = 0 to 4
        Input values[i]
    End
    Output "Show the Array values: "
    For i = 0 to 4
        Output values[i]
    End
End

#include <stdio.h>
int main() {
//! showArray(values)

int values[5];

  printf("Enter 5 integers:\n ");

 for(int i = 0; i<=4; ++i) {
     scanf("%d\n", &values[i]);
  }

  printf("Show the Array values:\n ");
  for(int i = 0; i<=4; ++i) {
     printf("%d\n", values[i]);
  }
  return 0;
} 
Enter 5 integers: 
1
2
3
4
5
Show the Array values: 
1
2
3
4
5