Skip to main content

Posts

Showing posts with the label sample c program

Sample C Program To Find Out The No. Of Times A Character Is Present In The String.

This is a Sample C Program To Accept A String & Find Out Whether This Character Is Present In The String. If Present Then Display How Many Times This Character Occurs. #include<stdio.h> #include<conio.h> #include<string.h> void s(char *p,char hc); void main() { char str[10]; char ch; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); printf(" \n \n Enter the character: \t "); scanf("%c",&ch); s(str,ch); } void s(char *p,char hc) { int a = 0; int i,l; l = strlen(p); for(i = 0; i < l; i++)   {      if ( p[i] == hc)        {          a++;        }      else          continue;   } printf(" \n \n The Entered Character occurs %d times. ", a); getch(); } OUTPUT:  Enter the string: Googleplus Enter the character: l The Entered Character occurs 2 times. ALSO R...

Sample C Program To Accept A String & Display Number Of Each Vowels.

#include<stdio.h> #include<conio.h> #include<string.h> char vowels(char *p); void main() { char str[10]; clrscr(); printf(" \n \n Enter the string: \t "); gets(str); vowels(str); getch(); } char vowels(char *p) { int i, l, v1 = 0, v2 = 0, v3 = 0, v4 = 0, v5 = 0, v6 = 0, v7 = 0, v8 = 0, v9 = 0, v10 = 0; l = strlen(p); printf(" \n \n The number of vowels in the string is: \t "); for( i = 0; i < l; i++ ) { if ( p[i] == 'a' )   {      v1++;   } if ( p[i] == 'e' )   {      v2++;   } if ( p[i] == 'i' )   {      v3++;   } if ( p[i] == 'o' )   {      v4++;   } if ( p[i] == 'u' )   {      v5++;   } if ( p[i] == 'A' )   {      v6++;   } if ( p[i] == 'E' )   {      v7++;   } if ( p[i] == 'I' )   {      v8++; ...

Sample C program To Print First Ten Numbers.

#include <stdio.h> #include <conio.h> main() { int c; for ( c = 1 ; c <= 10 ; c++ ) printf("%d\n", c); getch(); return 0; } OUTPUT: 1 2 3 4 5 6 7 8 9 10 Sample C Program To Find Area & Circumference Of A Circle. #include <stdio.h> #include <conio.h> void main() { int r; float pi=3.14, area, ci; clrscr(); printf(" Enter radius of circle: "); scanf("%d",&r); area = pi * r * r; printf(" Area of circle =%f",area); ci = 2 * pi * r; printf(" Circumference =%f",ci); getch(); } OUTPUT: Enter radius of circle: 5 Area of circle =78.500000 Circumference =31.400002 ALSO READ: -- Program To Print First Ten(10) Natural Numbers. -- Program To Print Fibonacci Series Upto 100. -- Program To Check Whether A Number Is Prime Or Not. -- Program To Compute The Reverse Of A Number. -- Program To Print A Semicolon Without Using A Semicolon. -- Pro...