CPNM LAB SYLLABUS AND EXPERIMENT ARE BELOW
FOR CPNM OBSERVATION
👉 Click here👈
 [note:observation is up dated now]
[note:observation is up dated now]
=========================================================================
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 <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;
        }		
3. Write a set of string manipulation functions e.g. for getting a sub-string from a given position, Copying one string to another, Reversing a string, adding one string to another
--------------------------------------------------------------------------------------------------------
PROGRAM:-
#include<stdio.h>
#include<string.h>
#include<stdlib.h>                            //If we use #include<stdio. h> in your c program, it will include stdio. h file into our source program which has the information for all input, output related functions.
int main()
{
 char string1[25],string2[25];
 int choice;
 char* p;
 while (1)
{
 printf("the list of string manipulation operations\n");
 printf("__________________________________________\n");
 printf("\n1.Finding string length\n2.Finding string concatenation\n3.Compare two strings\n4.Copying two strings\n5.Reverse of string\n6.Extract the given string\n7.Exit\n");
 printf("_____________________________\n");
 printf("choose (1-7) from the above list:");
  scanf("%d",&choice);
  switch (choice)
{ 
  case 1:
  printf("enter the string1 :");
   scanf("%s",string1);
  printf("the length of the string is %ld\n",strlen(string1));
 printf("__________________________________________\n");
  break;
  case 2:
  printf("enter two strings :");
   scanf("%s%s",string1,string2);
  strcat(string1,string2);
  printf("the concatenated string is =%s\n",string1);
  printf("__________________________________________\n");
  break;
  case 3:
  printf("enter two strings :");
   scanf("%s%s",string1,string2);
  if (strcmp(string1,string2)==0)
  { printf("the given two strings are equal");}
  else
  { printf("the given two strings are not equal\n");}
 printf("__________________________________________\n");
  break;
  case 4:
  printf("enter the string :");
   scanf("%s",string1);
  printf("string1=%s\n",string1);
  printf("after copying string1 to string2\n");
  strcpy(string2,string1);
  printf("string2=%s\n",string2);
   printf("__________________________________________\n");
  break;
  case 5:
  printf("enter the string");
   scanf("%s",string1);
  printf("before reversing string1 = %s",string1);
  strrev(string1);
  printf("after reversing of string is = %s",string1);
  printf("___________________________________\n");
  break;
  case 6:
  printf("Extracting substring from a given string\n");
  printf("enter the string :");
   scanf("%s",string1);
  printf("Enter the sub string to extract :");
   scanf("%s",string2);
   if (p)
  { 
    printf("string found\n");
    printf("First occurence of string %s in %s is %s\n",string1,string1,p);
     printf("__________________________________________\n");
  }
   else
  { printf("string not Found\n");
   printf("__________________________________________\n");}
break;
  case 7:
  exit(0);
  }
  }
   return 0;
  }
output:-
4. Write a program which determines the largest and the smallest number that can be stored in different data types like short, int, long, float, and double. What happens when you add 1 to the largest possible integer number that can be stored?
----------------------------------------------------------------------------------------
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main()
{ 
  printf("The minimum and maximum ranges of short_int data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of short_int data type is %d\n",SHRT_MIN);
  printf("Maximum value of short_int data type is %d\n",SHRT_MAX);
  printf("\n");
  printf("The minimum and maximum ranges of integer data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of integer data type is %d\n",INT_MIN);
  printf("Maximum value of integer data type is %d\n",INT_MAX);
  printf("\n");
  printf("The minimum and maximum ranges of floating point data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of floating point data type is %.2f\n",FLT_MIN);
  printf("Maximum value of floating point data type is %.2f\n",FLT_MAX);
  printf("The minimum and maximum ranges of Double data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of Double data type is %.2f\n",DBL_MIN);
  printf("Maximum value of Double data type is %.2f\n",DBL_MAX);
  printf("\n");
  printf("The minimum and maximum ranges of Long data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of Long data type is %ld\n",LONG_MIN);
  printf("Maximum value of Long data type is %ld\n",LONG_MAX);
  printf("\n");
  printf("The minimum and maximum ranges of character data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of character data type is %d\n",CHAR_MIN);
  printf("Maximum value of character data type is %d\n",CHAR_MAX);
  printf("\n");
printf("The minimum and maximum ranges of Unsigned integer data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Minimum value of Unsigned integer data type is %u\n",INT_MIN);
  printf("Maximum value of Unsigned integer data type is %u\n",INT_MAX);
  printf("\n");
  printf("The maximum ranges of Unsigned character and unsigned long data type is ");
  printf("\n---------------------------------------------------------\n");
  printf("Maximum value of Unsigned character data type is %d\n",UCHAR_MAX);
  printf("Maximum value of Unsigned long data type is %u\n",ULONG_MAX);
  printf("\n---------------------------------------------------------\n");
  printf("When add 1 to the largest value of int is %d",INT_MAX+1);
  return 0;
}
Output:- 
==================================================================
5. Write a program, which generates 100 random real numbers in the range of 10.0 to 20.0, and sort them in descending order. 
PROGRAM  :-
  #include <stdio.h>
  #include <float.h>
  #include <stdlib.h>
  void main()
  {
   int i,j,temp;
   float a[100];
   for (i=0;i<100;i++)
  {
     do 
     {  a[i]=1+rand()%99;  }
     while(a[i]<10.0 || a[i]>20.0); 
      }
     printf("The generated random numbers is :\n");
     printf("=================================\n");
      for(i=0;i<100;i++)
    {  
       printf("%.2f\t",a[i]);
     }
    for (i=0;i<99;i++)
     {  if (a[i]<a[j])
       { temp=a[i];
         a[i]=a[j];
         a[j]=temp;
        }
      }
    }
  printf("\nThe generated random numbers in desending order is :\n");
  printf("======================================================\n");
  for(i=0;i<100;i++)
  {  
    printf("%.2f\t",a[i]);
  }
==============================================================================
   6. Write a function for transposing a square matrix in place (in place means that you are not allowed to have full temporary matrix).
  
  
  
 
-------------------------------------------
PROGRAM :-
#include <stdio.h>
int main()
{  int i,j,n;
   int a[10][10];
  printf("ENTER THE ORDER OF MATRIX : ");
  scanf("%d",&n);
printf("--------------------------");
  printf("\nENTER THE MATRIX ELEMENTS:\n");
   for (i=0;i<n;i++)
{
   for (j=0;j<n;j++)
{
   printf("THE ELEMENT AT POSITION a[%d][%d]=",i,j);
   scanf("%d",&a[i][j]);
}
}
  transpose(a,n);
 for (i=0;i<n;i++)
{ 
 for (j=0;j<n;j++)
{
 printf("%d\t",a[i][j]);
}
 printf("\n");
}
printf("--------------------------------------");
printf("\nThe above matrix is transpose matrix\n");
return 0;
}
void transpose (int a[10][10],int n)
{  
  int i,j;
  float temp;
 for (i=0;i<n-1;i++)
{
{
  temp=a[i][j];
   a[i][j]=a[j][i];
   a[j][i]=temp;
}
}
}
==================================================================
 
  .png=w704-h205-p-k-no-nu)
.png=w460-h703-p-k-no-nu)
.png=w704-h543-p-k-no-nu)
 
 
 
 
0 Comments