Skip to main content

Posts

Example of Sting in C

  Basic Program of String in C Programing #include<stdio.h> #include<conio.h> void main( ) { char s[50]; clrscr( ); printf("\nEnter the string :"); scanf("%s",s); printf("\nYour string : %s",s); getch(); } Note : When we read the string we only specify the string name , because string is an array        and the array name will specify the base address i.e. address of the zeroth position           element. Thus , the statements , scanf("%s",s); and, scanf("%s",&s[0]);   are same. output : Enter the string : computer Your string : computer Enter the string : computer science Your string : computer This is because the scanf( ) function will get terminated by pressing the space.     Join us on Facebook: Click Here     c programming language,c programming software,c programming download,c programming online,c programming examples,c programming tutorial,c programming code c p...

About String in C

  String in C programing String is a sequence or a group of characters. The char type variable is capable of storing a single character while the character array is capable of storing the group of characters. So,string is just a character array. The general form of string declaration is , char stringname[size of array]; e.g.  char s[50]; This statement will declare the character array capable of storing the 50 characters. Initialization of string  To initialize the string there are two ways, (a) char str[5]={'a','j','a','y','\0'}; In this case , all the characters are enclosed in the single quotes and are given within the Curley braces separated by comma. '\0' is the NULL character and is used to end the string. (b) char s[5]="ajay"; When the string is initialized by enclosing the group of    characters in the double quotes , the    '\0' or NULL character will automatically get inserted. Reading and Displ...

Write a 'C' function to calculate the x ^ y.

'C' function to calculate the x ^ y. x=5 y=3 x^ y=5^3=5*5*5=125 (i) When the functin returns the value  (ii) When the function doesnot returns the value . #include<stdio.h> #include<conio.h> /*function prototype*/ int power(int,int); void main() { int x,y,result; clrscr(); printf("\nEnter the value of  x and y :"); scanf("%d %d",&x,&y); result=power(x,y); /*function call*/ printf("\nResult = %d",result); getch(); } /*function defintion*/ int power(int x,int y) { int i,result; result=1; for(i=1;i<=y;i++) result=result*x; return result; } Join us on Facebook  :-  Practice program -JAVA c programming language,c programming software,c programming download,c programming online,c programming examples,c programming tutorial,c programming code c programming w3schools,c++ compiler download,turbo c compiler,online c compiler,c com...

Write a 'c' program using function to calculate the value of c(ncr)

Function to calculate the value of c(ncr) in C c =     n!                    ----------                     r!*(n-r)! #include<stdio.h> #include<conio.h> /*function prototype*/ int factorial(int); void main( ) { int n,r,c,factn,factr,factnr; clrscr(); printf("\nEnter the value of n and r:"); scanf("%d%d",&n,&r); /*calculate the factorial of n */ factn=factorial(n); /*calculate the factorial of r */ factr=factorial(r); /* calculate the factorail of n-r*/ factnr=factorial(n-r); /*calculate the value of c */  c=factn/(factr*factnr); printf("\nc=%d",c); getch(); } /*function definition */ int factorial(int num) { int fact=1,i; for(i=1;i<=num;i++) fact=fact*i; return fact; } Join us on Facebook:  Click Here c pr...

Write a 'c' program to calculate the factorial of the number using Function

Calculate the factorial of the number using Function in C (i) When the function  returns the value #include<stdio.h> #include<conio.h> /*function prototype*/ int factorial(int); void main( ) { int num,fact; clrscr(); printf("\nEnter the number :"); scanf("%d",&num); fact=factorial(num); /*function call*/ printf("\nFactorial = %d",fact); getch(); } /*function defintion */ int factorial(int num) { int i,fact; fact=1; for(i=1;i<=num;i++) fact=fact*i; return fact; } (ii) When the function does not return the value  #include<stdio.h> #include<conio.h> /*function prototype */ void factorial(int); void main() { int num; clrscr( ); prindtf("\nEnter the number :"); scanf("%d",&num); factorial(num); /* function call*/ getch(); } /* function definition */ void factorial...