Posts

c program to find length of the string

Image
c program to find length of the string  Here at this program you will learn how to calculate length of any string entered by user. #include <stdio.h> int main() {     char s[1000];     int i;     printf("Enter a string: ");     scanf("%s", s);     for(i = 0; s[i] != '\0'; ++i);     printf("Length of string: %d", i);     return 0; }

c program to count vowel,consonant,space,digits in a string

Image
c program to count vowel,consonant,space,digits in a string Enter any string   like balmukund123 and it will give the number of vowel,consonant,digits,and space in this string. #include <stdio.h> int main() {     char line[150];     int i, vowels, consonants, digits, spaces;     vowels =  consonants = digits = spaces = 0;     printf("Enter a line of string: ");     scanf("%[^\n]", 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')         {             ++vowels;         }         else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))         {      

c program to check an alphabet is vowel or consonant

Image
c program to check an alphabet is vowel or consonant  Enter any alphabet then it will give an alphabet is vowel or consonant.vowel are a,e,i,o,u.and rest all the alphabets are consonant.  #include <stdio.h> int main() {     char c;     int isLowercaseVowel, isUppercaseVowel;     printf("Enter an alphabet: ");     scanf("%c",&c);     // evaluates to 1 (true) if c is a lowercase vowel     isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');     // evaluates to 1 (true) if c is an uppercase vowel     isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');     // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true     if (isLowercaseVowel || isUppercaseVowel)         printf("%c is a vowel.", c);     else         printf("%c is a consonant.&quo

c program to concat two string without using concat function.

Image
c program to concat two string without using concat function This program helps you to concat two string without using strcat() which is declared in string.h header file in c. #include <stdio.h> int main() {     char s1[100], s2[100], i, j;     printf("Enter first string: ");     scanf("%s", s1);     printf("Enter second string: ");     scanf("%s", s2);     // calculate the length of string s1     // and store it in i     for(i = 0; s1[i] != '\0'; ++i);     for(j = 0; s2[j] != '\0'; ++j, ++i)     {         s1[i] = s2[j];     }     s1[i] = '\0';     printf("After concatenation: %s", s1);     return 0; }

c program to remove characters in string except alphabets

Image
c program to remove characters in string except alphabets if you enter any string then it removes all character from string except alphabet. #include<stdio.h> int main() {     char line[150];     int i, j;     printf("Enter a string: ");     gets(line);     for(i = 0; line[i] != '\0'; ++i)     {         while (!( (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || line[i] == '\0') )         {             for(j = i; line[j] != '\0'; ++j)             {                 line[j] = line[j+1];             }             line[j] = '\0';         }     }     printf("Output String: ");     puts(line);     return 0; }

c program to shut down your computer

Image
c program to shut down your computer if you are using windows then go through the following program to shut down your computer. #include<stdio.h> #include<stdlib.h> int main(){ char y; printf("do you want to switch off your pc(y\n)"); scanf("%c",&y); if(y=='Y'||y=='y'){ system("c:\\WINDOWS\\System32\\shutdown -s" ); return 0; } }

c program to find armstrong number

Image
c program to find armstrong number armstrong number means the sum of cubic digits of any number is equal to that number. for eg. any number is 153 then 1*1*1+5*5*5+3*3*3=153 so 153 is armstrong number. #include <stdio.h>   int power(int, int);   int main() {    int n, sum = 0, temp, remainder, digits = 0;      printf("Input an integer\n");    scanf("%d", &n);      temp = n;    // Count number of digits    while (temp != 0) {       digits++;       temp = temp/10;    }        temp = n;        while (temp != 0) {       remainder = temp%10;       sum = sum + power(remainder, digits);       temp = temp/10;    }      if (n == sum)       printf("%d is an Armstrong number.\n", n);    else       printf("%d isn't an Armstrong number.\n", n);      return 0; }   int power(int n, int r) {    int c, p = 1;        for (c = 1; c <= r; c++)