Posts

Showing posts from January, 2023

PPS UNIT 3 NOTES

 PPS UNIT 3 NOTES LINK https://drive.google.com/file/d/1BOi4T9F1w35S-rgEnOeXab0GIEp1_nty/view?usp=share_link

C Program to Check Whether a Character is a Vowel or Consonant

  # include <stdio.h> int main () { char c; int lowercase_vowel, uppercase_vowel; printf ( "Enter an alphabet: " ); scanf ( "%c" , &c); // evaluates to 1 if variable c is a lowercase vowel lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ); // evaluates to 1 if variable c is a uppercase vowel uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ); // evaluates to 1 (true) if c is a vowel if (lowercase_vowel || uppercase_vowel) printf ( "%c is a vowel." , c); else printf ( "%c is a consonant." , c); return 0 ; }

C PROGRAM TO PRINT * DESIGN PATTERN

  # include <stdio.h> int main () { int i, j, rows; printf ( "Enter the number of rows: " ); scanf ( "%d" , &rows); for (i = 1 ; i <= rows; ++i) { for (j = 1 ; j <= i; ++j) { printf ( "* " ); } printf ( "\n" ); } return 0 ; }

C PROGRAM TO FIND SUM OF DIGITS OF A NUMBER

  #include<stdio.h>      int  main()     {     int  n,sum=0,m;     printf( "Enter a number:" );     scanf( "%d" ,&n);     while (n>0)     {     m=n%10;     sum=sum+m;     n=n/10;     }     printf( "Sum is=%d" ,sum);     return  0;   }   

C PROGRAM TO FIND LCM OF TWO NUMBERS

  # include <stdio.h> int main () { int n1, n2, max; printf ( "Enter two positive integers: " ); scanf ( "%d %d" , &n1, &n2); // maximum number between n1 and n2 is stored in max max = (n1 > n2) ? n1 : n2; while ( 1 ) { if ((max % n1 == 0 ) && (max % n2 == 0 )) { printf ( "The LCM of %d and %d is %d." , n1, n2, max); break ; } ++max; } return 0 ; }

C PROGRAM TO FIND PRIME NUMBERS

  #include<stdio.h>    int  main(){     int  n,i,m=0,flag=0;     printf( "Enter the number to check prime:" );     scanf( "%d" ,&n);     m=n/2;     for (i=2;i<=m;i++)     {     if (n%i==0)     {     printf( "Number is not prime" );     flag=1;     break ;     }     }     if (flag==0)     printf( "Number is prime" );      return  0;    }    

c program to find power of a number without using pow function

# include < stdio . h >    # include < string . h >    # include < conio . h >    # include < math >    # include < stdlib >    int  Pow (  int  a ,  int  b ) {        int  power = 1 , i ;        for  ( i = 1 ; i < = b ; + + i ) {           power = power * a ;       }        return  power ;   }   int  main ( ) {        long   long   int  base , exponent ;          printf (  " enter Base : "  ) ;       scanf (  " % d "  , & base ) ;          printf (  " enter Power : "  ) ;       scanf (  " % d "  , & exponent ) ;          printf (  "  % d ^ % d = % d "  , base , exponent , Pow ( base , exponent ) ) ;   }    

C PROGRAM TO GENERATE PASCAL TRIANGLE AND PYRAMID OF NUMBERS

  A)      Pascal triangle of numbers: #include<stdio.h> #include<conio.h> int main() { int rows,k=1,space,i,j; clrscr();   printf("\nEnter number of rows: "); scanf("%d",&rows); for(i=0;i<rows;i++) { for(space=1; space <= rows-i; space++) printf(" "); for(j=0;j<=i;j++) { if(j == 0||i == 0) k=1; else k=k*(i-j+1)/j; printf("%4d",k); } printf("\n"); } getch(); return 0; }   Output: Enter no. of rows: 6   1 1         1 1         2         1 1       3         3         1 1      4        6         4        1 1     5       10      10       5        1 B)                   Pyramid of numbers.   #include<stdio.h> #include <conio.h> #include<math.h> int main() { int rows,space,i,j; clrscr();   printf("\nEnter number of rows: ");// enter a number for generating the pyramid

C PROGRAM TO CONVERT BINARY TO OCTAL,HEXADECIMAL AND VICE VERSA

A)      Binary to Decimal: #include <stdio.h> #include<conio.h>   int main() { int num, binary_val, decimal_val = 0, base = 1, rem;   printf("\nEnter a binary number(1s and 0s) \n"); scanf("%d", &num); binary_val = num; while (num > 0) { rem = num % 10; decimal_val = decimal_val + rem * base; num = num / 10 ; base = base * 2; } printf("\nThe Binary number is = %d \n", binary_val); printf("\nIts decimal equivalent is = %d \n", decimal_val);   getch(); return 0;   } B)      Binary to Octal: #include <stdio.h> #include <conio.h>   int main() { long int binarynum, octalnum = 0, j = 1, remainder;   clrscr();   printf("Enter the value for binary number: "); scanf("%ld", &binarynum); while (binarynum != 0) { remainder = binarynum % 10; octalnum = octalnum + re

C PROGRAM TO CHECK WHETHER A GIVEN YEAR IS A LEAP YEAR OR NOT

  #include<stdio.h>    #include<conio.h>    void  main() {        int  year;       printf( "Enter a year: " );       scanf( "%d" , &year);        if (((year%4==0) && ((year%400==0) || (year%100!==0))       {           printf( "%d is a leap year" , &year);       }  else  {           printf( "%d is not a leap year" , &year);       }       getch();   }  

C PROGRAM FOR ALPHABET TRIANGLE

 C PROGRAM FOR ALPHABET TRIANGLE #include<stdio.h>      #include<stdlib.h>    int  main(){      int  ch=65;          int  i,j,k,m;       system( "cls" );        for (i=1;i<=5;i++)         {              for (j=5;j>=i;j--)                 printf( " " );              for (k=1;k<=i;k++)                 printf( "%c" ,ch++);                 ch--;              for (m=1;m<i;m++)                 printf( "%c" ,--ch);             printf( "\n" );             ch=65;         }     return  0;   }