Posts

Raise keyword in python

#raise is a built-in keyword used to raise exception # visit all built-in Exceptions and understand name= input ( "enter u r name:" ) if name.isnumeric(): raise Exception ( "numbers r not allowed" ) #here we used raise keyword

Typedef keyword in c

// typedef is a keyword which is used to give name to the existing data type // syntax- typedef <previous_name> <alias_name>; #include <stdio.h> int main () {     typedef int nt ; // here i given a new name to the data type int to 'nt'     nt a ;           // now i can use 'nt' in place of int     // it is not neccesary to use alias name or new name i can use previous name also like u can see below     int b ;     //--------------------     // using typedef with structure     typedef struct library     {         char name [ 20 ];         int pages ;         char author [ 20 ];     } lib ;             // here i given a new name to the data type library(structure) to 'lib'     lib book1 , book2 ; // here now i can use 'lib' instead of 'struct libra...

structure in c

//structures are user defined data types in c //in structures we can store any type of data types like int floate char etc //declaring a structure #include <stdio.h> #include <string.h> struct library //here strut is a keyword for creating a structure, here library also called structure tag {     char name [ 20 ]; //members or elements of library tag or structure name     int pages ;     char author [ 20 ]; //character array or string of size 20, we have to use string for a char value //there are two methods to initialize a variable from structure }; //book1; //method 1 int main () {     struct library book1 , book2 ; //method 2     //there are two ways to assign values to the variables     //struct library book1={'h',2,'s'}; //way 1,but this is an error, like this we can only assign int values not char     strcpy ( book1 . name , "softwareharish" ); //way 2     book1 . pages = 100 ; ...

python speak

#from pywin32 module we can make read the sentences by the computer from win32com.client import Dispatch speak=Dispatch( "sapi.spvoice" ) speak.speak( "harish is a champion in coding " ) #in function def speak (str): from win32com.client import Dispatch speak = Dispatch( "sapi.spvoice" ) speak.speak(str) if __name__== '__main__' : speak( "jai ntr" )

string functions

#include <stdio.h> #include <string.h> //string functions library int main () {     char s1 [] = "harish" ; //string1     char s2 [] = "shiva" ; //string2     char s3 [ 10 ];     //puts(strcat(s1,s2)); //concatenation     printf ( "length of s1: %d \n " , strlen ( s2 )); //give length of string     printf ( "the reversed string of s1: " );     puts ( strrev ( s1 )); //reverse the string     //s3=strcat(s1,s2); //you canot do like this     strcpy ( s3 , strcat ( s1 , s2 )); //copy value in another variable     printf ( "s3 copied from s1 and s2:" );     puts ( s3 );     return 0 ; }

triangular star

#include <stdio.h> char printstar ( int rows ); int main () {     int n , row , j ;     char star = '*' ;     printf ( "enter 1 for triangle star \n 0 for reverse triangle star \n " );     printf ( "enter:" );     scanf ( " %d " ,& n );     if ( n == 0 )     {         printf ( "enter no of rows u want:" );         scanf ( " %d " ,& row );         for ( j = row ; j >= 1 ; j --)         {             printstar ( j );         }     }     else if ( n == 1 )     {         printf ( "enter no of rows u want:" );         scanf ( " %d " ,& row );         for ( j = 1 ; j <= row ; j ++)         {             printstar ( j ); ...

Fibbonachi series

#include <stdio.h> int recursive ( int n ); int iterative ( int n ); int main () {     int n , fib1 , fib2 ;     printf ( "enter no of which u want fibbonachi:" );     scanf ( " %d " ,& n );     fib1 = recursive ( n );     fib2 = iterative ( n );     printf ( "recursive fibonachi is %d \n " , fib1 );     printf ( "iterative fibonachi is %d " , fib2 );     return 0 ; } int recursive ( int n ) {     if ( n == 1 || n == 2 )     {         return n - 1 ;     }     else     {         return recursive ( n - 1 )+ recursive ( n - 2 );     } } int iterative ( int n ) {     int a = 0 , b = 1 ;     for ( int i = 0 ; i < n - 1 ; i ++)     {         b = a + b ;         a = b - a ;     }     return a ; }