C Program to Sort set of strings in alphabetical order

#include<stdio.h> #include<string.h> int main(){ int i,j,count; char str[25][25],temp[25]; puts(“How many strings u are going to enter?: “); scanf(“%d”,&count); puts(“Enter Strings one by one: “); for(i=0;i<=count;i++) gets(str[i]); for(i=0;i<=count;i++) for(j=i+1;j<=count;j++){ if(strcmp(str[i],str[j])>0){ strcpy(temp,str[i]); strcpy(str[i],str[j]); strcpy(str[j],temp); } } printf(“Order of Sorted Strings:”); for(i=0;i<=count;i++) puts(str[i]); return 0; }

C Program to convert uppercase string to lowercase string

#include<stdio.h> #include<string.h> int main(){ /* This array can hold a string of upto 26 * chars, if you are going to enter larger string * then increase the array size accordingly */ char str[26]; int i; printf(“Enter the string: “); scanf(“%s”,str); for(i=0;i<=strlen(str);i++){ if(str[i]>=65&&str[i]<=90) str[i]=str[i]+32; } printf(“\nLower Case String is: %s”,str); return 0; }

C Program to Convert Decimal to Octal Number

#include <stdio.h> #include <math.h> /* This function converts the decimal number “decimalnum” * to the equivalent octal number */ int decimalToOctal(int decimalnum) { int octalnum = 0, temp = 1; while (decimalnum != 0) { octalnum = octalnum + (decimalnum % 8) * temp; decimalnum = decimalnum / 8; temp = temp * 10; } … Read more

C program to calculate and print the value of nPr

#include <stdio.h> void main() { int n, r, npr_var; printf(“Enter the value of n:”); scanf(“%d”, &n); printf(“\nEnter the value of r:”); scanf(“%d”, &r); /* nPr is also known as P(n,r), the formula is: * P(n,r) = n! / (n – r)! For 0 <= r <= n. */ npr_var = fact(n) / fact(n – r); … Read more

C Program to Count Vowels and Consonants in a String using Pointer

  #include <stdio.h> int main() { char str[100]; char *p; int vCount=0,cCount=0; printf(“Enter any string: “); fgets(str, 100, stdin); //assign base address of char array to pointer p=str; //’\0′ signifies end of the string while(*p!=’\0′) { if(*p==’A’ ||*p==’E’ ||*p==’I’ ||*p==’O’ ||*p==’U’ ||*p==’a’ ||*p==’e’ ||*p==’i’ ||*p==’o’ ||*p==’u’) vCount++; else cCount++; //increase the pointer, to point next … Read more

C Program to Print String using Pointer

#include <stdio.h> int main() { char str[100]; char *p; printf(“Enter any string: “); fgets(str, 100, stdin); /* Assigning the base address str[0] to pointer * p. p = str is same as p = str[0] */ p=str; printf(“The input string is: “); //’\0′ signifies end of the string while(*p!=’\0′) printf(“%c”,*p++); return 0; }  

C Program to Check Whether a Number is Prime or Not

Program to Check Prime Number #include <stdio.h> int main() { int n, i, flag = 0; printf(“Enter a positive integer: “); scanf(“%d”, &n); for (i = 2; i <= n / 2; ++i) { // condition for non-prime if (n % i == 0) { flag = 1; break; } } if (n == 1) … Read more

C program to convert Celsius to Fahrenheit using while loop

To convert Celsius to Fahrenheit #include <stdio.h> #include <stdlib.h> int main() { float celsius, fahrenheit; printf(“\nEnter temperature in celsius: “); scanf(“%f”, &celsius); fahrenheit = (1.8) * celsius + 32; printf(“\n%f deg celsius is %f fahrenheit\n”, celsius, fahrenheit); return 0; }  

C Program to Make a Simple Calculator Using switch case

Simple Calculator using switch Statement #include <stdio.h> int main() { char operator; double first, second; printf(“Enter an operator (+, -, *,): “); scanf(“%c”, &operator); printf(“Enter two operands: “); scanf(“%lf %lf”, &first, &second); switch (operator) { case ‘+’: printf(“%.1lf + %.1lf = %.1lf”, first, second, first + second); break; case ‘-‘: printf(“%.1lf – %.1lf = %.1lf”, … Read more