Posts

Pointer Array in C

Provide any example program with the use of pointer and array at a time. void printArray ( int * ptr , size_t length ); { //for statment to print values using array size_t i = 0 ; for ( ; i < length ; ++ i ) printf ( "%d" , ptr [ i ]); } void printString ( const char * ptr ); { //for statment to print values using array for ( ; * ptr != NULL ; ++ ptr ) printf ( "%c" , * ptr ); } int main () { int array [ 6 ] = { 2 , 4 , 6 , 8 , 10 }; const char * str = "Hello World!" ; printArray ( array , 6 ); printString ( str ); return 0 ; }

Recursive Function in C

Write a program to calculate factorial of a given integer number. Use recursive function

String Programming in C

Write a program to count vowel, consonant and word from a given string.   main() {   char line[100];   int i,con=0,vowel=0,word=0;   printf("Enter your string :\n");   gets(line); for(i=0;line[i]!='\0';++i)   {    if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||     line[i]=='o' || line[i]=='u' || line[i]=='A' ||     line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')     ++vowel;   else if((line[i]>='a' && line[i]<='z')||(line[i]>='A' && line[i]<='Z'))     ++con; else if(line[i]==' ')word++; }   printf("\nVOWEL : %d",vowel);   printf("\nCONSONENT : %d",con);   printf("\nWORD : %d",(word+1)); }

Function Programming : Fibonacci in C

Write a program to generate a Fibonacci Series. Use function. Hints: First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two numbers in series every other numbers are the sum of two previous numbers. For example 5 = 2 + 3 (addition of 2 & 3). Source Code in C: #include<stdio.h> void fibonacci(int m, int n); int main( ) {      int a=0, b=1;      printf("Fibonacci series is :\n\n");      fibonacci(a, b); } void fibonacci(int m, int n) {       int sum=0, i;       for(i=0; i<=50; i++)        {           sum=m+n;           printf ("  %d",sum);           m=n;           n=sum;        } }

Function Programming : divisible by 9 in C

Write a program to check Number which is dividable by 9 or not. Use function to call and return the value.   Source Code in C: #include <stdio.h> void check_divisible(int); int main( ) {      int n, result;      printf ("\n Enter the number to check");      scanf ("%d", &n);      result= check_divisible(n);      return 0; } void check_divisible(int a) {      int i=9;      if (a%9 = =0)            printf ("\n This is divisible by 9");      else           printf ("\n This is not divisible by 9"); }

Function Programming : Area of Circle in C

Write a program to find the area of a Circle. Use function to find area where area = pi * r ^ 2 ( r means radius, ^ means power and the value of pi is 3.144) . Source Code in C: #include<stdio.h> float checkArea(float radius) {       float area;       area=3.14159*(radius*radius) ;       return area; } int main() {       float r, area_of_circle=0;       printf ("\nEnter Radius: ");       scanf ("%f", &r);       area_of_circle= checkArea(r) ;       printf ("\nArea is: %f", area_of_circle); }

Function Programming : Divisible by 5 in C

Write a C Program using function to check whether the given input is divisible by 5 or not. Source Code in C: #include<stdio.h> void divis (int p, int q); int main() {      int a, b=5;      scanf ("%d", &a);      divis(a, b); } void divis (int p, int q) {      if (p%q = =0)           printf ("\n Given number is divisible by 5");      else            printf ("\n Given number is not divisible by 5");  }