Posts

Showing posts from January, 2019

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++)

c program to convert any three digit number in words

Image
c program to convert any three digit number in words In this program if you enter any three digit number like 123 then it will print one hundred twenty three for this you just need the basic knowledge of switch case.Then go through the given program below. #include<stdio.h> int main(){ int first,second,third; printf("enter 3 digit number\n"); scanf("%1d%1d%1d",&first,&second,&third); switch(first%10){ case 1: printf(" one hundred"); break; case 2: printf(" two hundred"); break; case 3: printf(" three hundred"); break; case 4: printf(" four hundred"); break; case 5: printf(" five hundred"); break; case 6: printf(" six hundred"); break; case 7: printf(" seven hundred"); break; case 8: printf(" eight hundred"); break; case 9: printf(" nine hundred"); bre

c program to find number of even and odd number

Image
c program to find number of even and odd number   if you want to find number of even and odd number entered by user then please go through the given below program. #include<stdio.h> #include<string.h> int main(){ int a[20],i,n,e=0; printf("enter the size of array\n"); scanf("%d",&n); printf("enter the %d elements of array\n",n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n;i++){ switch(a[i]%2){ case 0: e++; break; } } printf("number of even %d\n",e); printf("number of odd %d\n",n-e); }

c program to insert any element in array

Image
c program to insert any element in array if you want to insert any element in array at any position then go through the given programming solution below. #include<stdio.h> #include<string.h> int main(){ int a[20],i,n,p,v; printf("enter size of array\n"); scanf("%d",&n); printf("enter the element of array\n"); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("enter the position at which you want to enter  the element and value of element\n"); scanf("%d%d",&p,&v); p=p-1; printf("your final array is\n"); for(i=0;i<n;i++){ if(i==p){ a[p]=v; } printf("%d\n",a[i]); } }

c program to delete any number in array

Image
c program to delete any number in array if you are using turbo c compiler please use  #include<conio.h>  header file. and if you are using devc++ or any other compiler than simply go through the given program below. #include<stdio.h> #include<string.h> int main(){ int a[20],i,n,p; printf("enter size of array\n"); scanf("%d",&n); printf("enter the element of array\n"); for(i=0;i<n;i++){ scanf("%d",&a[i]); } printf("enter the position at which you want to delete the array\n"); scanf("%d",&p); p=p-1; printf("your final array is\n"); for(i=0;i<n;i++){ if(i==p){ continue; } printf("%d\n",a[i]); } }

c program to find even and odd number

Image
c program to find even and odd number  if you are using turbo c compiler please use  #include<conio.h>  header file. and if you are using devc++ or any other compiler than simply go through the given program below. #include <stdio.h> int main() {     int number;     printf("Enter an integer: ");     scanf("%d", &number);     // True if the number is perfectly divisible by 2     if(number % 2 == 0)         printf("%d is even.", number);     else         printf("%d is odd.", number);     return 0; }

How to find second highest number in array by c programming

Image
How to find second highest number in array by c programming if you are using turbo c compiler please use  #include<conio.h> header file. and if you are using devc++ or any other compiler than simply go through the given program below. #include <stdio.h> int main(){          char a[20],i,n,temp;     printf("enter size of array\n");     scanf("%d",&n);     printf("enter elements of array\n");     for(i=0;i<n;i++){        scanf("%d",&a[i]);               }          for(i=0;i<n;i++){                  if(a[i]>a[0])         {            temp=a[0];             a[0]=a[i];            a[i]=temp;                                              }     }          for(i=1;i<n;i++){                  if(a[i]>a[1]){             a[1]=a[i];         }     }     printf("second highest number is %d\n",a[1]);      }

How to print the table of given number by user in c program

Image
How to print the table of given number by user in c program #include<stdio.h> int main(){ int i,a,c;     //a is any number given by user whose table is to be print. printf("enter any number"); scanf("%d",&a); for(i=1;i<=10;i++){ c=a*i; printf("%d*%d=%d\n",a,i,c); } }