Ticker

6/recent/ticker-posts

CPNM LAB PROGRAM-2

cpnm lab 2 programming made by ece the wonders ***THANK YOU***
----------------------------------------------
2. Write a program, which generates 100 random integers in the range of 1 to 100. Store them in an array and then print the arrays. Write 3 versions of the program using different loop constructs. (e.g. for, while, and do while).
----------------------------------------------

#include <stdio.h>
#include <stdlib.h>


int main()
{
  int n,i=1,a[100];
printf("choose the program type option:- 1=for,2=while,3=do while :");
scanf("%d",&n);

switch (n)
{
   case 1:
     
       {   printf("generate random numbers from (1-100) using 'for' loop\n");
             
           printf("----------------------------------------------------\n");
             
for (i=0;i<100;i++)
a[i]=1+rand()%99;
printf("%d\t",a[i]);
}
break;
          }

    case 2:
  { printf("generate random numbers from (1-100) using 'while' loop\n");
             
         printf("-------------------------------------------------------");
             while(i<=100)
{   
                    a[i]=1+rand()%99;
                  printf("%d\t",a[i]);

                  i++;    }
          break; 
        }
case 3:
          
        { printf("generate random numbers from (1-100) using 'do while' loop\n");
             
         printf("-------------------------------------------------------");
             do
{   
                   a[i]=1+rand()%99;
                  printf("%d\t",a[i]);

                  i++;  }
                 while(i<=100);
          break; 
        }
        
    }
        return 0;
        }
     
               



opt :-

             selection of text is disabled so         please dont try to copy and pasting the code

Post a Comment

0 Comments