Posts

Showing posts from December, 2022

PPS UNIT 2 Notes

 PPS Unit 2 Notes complete https://drive.google.com/file/d/1hM43NMdIz1sfFixcIlTzz0S1OXxL8CRm/view?usp=share_link

Explicit Conversion Program

/  / C program to demonstrate explicit type casting #include<stdio.h>       int main() {      double x = 1.2;            // Explicit conversion from double to int      int sum = ( int )x + 1;            printf ( "sum = %d" , sum);            return 0; }

Implicit Conversion Program

// An example of implicit conversion #include <stdio.h> int main() {      int x = 10; // integer x      char y = 'a' ; // character c          // y implicitly converted to int. ASCII      // value of 'a' is 97      x = x + y;          // x is implicitly converted to float      float z = x + 1.0;          printf ( "x = %d, z = %f" , x, z);      return 0; }  

Bitwise Operators Program

  #include <stdio.h> void main()  { unsigned int p = 60; /* 60 = 0011 1100 */ unsigned int q = 13; /* 13 = 0000 1101 */ int r = 0; r = p | q; /* 61 = 0011 1101 */ printf(“Line 1 – The value of r is %d\n”, r ); r = p & q; /* 12 = 0000 1100 */ printf(“Line 2 – The value of r is %d\n”, r ); r = ~p; /*-61 = 1100 0011 */ printf(“Line 3 – The value of r is %d\n”, r ); r = p ^ q; /* 49 = 0011 0001 */ printf(“Line 4 – The value of r is %d\n”, r ); r = p >> 2; /* 15 = 0000 1111 */ printf(“Line 5 – The value of r is %d\n”, r ); r = p << 2; /* 240 = 1111 0000 */ printf(“Line 6 – The value of r is %d\n”, r ); }

Logical Operators Program

  # include <stdio.h> int main () { int a = 5 , b = 5 , c = 10 , result; result = (a == b) && (c > b); printf ( "(a == b) && (c > b) is %d \n" , result); result = (a == b) && (c < b); printf ( "(a == b) && (c < b) is %d \n" , result); result = (a == b) || (c < b); printf ( "(a == b) || (c < b) is %d \n" , result); result = (a != b) || (c < b); printf ( "(a != b) || (c < b) is %d \n" , result); result = !(a != b); printf ( "!(a != b) is %d \n" , result); result = !(a == b); printf ( "!(a == b) is %d \n" , result); return 0 ; }

Relational Operators Program

# include <stdio.h> int main () { int a = 5 , b = 5 , c = 10 ; printf ( "%d == %d is %d \n" , a, b, a == b); printf ( "%d == %d is %d \n" , a, c, a == c); printf ( "%d > %d is %d \n" , a, b, a > b); printf ( "%d > %d is %d \n" , a, c, a > c); printf ( "%d < %d is %d \n" , a, b, a < b); printf ( "%d < %d is %d \n" , a, c, a < c); printf ( "%d != %d is %d \n" , a, b, a != b); printf ( "%d != %d is %d \n" , a, c, a != c); printf ( "%d >= %d is %d \n" , a, b, a >= b); printf ( "%d >= %d is %d \n" , a, c, a >= c); printf ( "%d <= %d is %d \n" , a, b, a <= b); printf ( "%d <= %d is %d \n" , a, c, a <= c); return 0 ; }

Assignment Operators Program

# include <stdio.h> int main () { int a = 5 , c; c = a; // c is 5 printf ( "c = %d\n" , c); c += a; // c is 10 printf ( "c = %d\n" , c); c -= a; // c is 5 printf ( "c = %d\n" , c); c *= a; // c is 25 printf ( "c = %d\n" , c); c /= a; // c is 5 printf ( "c = %d\n" , c); c %= a; // c = 0 printf ( "c = %d\n" , c); return 0 ; }

Arithmetic Operators Program

  # include <stdio.h> int main () { int a = 9 ,b = 4 , c; c = a+b; printf ( "a+b = %d \n" ,c); c = a-b; printf ( "a-b = %d \n" ,c); c = a*b; printf ( "a*b = %d \n" ,c); c = a/b; printf ( "a/b = %d \n" ,c); c = a%b; printf ( "Remainder when a divided by b = %d \n" ,c); return 0 ; }

Increment/Decrement Programs

1. Increment Operator #include <stdio.h> int main() { int x = 5, y = 5; // x is displayed // Then, x is increased to 6. printf(“%d post-increment n”, x++); // y is increased to 6 // Then, it is displayed. printf(“%d pre-increment”, ++y); return 0; } 2. Decrement Operator #include <stdio.h> int main() { int x = 5, y = 5; // x is displayed // Then, x is decreased to 4. printf(“%d post-decrement n”, x–); // y is decreased to 4 // Then, it is displayed. printf(“%d pre-decrement”, –y); return 0; }

Lab Record Program No 8

8.Write a C Program to find Sin(x) and Cos(x) values using series expansion.  A)PROGRAM FOR SUM OF SIN (X) SERIES /*x -x^3/3! + x^5/5! - .........*/  #include<stdio.h> #include<conio.h>   #include<math.h>   void main()  {  float x,s=0;   int fact(int x);   int n,i,t=1;   clrscr();   printf("\nEnter the value of x & n ");   scanf("%f%d",&x,&n);   for(i=1; i<=n; i++)   {   s=s+pow(-1,(i+1))*(pow(x,t))/((float)fact(t));   printf("x^%d/%d!",t,t);   if(i%2==0)   printf("+");  else   printf("-"); t=t+2;  }   printf("\nSum of series = %.2f",s);   getch();  }  int fact(int x)  {   int i,f=1;  for(i=1; i<=x; i++)  f=f*i;   return(f);  } B)PROGRAM FOR SUM OF COS (X) SERIES  #include<stdio.h>   #include<conio.h>   void main()  {  int i, n;   float x, sum=1, t=1;   clrscr();   printf(" Enter the value for x : ");   scanf("%f",&x);   printf(" Enter the value fo

Lab Record Program No 7

 7.Write a C Program to find Minimum and Maximum element in the array and to find Roots of a Quadratic equation.  A) Maximum and minimum of given list of numbers  #include<stdio.h> #include<conio.h> void main()  {   int arr[20];   int i, max, min, size; clrscr(); printf("\nEnter size of the array: "); scanf("%d", &size); printf("\nEnter %d elements of the array: ",size); for(i=0; i<size; i++) scanf("%d", &arr[i]);  /* assume the first element as maximum and minimum */  max = arr[0];  min = arr[0]; for(i=1; i<size; i++)  {  /* If current element of array is greater than max */  if(arr[i]>max)  max = arr[i];  /* If current element of array is smaller than min */  if(arr[i]<min)  min = arr[i];  } printf("\nMaximum element = %d\n", max); printf("\nMinimum element = %d\n", min); getch(); } B) Roots of a Quadratic Equation  #include<stdio.h> #include<conio.h> #include<math.h> voi