Posts

Showing posts from May, 2023

C program to identify Character key

Image
 Q. Write a C program to find which character does the keyword belongs to and do Uppercase to Lowercase and Lowercase to Uppercase Conversion . Ans: #include<stdio.h> int main() { char key; printf("Press any Key:"); scanf("%c",&key); if (key>=65 && key<=90) printf("Uppercase, Lowercase Conversion=%c", key+32); else if (key>=97 && key<=122) printf("Lowercase, Uppercase Conversion=%c", key-32); else if (key>=48 && key<=57) printf("Digit=%c", key); else  printf("Symbol"); return 0; }

C program to find roots of an equation.

Image
 Q. Write a C program to find roots of an equation. Ans: #include <stdio.h> #include <math.h> int main() {     double a, b, c;     double discriminant, root1, root2;     printf("Enter the coefficients (a, b, c) of the quadratic equation:\n");     scanf("%lf %lf %lf", &a, &b, &c);     discriminant = b * b - 4 * a * c;     if (discriminant >= 0) {         root1 = (-b + sqrt(discriminant)) / (2 * a);         root2 = (-b - sqrt(discriminant)) / (2 * a);         printf("Root 1 = %.2lf\n", root1);         printf("Root 2 = %.2lf\n", root2);     } else {         double realPart = -b / (2 * a);         double imaginaryPart = sqrt(-discriminant) / (2 * a);         printf("Root 1 = %.2lf + %.2lfi\n", realPart, imaginaryPart);         printf...

C program to find oldest one among Mr.X Mr.Y and Mr.Z

Image
 Q. Write a C program to find the oldest one among Mr.X, Mr.Y and Mr.Z. Ans: int main() {     int A, B, C;          printf("Enter ages of MrX MrY and MrZ: ");     scanf("%d %d %d", &A, &B, &C);          if(A > B && A > C)     {         printf("MrX is the Oldest.\n", A);     }     else if(B > A && B > C)     {         printf("MrY is the Oldest.\n", B);     }     else if(C > A && C > B)     {         printf("MrZ is the Oldest.\n", C);     }     else     {         printf("All are equal.\n");     }          return 0; }

C program to find Odd and Even Numbers.

Image
 Q. Write a C program to find Odd and Even numbers. Ans: #include <stdio.h> int main() {     int num;          printf("Enter a number: ");     scanf("%d", &num);          if(num % 2 == 0) {         printf("%d is even.", num);     } else {         printf("%d is odd.", num);     }          return 0; }

C program to find if a number is Strong or not.

Image
 Q. Write a C program to find if a number is Strong or not. Ans: #include <stdio.h> int main() {     int num, originalnum, rem, sum = 0;     printf("Enter a positive integer: ");     scanf("%d", &num);     originalnum = num;     while (num > 0)     {         int i = 1, factorial = 1;         rem = num % 10;         // calculate the factorial of the digit         while (i <= rem)         {             factorial *= i;             i++;         }         sum += factorial;         num /= 10;     }     if (sum == originalnum)     {         printf("%d is a strong number.\n", originalnum);     }     else     {   ...

C program to find if a number is prime or not.

Image
 Q. Write a C program to find if a number is prime or not. Ans: #include <stdio.h> int main() {     int n, i = 2;     printf("Enter any number: ");     scanf("%d", &n);     if (n <= 1) {         printf("Input Error\n");     } else {         while (i < n) {             if (n % i == 0) {                 printf("Number is not prime\n");                 break;             }             i++;         }         if (i == n) {             printf("Number is Prime\n");         }     }     return 0; }

C program to find if a number is Armstrong or not.

Image
 Q. Write a C program to find if a number is Armstrong or not. Ans: #include <stdio.h> #include <math.h> int main () {     int num, originalnum, rem, result = 0, n = 0;     printf("Enter an Integer: ");     scanf("%d", &num);     originalnum = num;     while (originalnum != 0)     {         originalnum /= 10;         ++n;     }     originalnum = num;     while (originalnum != 0)     {         rem = originalnum % 10;         result += pow(rem, n);         originalnum /= 10;     }     if (result == num)         printf("%d is an armstrong num", num);     else         printf("%d is not an armstrong num", num);     return 0; }

Find Sum of Digits using C programming

Image
 Q. write a C program to find sum of digits. Ans: #include <stdio.h> int main () { int num, digit, sum=0; printf("Enter a positive integer:"); scanf("%d",&num); while (num>0) { digit = num%10; sum += digit; num /= 10; } printf("The sum of digits is %d",sum); return 0; }

Area and circumference of a Circle using C programming

Image
 Q. Write a C program to find area and circumference of a circle. Ans: #include <stdio.h> #define PI 3.14159 int main() {     float radius, area, circumference;          printf("Enter the radius of the circle: ");     scanf("%f", &radius);          // Calculate area and circumference using formulas     area = PI * radius * radius;     circumference = 2 * PI * radius;          printf("Area of the circle is: %.2f\n", area);     printf("Circumference of the circle is: %.2f\n", circumference);          return 0; }

Fahrenheit to degree Celsius conversion by C programming.

Image
Q. Write a C program to convert degree Fahrenheit to degree Celsius: Ans:  #include <stdio.h> int main() {     float fahrenheit, celsius;          printf("Enter temperature in Fahrenheit: ");     scanf("%f", &fahrenheit);          // Convert Fahrenheit to Celsius using the formula (F - 32) * 5/9     celsius = (fahrenheit - 32) * 5 / 9;          printf("%.2f Fahrenheit is equal to %.2f Celsius.\n", fahrenheit, celsius);          return 0; }

Calculating Distance Between the Two points

Image
 Q. Write a C program to calculate the distance between two points. Ans: #include <stdio.h> #include <math.h> int main() {     float x1, y1, x2, y2, distance;          printf("Enter point 1 (x, y): ");     scanf("%f %f", &x1, &y1);          printf("Enter point 2 (x, y): ");     scanf("%f %f", &x2, &y2);          // Calculate distance using the formula     distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));          printf("The distance between (%.2f, %.2f) and (%.2f, %.2f) is %.2f\n", x1, y1, x2, y2, distance);          return 0; }

Swapping Two Numbers without Using Third Variable

Image
 Q. Write a  C program to swap two numbers without using third variable. Ans: #include <stdio.h> int main() {     int a, b;     printf("Enter two numbers: ");     scanf("%d %d", &a, &b);     printf("Before swapping: a = %d, b = %d\n", a, b);     a = a + b;     b = a - b;     a = a - b;     printf("After swapping: a = %d, b = %d\n", a, b);     return 0; }

"Hello, World" Print using C programming

Image
 "Hello World" Print in C programming Language: Ans: #include <stdio.h> int main() {     printf("Hello, world!\n");     return 0; }