├── Full Pyramid Pattern of Numbers ├── Full Pyramid of Numbers in 180 Degree ├── Half Pyramid Pattern of Numbers ├── How to write a function to swap? ├── Inverted Half Pyramid of Numbers ├── Naive Approach to check Prime number in C ├── Program To Check Leap Year ├── Program To Check Neon Number ├── Program To Convert Fahrenheit To Celsius ├── Program To Find Factorial of a Number ├── Program To Find LCM of Two Numbers ├── Program To Print ASCII Value of a Character ├── Program To Print Triangle ├── Program To Reverse a Number ├── Program to Add Two Complex Numbers ├── Program to Calculate Sum of Natural Numbers ├── Program to Check Armstrong Number ├── Program to Check Prime Number using Most Efficient sqrt(N) ├── Program to Check Prime Number using sqrt(N) ├── Program to Check Prime Numbers using Wilson’s Theorem ├── Program to Check Vowel or Consonant ├── Program to Check Whether a Given Number is Even or Odd ├── Program to Check Whether a Number is Prime or Not ├── Program to Check Whether a Number is a Palindrome or Not ├── Program to Display Armstrong Number Between Two Intervals ├── Program to Display Prime Numbers Between Intervals ├── Program to Find All Factors of a Natural Number ├── Program to Find the Size of int, float, double and char ├── Program to Find the Sum of Fibonacci Numbers at Even Indexes up to N Terms ├── Program to Generate Multiplication Table ├── Program to Make a Simple Calculator ├── Program to Print Alphabets From A to Z Using Loop ├── Program to Print Armstrong Numbers Between 1 to 1000 ├── Program to Print Fibonacci Series ├── Program to Print Number Pattern ├── Program to Print Prime Numbers From 1 to N ├── Program to Swap two Numbers ├── README.md ├── program to Check Whether a Number is Positive or Negative or Zero ├── program to Find the Largest Number Among Three Numbers └── program to demonstrate between the given intervals using pow() an armstrong number /Full Pyramid Pattern of Numbers: -------------------------------------------------------------------------------- 1 | Full Pyramid Pattern of Numbers 2 | A full pyramid pattern of numbers is similar to an equilateral triangle. 3 | 4 | Examples: 5 | 6 | 1 7 | 2 2 2 8 | 3 3 3 3 3 9 | 4 4 4 4 4 4 4 10 | 5 5 5 5 5 5 5 5 5 11 | 12 | // C program to print the full pyramid pattern of alphabets 13 | #include 14 | 15 | int main() 16 | { 17 | int rows; 18 | printf("Number of rows: "); 19 | scanf("%d", &rows); 20 | 21 | // first loop to print all rows 22 | for (int i = 1; i <= rows; i++) { 23 | 24 | // inner loop 1 to print white spaces 25 | for (int j = 1; j <= 2 * (rows - i); j++) { 26 | printf(" "); 27 | } 28 | 29 | // inner loop 2 to print numbers 30 | for (int k = 1; k < 2 * i; k++) { 31 | printf("%d ", i); 32 | } 33 | printf("\n"); 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Full Pyramid of Numbers in 180 Degree: -------------------------------------------------------------------------------- 1 | This pattern can be printed by combining half pyramid pattern and an inverted half-pyramid pattern. 2 | 3 | 4 | Examples: 5 | 6 | 1 7 | 22 8 | 333 9 | 4444 10 | 55555 11 | 4444 12 | 333 13 | 22 14 | 1 15 | 16 | ------------------------------------------------- 17 | // C program to print the pyramid pattern 18 | #include 19 | 20 | // Print the pattern upto n 21 | void printPattern(int n) 22 | { 23 | // Printing upper part 24 | for (int i = 1; i <= n; i++) { 25 | for (int j = 1; j <= i; j++) 26 | printf("%d", i); 27 | printf("\n"); 28 | } 29 | 30 | // printing lower part 31 | for (int i = n - 1; i > 0; i--) { 32 | for (int j = i; j > 0; j--) 33 | printf("%d", i); 34 | printf("\n"); 35 | } 36 | } 37 | 38 | // Driver Code 39 | int main() 40 | { 41 | int n = 8; 42 | printPattern(n); 43 | return 0; 44 | } 45 | 46 | // This code is contributed by bhartik021. 47 | 48 | 49 | -------------------------------------------------------------------------------- /Half Pyramid Pattern of Numbers: -------------------------------------------------------------------------------- 1 | 1 2 | 2 2 3 | 3 3 3 4 | 4 4 4 4 5 | 5 5 5 5 5 6 | // C program to print right half pyramid pattern of star 7 | #include 8 | 9 | int main() 10 | { 11 | int rows; 12 | printf("Number of rows: "); 13 | scanf("%d", &rows); 14 | 15 | // first loop for printing rows 16 | for (int i = 1; i <= rows; i++) { 17 | 18 | // second loop for printing similar number in each 19 | // rows 20 | for (int j = 1; j <= i; j++) { 21 | printf("%d ", i); 22 | } 23 | printf("\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /How to write a function to swap?: -------------------------------------------------------------------------------- 1 | // How to write a function to swap? Since we want the local variables of main to modified by swap function, we must them using pointers in C. 2 | // C program to swap two variables using a 3 | // user defined swap() 4 | #include 5 | 6 | // This function swaps values pointed by xp and yp 7 | void swap(int *xp, int *yp) 8 | { 9 | int temp = *xp; 10 | *xp = *yp; 11 | *yp = temp; 12 | } 13 | 14 | int main() 15 | { 16 | int x, y; 17 | printf("Enter Value of x "); 18 | scanf("%d", &x); 19 | printf("\nEnter Value of y "); 20 | scanf("%d", &y); 21 | swap(&x, &y); 22 | printf("\nAfter Swapping: x = %d, y = %d", x, y); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Inverted Half Pyramid of Numbers: -------------------------------------------------------------------------------- 1 | 5 5 5 5 5 2 | 4 4 4 4 3 | 3 3 3 4 | 2 2 5 | 1 6 | 7 | // C program to print inverted half pyramid pattern of number 8 | #include 9 | 10 | int main() 11 | { 12 | int rows; 13 | printf("Number of rows: "); 14 | scanf("%d", &rows); 15 | 16 | // first loop for printing rows 17 | for (int i = rows; i >= 1; i--) { 18 | 19 | // second loop for printing similar number in each rows 20 | for (int j = 1; j <= i; j++) { 21 | printf("%d ", i); 22 | } 23 | printf("\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Naive Approach to check Prime number in C: -------------------------------------------------------------------------------- 1 | // C Program to check for prime number using Naive Approach 2 | #include 3 | 4 | // Function to check prime number 5 | void checkPrime(int N) 6 | { 7 | // initially, flag is set to true or 1 8 | int flag = 1; 9 | 10 | // loop to iterate through 2 to N/2 11 | for (int i = 2; i <= N / 2; i++) { 12 | 13 | // if N is perfectly divisible by i 14 | // flag is set to 0 i.e false 15 | if (N % i == 0) { 16 | flag = 0; 17 | break; 18 | } 19 | } 20 | 21 | if (flag) { 22 | printf("The number %d is a Prime Number\n", N); 23 | } 24 | else { 25 | printf("The number %d is not a Prime Number\n", N); 26 | } 27 | 28 | return; 29 | } 30 | 31 | // driver code 32 | int main() 33 | { 34 | int N = 546; 35 | 36 | checkPrime(N); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Program To Check Leap Year: -------------------------------------------------------------------------------- 1 | // C program to check if a given 2 | // year is leap year or not 3 | #include 4 | #include 5 | 6 | bool checkYear(int year) 7 | { 8 | // If a year is multiple of 400, 9 | // then it is a leap year 10 | if (year % 400 == 0) 11 | return true; 12 | 13 | // Else If a year is multiple of 100, 14 | // then it is not a leap year 15 | if (year % 100 == 0) 16 | return false; 17 | 18 | // Else If a year is multiple of 4, 19 | // then it is a leap year 20 | if (year % 4 == 0) 21 | return true; 22 | return false; 23 | } 24 | 25 | // Driver code 26 | int main() 27 | { 28 | int year = 2000; 29 | 30 | checkYear(year)? printf("Leap Year"): 31 | printf("Not a Leap Year"); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Program To Check Neon Number: -------------------------------------------------------------------------------- 1 | Given a number (num) we need to check whether it is a Neon Number ( i.e. a number where the sum of digits of the square of the number is equal to the number ) and return “true” or “false” accordingly. 2 | Approach 3 | The basic idea is to first calculate the square of the number and then by calculating the sum of digits of the square we can check whether the given number is Neon Number or not. 4 | 5 | Algorithm 6 | At first, we need to find the square of the given number. 7 | Then we need to extract the digits of the square of the number using a loop. 8 | Then we need to calculate the sum of digits. 9 | At last, we need to check the sum with the given number, and the Outcome will be: 10 | ” true ” , if the sum is equal to the given number, or 11 | ” false ” , if the sum is not equal to the given number. 12 | --------------------------------------------------------------------- 13 | // C program to demonstrate whether 14 | // a number is Neon number or not 15 | #include 16 | 17 | int Check_Neon_Number(int num) { 18 | 19 | // Calculating the square of the number 20 | int square = num * num; 21 | 22 | // Copying the square in a variable 23 | // to extract the digit 24 | int n = square; 25 | 26 | // Declaring a variable to store the digits 27 | int digit; 28 | 29 | // Initializing a variable to 30 | // calculate the sum of digits 31 | int sum = 0; 32 | 33 | // To calculate the sum of digits 34 | while (n != 0) { 35 | 36 | // Extracting the digit 37 | digit = n % 10; 38 | sum = sum + digit; 39 | n = n / 10; 40 | } 41 | 42 | // Checking the condition of a Neon Number 43 | if (sum == num) 44 | return 1; // If condition is true. 45 | else 46 | return 0; // If condition is false. 47 | } 48 | 49 | // Driver Code 50 | int main() 51 | { 52 | int num = 9; 53 | 54 | // Calling the function 55 | int ans = Check_Neon_Number(num); 56 | if (ans == 1) 57 | 58 | // The number is Neon 59 | printf("true"); 60 | else 61 | 62 | // The number is not Neon 63 | printf("false"); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Program To Convert Fahrenheit To Celsius: -------------------------------------------------------------------------------- 1 | // Formula for converting Fahrenheit scale to Celsius scale 2 | 3 | // T(°C) = (T(°F) - 32) × 5/9 4 | 5 | // C Program to convert 6 | // Fahrenheit to Celsius 7 | #include 8 | 9 | // Function to convert Degree 10 | // Fahrenheit to Degree Celsius 11 | float fahrenheit_to_celsius(float f) 12 | { 13 | return ((f - 32.0) * 5.0 / 9.0); 14 | } 15 | 16 | // Driver code 17 | int main() 18 | { 19 | float f = 40; 20 | 21 | // Passing parameter to function 22 | printf("Temperature in Degree Celsius : %0.2f", 23 | fahrenheit_to_celsius(f)); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Program To Find Factorial of a Number: -------------------------------------------------------------------------------- 1 | // C program to implement 2 | // the above approach 3 | #include 4 | 5 | // Function to find factorial of 6 | // given number 7 | unsigned int factorial(unsigned int n) 8 | { 9 | int res = 1, i; 10 | for (i = 2; i <= n; i++) 11 | res *= i; 12 | return res; 13 | } 14 | 15 | // Driver code 16 | int main() 17 | { 18 | int num = 5; 19 | printf("Factorial of %d is %d", 20 | num, factorial(num)); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Program To Find LCM of Two Numbers: -------------------------------------------------------------------------------- 1 | // C program to find LCM 2 | // of two numbers 3 | #include 4 | 5 | // Recursive function to return 6 | // gcd of a and b 7 | int gcd(int a, int b) 8 | { 9 | if (a == 0) 10 | return b; 11 | return gcd(b % a, a); 12 | } 13 | 14 | // Function to return LCM of 15 | // two numbers 16 | int lcm(int a, int b) 17 | { 18 | return (a / gcd(a, b)) * b; 19 | } 20 | 21 | // Driver code 22 | int main() 23 | { 24 | int a = 15, b = 20; 25 | printf("LCM of %d and %d is %d ", 26 | a, b, lcm(a, b)); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Program To Print ASCII Value of a Character: -------------------------------------------------------------------------------- 1 | // C program to print 2 | // ASCII Value of Character 3 | #include 4 | 5 | // Driver code 6 | int main() 7 | { 8 | char c = 'k'; 9 | 10 | // %d displays the integer value of 11 | // a character 12 | // %c displays the actual character 13 | printf("The ASCII value of %c is %d", 14 | c, c); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Program To Print Triangle: -------------------------------------------------------------------------------- 1 | * 2 | ** 3 | *** 4 | **** 5 | ***** 6 | ****** 7 | -------------------------------------------- 8 | // C program to print a triangle 9 | #include 10 | 11 | // Driver code 12 | int main() 13 | { 14 | int n = 6; 15 | 16 | // ith row has i elements 17 | for (int i = 1; i <= n; i++) { 18 | for (int j = 1; j <= i; j++) { 19 | printf("*"); 20 | } 21 | printf("\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Program To Reverse a Number: -------------------------------------------------------------------------------- 1 | ITERATIVE WAY 2 | 3 | Algorithm: 4 | 5 | Input: num 6 | (1) Initialize rev_num = 0 7 | (2) Loop while num > 0 8 | (a) Multiply rev_num by 10 and add remainder of num 9 | divide by 10 to rev_num 10 | rev_num = rev_num*10 + num%10; 11 | (b) Divide num by 10 12 | (3) Return rev_num 13 | Example: 14 | 15 | num = 4562 16 | rev_num = 0 17 | rev_num = rev_num *10 + num%10 = 2 18 | num = num/10 = 456 19 | rev_num = rev_num *10 + num%10 = 20 + 6 = 26 20 | num = num/10 = 45 21 | rev_num = rev_num *10 + num%10 = 260 + 5 = 265 22 | num = num/10 = 4 23 | rev_num = rev_num *10 + num%10 = 2650 + 4 = 2654 24 | num = num/10 = 0 25 | --------------------------------------------------------------------------- 26 | 27 | // C program to implement 28 | // the above approach 29 | #include 30 | 31 | // Iterative function to 32 | // reverse digits of num 33 | int reverseDigits(int num) 34 | { 35 | int rev_num = 0; 36 | while (num > 0) 37 | { 38 | rev_num = rev_num * 10 + num % 10; 39 | num = num / 10; 40 | } 41 | return rev_num; 42 | } 43 | 44 | // Driver code 45 | int main() 46 | { 47 | int num = 4562; 48 | printf("Reverse of no. is %d", 49 | reverseDigits(num)); 50 | 51 | getchar(); 52 | return 0; 53 | } 54 | 55 | ------------------------------------ 56 | RECURSIVE WAY : 57 | ------------------------------------ 58 | // C program to reverse digits 59 | // of a number 60 | #include ; 61 | 62 | // Recursive function to 63 | // reverse digits of num 64 | int reversDigits(int num) 65 | { 66 | static int rev_num = 0; 67 | static int base_pos = 1; 68 | if (num > 0) 69 | { 70 | reversDigits(num / 10); 71 | rev_num += (num % 10) * base_pos; 72 | base_pos *= 10; 73 | } 74 | return rev_num; 75 | } 76 | 77 | // Driver code 78 | int main() 79 | { 80 | int num = 4562; 81 | printf("Reverse of no. is %d", 82 | reversDigits(num)); 83 | 84 | getchar(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /Program to Add Two Complex Numbers: -------------------------------------------------------------------------------- 1 | // C program to demonstrate 2 | // addition of complex numbers 3 | #include 4 | 5 | // define a structure for complex number 6 | typedef struct complexNumber { 7 | int real; 8 | int img; 9 | } complex; 10 | 11 | // complex add(complex x, complex y) function C Program to 12 | // Add Two Complex numbers. This function accepts two 13 | // complex type numbers as parameter as return addition of 14 | // them. 15 | complex add(complex x, complex y); 16 | 17 | // driver code 18 | int main() 19 | { 20 | 21 | // define three complex type numbers 22 | complex a, b, sum; 23 | 24 | // first complex number 25 | a.real = 2; 26 | a.img = 3; 27 | 28 | // second complex number 29 | b.real = 4; 30 | b.img = 5; 31 | 32 | // print first complex number 33 | printf("\n a = %d + %di", a.real, a.img); 34 | 35 | // print second complex number 36 | printf("\n b = %d + %di", b.real, b.img); 37 | 38 | // call add(a,b) function and 39 | // pass complex numbers a & b 40 | // as an parameter. 41 | sum = add(a, b); 42 | 43 | // print result 44 | printf("\n sum = %d + %di", sum.real, sum.img); 45 | 46 | return 0; 47 | } 48 | 49 | // complex add(complex x, complex y) 50 | // function definition 51 | complex add(complex x, complex y) 52 | { 53 | 54 | // define a new complex number. 55 | complex add; 56 | 57 | // add real part of a&b 58 | add.real = x.real + y.real; 59 | 60 | // add Imaginary part of a&b 61 | add.img = x.img + y.img; 62 | 63 | // return add 64 | return (add); 65 | } 66 | -------------------------------------------------------------------------------- /Program to Calculate Sum of Natural Numbers: -------------------------------------------------------------------------------- 1 | // C Program to demonstrate 2 | // Sum of Natural Numbers 3 | // using while loops 4 | 5 | #include 6 | int main() 7 | { 8 | int i, s = 0; 9 | int n = 10; 10 | i = 1; 11 | 12 | // while loop executes 13 | // the statements until the 14 | // condition is false 15 | while (i <= n) { 16 | 17 | // adding natural numbers 18 | // up to given number n 19 | s += i; 20 | i++; 21 | } 22 | // printing the result 23 | printf("Sum = %d", s); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Program to Check Armstrong Number: -------------------------------------------------------------------------------- 1 | // C program to check given number is 2 | // Armstrong number or not using Sum 3 | // of Digits 4 | #include 5 | 6 | // Driver code 7 | int main() 8 | { 9 | int n = 153; 10 | int temp = n; 11 | int p = 0; 12 | 13 | // Calculating the sum of individual digits 14 | while (n > 0) { 15 | int rem = n % 10; 16 | p = (p) + (rem * rem * rem); 17 | n = n / 10; 18 | } 19 | 20 | // Condition to check whether the 21 | // value of P equals to user input 22 | // or not. 23 | if (temp == p) { 24 | printf("Yes. It is Armstrong No."); 25 | } 26 | else { 27 | printf("No. It is not an Armstrong No."); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Program to Check Prime Number using Most Efficient sqrt(N): -------------------------------------------------------------------------------- 1 | // C program to check if a number is prime using most efficient sqrt(n) 2 | #include 3 | #include 4 | 5 | // Function check whether a number 6 | // is prime or not 7 | int isPrime(int n) 8 | { 9 | // Check if n=1 or n=0 10 | if (n <= 1) 11 | return 0; 12 | // Check if n=2 or n=3 13 | if (n == 2 || n == 3) 14 | return 1; 15 | // Check whether n is divisible by 2 or 3 16 | if (n % 2 == 0 || n % 3 == 0) 17 | return 0; 18 | // Check from 5 to square root of n 19 | // Iterate i by (i+6) 20 | for (int i = 5; i * i <= n; i = i + 6) 21 | if (n % i == 0 || n % (i + 2) == 0) 22 | return 0; 23 | 24 | return 1; 25 | } 26 | 27 | // Driver Code 28 | int main() 29 | { 30 | int N = 17; 31 | if (isPrime(N)) 32 | printf("%d is a prime number", N); 33 | else 34 | printf("%d is not a prime number", N); 35 | return 0; 36 | } 37 | 38 | // This code is contributed by Susobhan Akhuli 39 | -------------------------------------------------------------------------------- /Program to Check Prime Number using sqrt(N): -------------------------------------------------------------------------------- 1 | // C program to check if a number is prime using sqrt(n) 2 | #include 3 | #include 4 | int main() 5 | { 6 | int N = 17; 7 | int flag = 1; 8 | 9 | double sqroot = sqrt(N); 10 | 11 | // Iterate from 2 to sqrt(n) 12 | for (int i = 2; i <= sqroot; i++) 13 | { 14 | 15 | // If n is divisible by any number between 2 and 16 | // sqrt(n), it is not prime 17 | if (N % i == 0) { 18 | flag = 0; 19 | break; 20 | } 21 | } 22 | 23 | if (flag) { 24 | printf("%d is a prime number", N); 25 | } 26 | else { 27 | printf("%d is not a prime number", N); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Program to Check Prime Numbers using Wilson’s Theorem: -------------------------------------------------------------------------------- 1 | // We will evaluate the (N-1)! + 1, where N is the given number. 2 | // Then we will check the divisibility of (N – 1)! + 1 with N, i.e. ((N – 1)! + ) % N == 0. 3 | // If the remainder is zero, then N is a prime number. 4 | // If the remainder is not zero, then N is not prime. 5 | 6 | #include 7 | 8 | // utility function to evaluate factorial 9 | long long int getFactorial(int n) 10 | { 11 | long long int f = 1; 12 | for (int i = 2; i <= n; i++) { 13 | f *= i; 14 | } 15 | return f; 16 | } 17 | 18 | // function to check prime number 19 | void checkPrime(int N) 20 | { 21 | 22 | long long fact = getFactorial(N - 1); 23 | 24 | if (fact % N == N - 1) { 25 | printf("The number %d is a prime number.", N); 26 | } 27 | else { 28 | printf("The number %d is not a prime number.", N); 29 | } 30 | 31 | return; 32 | } 33 | 34 | // driver code 35 | int main() 36 | { 37 | int N = 17; 38 | 39 | checkPrime(N); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Program to Check Vowel or Consonant: -------------------------------------------------------------------------------- 1 | // C Program to Check Vowel or 2 | // Consonant using switch case 3 | #include 4 | 5 | int isVowel(char ch) 6 | { 7 | int check = 0; 8 | switch (ch) 9 | { 10 | case 'a': 11 | case 'e': 12 | case 'i': 13 | case 'o': 14 | case 'u': 15 | case 'A': 16 | case 'E': 17 | case 'I': 18 | case 'O': 19 | case 'U': 20 | check = 1; 21 | } 22 | return check; 23 | } 24 | 25 | int main() 26 | { 27 | // 1 means Vowel 28 | printf("a is %d", 29 | isVowel('a')); 30 | 31 | // 0 means Consonant 32 | printf("x is %d", 33 | isVowel('x')); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Program to Check Whether a Given Number is Even or Odd: -------------------------------------------------------------------------------- 1 | // C program for the above approach 2 | #include 3 | 4 | // Function to check if a 5 | // number is even or odd 6 | void checkEvenOdd(int N) 7 | { 8 | // Find remainder 9 | int r = N % 2; 10 | 11 | // Condition for even 12 | if (r == 0) { 13 | printf("Even"); 14 | } 15 | 16 | // Otherwise 17 | else { 18 | printf("Odd"); 19 | } 20 | } 21 | 22 | // Driver Code 23 | int main() 24 | { 25 | // Given number N 26 | int N = 101; 27 | 28 | // Function Call 29 | checkEvenOdd(N); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Program to Check Whether a Number is Prime or Not: -------------------------------------------------------------------------------- 1 | We check the divisibility of the given number N with all the numbers starting from 2 to (N/2). 2 | If it is completely divisible by any number i.e. remainder is zero after division, then the number is not a prime number. 3 | If it is not completely divisible by a number between 2 and (N/2), then the number is a prime number. 4 | 5 | // C Program to check for prime number using Naive Approach 6 | #include 7 | 8 | // Function to check prime number 9 | void checkPrime(int N) 10 | { 11 | // initially, flag is set to true or 1 12 | int flag = 1; 13 | 14 | // loop to iterate through 2 to N/2 15 | for (int i = 2; i <= N / 2; i++) { 16 | 17 | // if N is perfectly divisible by i 18 | // flag is set to 0 i.e false 19 | if (N % i == 0) { 20 | flag = 0; 21 | break; 22 | } 23 | } 24 | 25 | if (flag) { 26 | printf("The number %d is a Prime Number\n", N); 27 | } 28 | else { 29 | printf("The number %d is not a Prime Number\n", N); 30 | } 31 | 32 | return; 33 | } 34 | 35 | // driver code 36 | int main() 37 | { 38 | int N = 546; 39 | 40 | checkPrime(N); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Program to Check Whether a Number is a Palindrome or Not: -------------------------------------------------------------------------------- 1 | // C program to check whether 2 | // a number is palindrome or not 3 | #include 4 | 5 | // Driver code 6 | int main() 7 | { 8 | // Define variables 9 | 10 | // This is our given number 11 | int original_number = 12321; 12 | 13 | // This variable stored reversed digit 14 | int reversed = 0; 15 | 16 | int num = original_number; 17 | 18 | // Execute a while loop to reverse 19 | // digits of given number 20 | while (num != 0) 21 | { 22 | int r = num % 10; 23 | reversed = reversed * 10 + r; 24 | num /= 10; 25 | } 26 | 27 | // Compare original_number with 28 | // reversed number 29 | if (original_number == reversed) 30 | { 31 | printf(" Given number %d is a palindrome number", 32 | original_number); 33 | } 34 | else 35 | { 36 | printf(" Given number %d is not a palindrome number", 37 | original_number); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Program to Display Armstrong Number Between Two Intervals: -------------------------------------------------------------------------------- 1 | // C program to demonstrate an armstrong number 2 | // between the given intervals 3 | 4 | #include 5 | 6 | int main() 7 | { 8 | int s = 1, e = 500, num, n, arm = 0, i, sum; 9 | 10 | // iterating the for loop 11 | // using the given intervals 12 | for (i = s; i <= e; i++) { 13 | num = i; 14 | sum = i; 15 | 16 | // finding the armstrong number 17 | while (num != 0) { 18 | n = num % 10; 19 | arm = arm + (n * n * n); 20 | num = num / 10; 21 | } 22 | 23 | // if number is equal to 24 | // the arm then it is a 25 | // armstrong number 26 | if (sum == arm) { 27 | printf("%d\n", i); 28 | } 29 | arm = 0; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Program to Display Prime Numbers Between Intervals: -------------------------------------------------------------------------------- 1 | // C Program to Display Prime 2 | // Numbers Between Intervals 3 | #include 4 | 5 | // Driver code 6 | int main() 7 | { 8 | // Declare the variables 9 | int a, b, i, j, flag; 10 | 11 | // Ask user to enter lower value 12 | // of interval 13 | printf("Enter lower bound of the interval: "); 14 | 15 | // Take input 16 | scanf("%d", &a); 17 | 18 | // Ask user to enter upper value 19 | // of interval 20 | printf("Enter upper bound of the interval: "); 21 | 22 | // Take input 23 | scanf("%d", &b); 24 | 25 | // Print display message 26 | printf("Prime numbers between %d and %d are: ", 27 | a, b); 28 | 29 | // Traverse each number in the interval 30 | // with the help of for loop 31 | for (i = a; i <= b; i++) 32 | { 33 | // Skip 0 and 1 as they are 34 | // neither prime nor composite 35 | if (i == 1 || i == 0) 36 | continue; 37 | 38 | // flag variable to tell 39 | // if i is prime or not 40 | flag = 1; 41 | 42 | for (j = 2; j <= i / 2; ++j) 43 | { 44 | if (i % j == 0) 45 | { 46 | flag = 0; 47 | break; 48 | } 49 | } 50 | 51 | // flag = 1 means i is prime 52 | // and flag = 0 means i is 53 | // not prime 54 | if (flag == 1) 55 | printf("%d ", i); 56 | } 57 | 58 | return 0; 59 | } 60 | 61 | ---------------------------------------------------- 62 | Approach 3: (Using Sieve of Eratosthenes Method) 63 | ---------------------------------------------------- 64 | 65 | // C program to find the prime numbers 66 | // between a given interval using Sieve of Eratosthenes 67 | #include 68 | #include 69 | #include 70 | 71 | void SieveOfEratosthenes(int srt, int n) 72 | { 73 | // Create a boolean array "prime[srt to n]" and 74 | // initialize all entries it as true. A value in 75 | // prime[i] will finally be false if i is Not a prime, 76 | // else true. 77 | bool prime[n + 1]; 78 | memset(prime, true, sizeof(prime)); 79 | prime[0] = false; 80 | prime[1] = false; 81 | 82 | for (int p = 2; p * p <= n; p++) { 83 | // If prime[p] is not changed, then it is a prime 84 | if (prime[p] == true) { 85 | // Update all multiples of p greater than or 86 | // equal to the square of it numbers which are 87 | // multiple of p and are less than p^2 are 88 | // already been marked. 89 | for (int i = p * p; i <= n; i += p) 90 | prime[i] = false; 91 | } 92 | } 93 | 94 | // Print all prime numbers 95 | for (int p = srt; p <= n; p++) 96 | if (prime[p]) 97 | printf("%d ", p); 98 | } 99 | 100 | // Driver Code 101 | int main() 102 | { 103 | int srt = 1; 104 | int end = 10; 105 | SieveOfEratosthenes(srt, end); 106 | return 0; 107 | } 108 | 109 | // This code is contributed by Susobhan Akhuli 110 | -------------------------------------------------------------------------------- /Program to Find All Factors of a Natural Number: -------------------------------------------------------------------------------- 1 | A Naive Solution would be to iterate all the numbers from 1 to n, checking if that number divides n and printing it. Below is a program for the same: 2 | // C implementation of Naive 3 | // method to print all divisors 4 | #include 5 | 6 | // Function to print the divisors 7 | void printDivisors(int n) 8 | { 9 | for (int i = 1; i <= n; i++) 10 | if (n % i == 0) 11 | printf("%d ", i); 12 | } 13 | 14 | // Driver code 15 | int main() 16 | { 17 | printf("The divisors of 100 are: "); 18 | printDivisors(100); 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------- 23 | // A Better (than Naive) Solution 24 | // to find all divisors 25 | #include 26 | #include 27 | 28 | // Function to print the divisors 29 | void printDivisors(int n) 30 | { 31 | // Note that this loop runs till 32 | // square root 33 | for (int i = 1; i <= sqrt(n); i++) 34 | { 35 | if (n % i == 0) 36 | { 37 | // If divisors are equal, 38 | // print only one 39 | if (n / i == i) 40 | printf("%d ", i); 41 | 42 | // Otherwise print both 43 | else 44 | printf("%d %d ", i, n / i); 45 | } 46 | } 47 | } 48 | 49 | // Driver code 50 | int main() 51 | { 52 | printf("The divisors of 100 are: "); 53 | printDivisors(100); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Program to Find the Size of int, float, double and char: -------------------------------------------------------------------------------- 1 | // Data Type Memory (bytes) Range Format Specifier 2 | // short int 2 -32,768 to 32,767 %hd 3 | // unsigned short int 2 0 to 65,535 %hu 4 | // unsigned int 4 0 to 4,294,967,295 %u 5 | // int 4 -2,147,483,648 to 2,147,483,647 %d 6 | // long int 4 -2,147,483,648 to 2,147,483,647 %ld 7 | // unsigned long int 4 0 to 4,294,967,295 %lu 8 | // long long int 8 -(2^63) to (2^63)-1 %lld 9 | // unsigned long long int 8 0 to 18,446,744,073,709,551,615 %llu 10 | // signed char 1 -128 to 127 %c 11 | // unsigned char 1 0 to 255 %c 12 | // float 4 %f 13 | // double 8 %lf 14 | // long double 12 %Lf 15 | 16 | // To find the size of the four variables: 17 | 18 | // The four types of variables are defined in integerType, floatType, doubleType and charType. 19 | // The size of the variables is calculated using the sizeof() operator. 20 | 21 | // C program to find the size of int, char, 22 | // float and double data types 23 | 24 | #include 25 | 26 | int main() 27 | { 28 | int integerType; 29 | char charType; 30 | float floatType; 31 | double doubleType; 32 | 33 | // Calculate and Print 34 | // the size of integer type 35 | printf("Size of int is: %ld",sizeof(integerType)); 36 | 37 | // Calculate and Print 38 | // the size of charType 39 | printf("Size of char is: %ld",sizeof(charType)); 40 | 41 | // Calculate and Print 42 | // the size of floatType 43 | printf("Size of float is: %ld",sizeof(floatType)); 44 | 45 | // Calculate and Print 46 | // the size of doubleType 47 | printf("Size of double is: %ld",sizeof(doubleType)); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Program to Find the Sum of Fibonacci Numbers at Even Indexes up to N Terms: -------------------------------------------------------------------------------- 1 | Approach: 2 | This approach includes solving the problem directly by finding all Fibonacci numbers till 2n and adding up only the even indices numbers from the array. 3 | // C Program to find the sum of 4 | // even-indices Fibonacci numbers 5 | #include 6 | 7 | // Computes value of the first 8 | // fibonacci numbers and stores 9 | // the even-indexed sum 10 | int calculateEvenSum(int n) 11 | { 12 | // return 0 if n is equals or less than to 0 13 | if (n <= 0) 14 | return 0; 15 | 16 | int fibo[2 * n + 1]; 17 | fibo[0] = 0, fibo[1] = 1; 18 | 19 | // Initialize the result 20 | int sum = 0; 21 | 22 | // Adding the remaining terms 23 | for (int i = 2; i <= 2 * n; i++) { 24 | fibo[i] = fibo[i - 1] + fibo[i - 2]; 25 | 26 | // For even indices 27 | if (i % 2 == 0) 28 | sum += fibo[i]; 29 | } 30 | 31 | // Return alternating sum 32 | return sum; 33 | } 34 | 35 | // Driver Code 36 | int main() 37 | { 38 | 39 | // Get n 40 | int n = 5; 41 | 42 | // calculateEvenSum(n) function is computed and return 43 | // the sum of even-indices Fibonacci numbers. 44 | int sum = calculateEvenSum(n); 45 | 46 | // display result 47 | printf("Even indexed Fibonacci Sum upto %d terms = %d", 48 | n, sum); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Program to Generate Multiplication Table: -------------------------------------------------------------------------------- 1 | // C program to Demonstrate the 2 | // Multiplication table of a number 3 | #include 4 | void print_table(int range, int num) 5 | { 6 | // Declaring a variable mul to store the product. 7 | int mul; 8 | 9 | // For loop to calculate the Multiplication table. 10 | for (int i = 1; i <= range; i++) { 11 | // To store the product. 12 | mul = num * i; 13 | 14 | // Printing the Multiplication Table. 15 | printf("%d * %d = %d", num, i, mul); 16 | 17 | // Proceeding to the next line. 18 | printf("\n"); 19 | } 20 | } 21 | // Driver code 22 | int main() 23 | { 24 | 25 | // The range of the 26 | // Multiplication table 27 | int range = 10; 28 | 29 | // The number to calculate the 30 | // Multiplication table 31 | int num = 5; 32 | 33 | // Calling the Function. 34 | print_table(range, num); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Program to Make a Simple Calculator: -------------------------------------------------------------------------------- 1 | // C Program to Make a Simple Calculator 2 | // Using switch case 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | char ch; 9 | double a, b; 10 | while (1) { 11 | printf("Enter an operator (+, -, *, /), if want to exit press x: "); 12 | scanf(" %c", &ch); 13 | // to exit 14 | if (ch == 'x') 15 | exit(0); 16 | printf("Enter two first and second operand: "); 17 | scanf("%lf %lf",&a,&b); 18 | // Using switch case we will differentiate 19 | // operations based on different operator 20 | switch (ch) { 21 | // For Addition 22 | case '+': 23 | printf("%.1lf + %.1lf = %.1lf\n", a, b, a + b); 24 | break; 25 | // For Subtraction 26 | case '-': 27 | printf("%.1lf - %.1lf = %.1lf\n", a, b, a - b); 28 | break; 29 | // For Multiplication 30 | case '*': 31 | printf("%.1lf * %.1lf = %.1lf\n", a, b, a * b); 32 | break; 33 | // For Division 34 | case '/': 35 | printf("%.1lf / %.1lf = %.1lf\n", a, b, a / b); 36 | break; 37 | // If operator doesn't match any case constant 38 | default: 39 | printf("Error! please write a valid operator\n"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Program to Print Alphabets From A to Z Using Loop: -------------------------------------------------------------------------------- 1 | // C Program to display alphabets using ASCII values 2 | #include 3 | 4 | int main() 5 | { 6 | int i; 7 | printf("Alphabets from (A-Z) are:\n"); 8 | 9 | // ASCII value of A=65 and Z=90 10 | for (i = 65; i <= 90; i++) { 11 | // Integer i with %c will be converted to character 12 | // before printing.%c will takes its equivalent 13 | // character value 14 | printf("%c ", i); 15 | } 16 | 17 | printf("\nAlphabets from (a-z) are:\n"); 18 | 19 | // ASCII value of a=97 and z=122 20 | for (i = 97; i <= 122; i++) { 21 | // Integer i with %c will be converted to character 22 | // before printing.%c will takes its equivalent 23 | // character value 24 | printf("%c ", i); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Program to Print Armstrong Numbers Between 1 to 1000: -------------------------------------------------------------------------------- 1 | Example: 2 | 3 | 153 4 | 13 + 53 + 33 5 | 1 + 125 + 27 = 153 6 | Approach : 7 | Count the number of digits in the number. 8 | Then calculate the sum of digits raised to the power of the number of digits in that number. 9 | Check whether it is equal to the number, if yes then print it. 10 | 11 | // C Program to Display Armstrong 12 | // numbers between 1 to 1000 13 | #include 14 | #include 15 | 16 | int main() 17 | { 18 | int i, digit1, digit2, digit3, sum, num; 19 | printf("All Armstrong number between 1 and 1000 are:\n"); 20 | 21 | // This loop will run for 1 to 1000 22 | for (i = 1; i <= 1000; i++) 23 | { 24 | num = i; 25 | // All single digit numbers are Armstrong number. 26 | if (num <= 9) 27 | { 28 | printf("%d ", num); 29 | } 30 | else 31 | { 32 | sum = pow(num % 10, 3) + pow((num % 100 - num % 10) / 10, 3) + pow((num % 1000 - num % 100) / 100, 3); 33 | if (sum == i) 34 | { 35 | printf("%d ", i); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Program to Print Fibonacci Series: -------------------------------------------------------------------------------- 1 | // C Program to print first n terms of Fibonacci series using recursion 2 | // C Program to print the Fibonacci series using recursion 3 | #include 4 | 5 | // first two values 6 | int prev1 = 1; 7 | int prev2 = 0; 8 | 9 | // recursive function to print the fibonacci series 10 | void fib(int n) 11 | { 12 | if (n < 3) { 13 | return; 14 | } 15 | int fn = prev1 + prev2; 16 | prev2 = prev1; 17 | prev1 = fn; 18 | printf("%d ", fn); 19 | return fib(n - 1); 20 | } 21 | 22 | // function that handles the first two terms and calls the 23 | // recursive function 24 | void printFib(int n) 25 | { 26 | // when the number of terms is less than 1 27 | if (n < 1) { 28 | printf("Invalid number of terms\n"); 29 | } 30 | // when the number of terms is 1 31 | else if (n == 1) { 32 | printf("%d ", 0); 33 | } 34 | // when the number of terms is 2 35 | else if (n == 2) { 36 | printf("%d %d", 0, 1); 37 | } 38 | // number of terms greater than 2 39 | else { 40 | printf("%d %d ", 0, 1); 41 | fib(n); 42 | } 43 | return; 44 | } 45 | 46 | // driver code 47 | int main() 48 | { 49 | int n = 9; 50 | printFib(n); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /Program to Print Number Pattern: -------------------------------------------------------------------------------- 1 | 1 2 | 232 3 | 34543 4 | 4567654 5 | 567898765 6 | ---------------------------------- 7 | // C program to illustrate the above 8 | // given pattern of numbers. 9 | #include 10 | 11 | int main() 12 | { 13 | int n = 5, i, j, num = 1, gap; 14 | 15 | gap = n - 1; 16 | 17 | for (j = 1; j <= n; j++) { 18 | num = j; 19 | 20 | for (i = 1; i <= gap; i++) 21 | printf(" "); 22 | 23 | gap--; 24 | 25 | for (i = 1; i <= j; i++) { 26 | printf("%d", num); 27 | num++; 28 | } 29 | num--; 30 | num--; 31 | for (i = 1; i < j; i++) { 32 | printf("%d", num); 33 | num--; 34 | } 35 | printf(""); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Program to Print Prime Numbers From 1 to N: -------------------------------------------------------------------------------- 1 | // Approach 1: To check whether every number is prime or not 2 | // First, we take the number N as the input. 3 | // Then use a loop to iterate the numbers from 1 to N. 4 | // Then check for each number to be a prime number. 5 | 6 | // C program to display Prime numbers till N 7 | 8 | #include 9 | #include 10 | 11 | // This function is to check 12 | // if a given number is prime 13 | bool isPrime(int n) 14 | { 15 | // since 0 and 1 is not prime 16 | // number return false. 17 | if (n == 1 || n == 0) 18 | return false; 19 | 20 | // Run a loop from 2 to n-1 21 | for (int i = 2; i < n; i++) { 22 | 23 | // if the number is divisible by i, then n is not a 24 | // prime number, otherwise n is prime number. 25 | if (n % i == 0) 26 | return false; 27 | } 28 | return true; 29 | } 30 | 31 | // Driver code 32 | int main() 33 | { 34 | int N = 10; 35 | 36 | // check for the every number from 1 to N 37 | for (int i = 1; i <= N; i++) { 38 | 39 | // check if i (current number) is prime 40 | if (isPrime(i)) { 41 | printf("%d ", i); 42 | } 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Program to Swap two Numbers: -------------------------------------------------------------------------------- 1 | // The idea is simple 2 | 3 | // Assign x to a temp variable : temp = x 4 | // Assign y to x : x = y 5 | // Assign temp to y : y = temp 6 | 7 | // C program to swap two variables 8 | #include 9 | 10 | int main() 11 | { 12 | int x, y; 13 | printf("Enter Value of x "); 14 | scanf("%d", &x); 15 | printf("\nEnter Value of y "); 16 | scanf("%d", &y); 17 | 18 | int temp = x; 19 | x = y; 20 | y = temp; 21 | 22 | printf("\nAfter Swapping: x = %d, y = %d", x, y); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 100 Interview Questions - 2 | 3 | 1. **Question 1:** 4 | **Question:** Write a C program that prints numbers from 1 to 10 using a `for` loop. 5 | **Expected Output:** 6 | ``` 7 | 1 2 3 4 5 6 7 8 9 10 8 | ``` 9 | 10 | 2. **Question 2:** 11 | **Question:** Create a C program that prints the even numbers from 2 to 20 using a `while` loop. 12 | **Expected Output:** 13 | ``` 14 | 2 4 6 8 10 12 14 16 18 20 15 | ``` 16 | 17 | 3. **Question 3:** 18 | **Question:** Develop a program that calculates the sum of numbers from 1 to 100 using a `for` loop. 19 | **Expected Output:** 20 | ``` 21 | The sum of numbers from 1 to 100 is 5050. 22 | ``` 23 | 24 | 4. **Question 4:** 25 | **Question:** Write a C program that prints the first 10 terms of the Fibonacci sequence using a `do-while` loop. 26 | **Expected Output:** 27 | ``` 28 | Fibonacci series: 0 1 1 2 3 5 8 13 21 34 29 | ``` 30 | 31 | 5. **Question 5:** 32 | **Question:** Create a program that prompts the user to enter a positive integer and then prints the multiplication table for that number from 1 to 10 using a `for` loop. 33 | **Expected Output:** 34 | ``` 35 | Enter a number: 7 36 | Multiplication table for 7: 37 | 7 x 1 = 7 38 | 7 x 2 = 14 39 | ... 40 | 7 x 10 = 70 41 | ``` 42 | 43 | 6. **Question 6:** 44 | **Question:** Develop a C program that prints a pattern of asterisks in the shape of a right-angled triangle using nested `for` loops. 45 | **Expected Output:** 46 | ``` 47 | * 48 | ** 49 | *** 50 | **** 51 | ***** 52 | ``` 53 | 54 | 7. **Question 7:** 55 | **Question:** Write a program that calculates the factorial of a user-entered number using a `while` loop. 56 | **Expected Output:** 57 | ``` 58 | Enter a number: 5 59 | The factorial of 5 is 120. 60 | ``` 61 | 62 | 8. **Question 8:** 63 | **Question:** Create a C program that checks if a user-entered number is a prime number using a `for` loop. 64 | **Expected Output:** 65 | ``` 66 | Enter a number: 17 67 | 17 is a prime number. 68 | ``` 69 | 70 | 9. **Question 9:** 71 | **Question:** Develop a program that finds and displays the prime numbers in a given range (e.g., 1 to 100) using a `for` loop. 72 | **Expected Output:** 73 | ``` 74 | Prime numbers in the range 1 to 100 are: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 75 | ``` 76 | 77 | 10. **Question 10:** 78 | **Question:** Write a C program that prints the ASCII values and characters for all printable characters (from ' ' to '~') using a `for` loop. 79 | **Expected Output:** 80 | ``` 81 | ASCII values and characters for printable characters: 82 | ' ' (Space) - ASCII: 32 83 | '!' - ASCII: 33 84 | '"' - ASCII: 34 85 | ... 86 | '~' - ASCII: 126 87 | ``` 88 | 89 | 90 | 11. **Question 11:** 91 | **Question:** Create a C program that calculates the sum of all even numbers between 1 and 50 using a `for` loop. 92 | **Expected Output:** 93 | ``` 94 | The sum of even numbers from 1 to 50 is 650. 95 | ``` 96 | 97 | 12. **Question 12:** 98 | **Question:** Write a C program that checks if a user-entered number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper divisors (excluding itself). 99 | **Expected Output:** 100 | ``` 101 | Enter a number: 28 102 | 28 is a perfect number. 103 | ``` 104 | 105 | 13. **Question 13:** 106 | **Question:** Develop a program that calculates the factorial of a user-entered number using a `do-while` loop. 107 | **Expected Output:** 108 | ``` 109 | Enter a number: 6 110 | The factorial of 6 is 720. 111 | ``` 112 | 113 | 14. **Question 14:** 114 | **Question:** Create a C program that prints the squares of numbers from 1 to 10 using a `for` loop. 115 | **Expected Output:** 116 | ``` 117 | 1^2 = 1 118 | 2^2 = 4 119 | 3^2 = 9 120 | ... 121 | 10^2 = 100 122 | ``` 123 | 124 | 15. **Question 15:** 125 | **Question:** Write a C program that calculates the sum of a geometric series (1 + 2 + 4 + 8 + ... + 2^n) using a `for` loop. Prompt the user for the number of terms (n). 126 | **Expected Output:** 127 | ``` 128 | Enter the number of terms (n): 5 129 | The sum of the geometric series is 31. 130 | ``` 131 | 132 | 16. **Question 16:** 133 | **Question:** Develop a C program that prints the first n terms of the square root series (1, sqrt(2), sqrt(3), ...) using a `for` loop. 134 | **Expected Output:** 135 | ``` 136 | Enter the number of terms (n): 4 137 | Square root series: 1.000 1.414 1.732 2.000 138 | ``` 139 | 140 | 17. **Question 17:** 141 | **Question:** Create a program that calculates the sum of an arithmetic series (3 + 7 + 11 + ... + 3n - 1) using a `for` loop. Prompt the user for the number of terms (n). 142 | **Expected Output:** 143 | ``` 144 | Enter the number of terms (n): 5 145 | The sum of the arithmetic series is 75. 146 | ``` 147 | 148 | 18. **Question 18:** 149 | **Question:** Write a C program that prints the numbers from 100 to 1 in reverse order using a `while` loop. 150 | **Expected Output:** 151 | ``` 152 | 100 99 98 97 96 ... 4 3 2 1 153 | ``` 154 | 155 | 19. **Question 19:** 156 | **Question:** Develop a program that generates and displays the Collatz sequence starting from a user-entered number. The Collatz sequence for a positive integer n is defined as follows: if n is even, divide it by 2; if n is odd, multiply it by 3 and add 1. 157 | **Expected Output:** 158 | ``` 159 | Enter a number: 10 160 | Collatz sequence: 10 5 16 8 4 2 1 161 | ``` 162 | 163 | 20. **Question 20:** 164 | **Question:** Create a C program that calculates and displays the GCD (greatest common divisor) of two user-entered numbers using the Euclidean algorithm in a `while` loop. 165 | **Expected Output:** 166 | ``` 167 | Enter the first number: 24 168 | Enter the second number: 18 169 | The GCD of 24 and 18 is 6. 170 | ``` 171 | 172 | 21. **Question 21:** 173 | **Question:** Write a C program to check if a user-entered number is a palindrome. A palindrome is a number that reads the same forwards and backwards. 174 | **Expected Output:** 175 | ``` 176 | Enter a number: 121 177 | 121 is a palindrome. 178 | ``` 179 | 180 | 22. **Question 22:** 181 | **Question:** Create a C program that prints a pattern of stars in the shape of a diamond using nested `for` loops. 182 | **Expected Output:** 183 | ``` 184 | * 185 | *** 186 | ***** 187 | ******* 188 | ***** 189 | *** 190 | * 191 | ``` 192 | 193 | 23. **Question 23:** 194 | **Question:** Develop a program that generates and displays a random number between 1 and 100. Prompt the user to guess the number, and provide hints. 195 | **Expected Output:** 196 | ``` 197 | Guess the number (1-100): 50 198 | Try higher. 199 | Guess the number (1-100): 75 200 | Try lower. 201 | Guess the number (1-100): 63 202 | Congratulations! You guessed the number (63). 203 | ``` 204 | 205 | 24. **Question 24:** 206 | **Question:** Write a C program that calculates the sum of the series 1 - 1/2 + 1/3 - 1/4 + ... - 1/n for a user-entered positive integer n. 207 | **Expected Output:** 208 | ``` 209 | Enter a positive integer (n): 5 210 | The sum of the series is -0.78333. 211 | ``` 212 | 213 | 25. **Question 25:** 214 | **Question:** Create a C program that simulates a simple game of rock-paper-scissors. The user plays against the computer. 215 | **Expected Output:** 216 | ``` 217 | Choose your move (rock, paper, scissors): rock 218 | Computer's move: scissors 219 | You win! 220 | ``` 221 | 222 | 26. **Question 26:** 223 | **Question:** Develop a program that calculates the value of π using the Leibniz formula. Prompt the user for the number of terms (n) to use in the formula. 224 | **Expected Output:** 225 | ``` 226 | Enter the number of terms (n): 1000000 227 | The value of π is approximately 3.14159. 228 | ``` 229 | 230 | 27. **Question 27:** 231 | **Question:** Write a C program that generates a random password of a specified length (e.g., 8 characters) containing a mix of letters (both uppercase and lowercase) and numbers. 232 | **Expected Output:** 233 | ``` 234 | Your random password: K4rW8p7X 235 | ``` 236 | 237 | 28. **Question 28:** 238 | **Question:** Create a C program that simulates a simple guessing game. The program generates a random number between 1 and 100, and the user must guess it within a limited number of attempts. 239 | **Expected Output:** 240 | ``` 241 | Guess the number (1-100). You have 5 attempts. 242 | Attempt 1: 50 243 | Try higher. 244 | Attempt 2: 75 245 | Try lower. 246 | ... 247 | Congratulations! You guessed the number (63) in 4 attempts. 248 | ``` 249 | 250 | 29. **Question 29:** 251 | **Question:** Develop a program that calculates the sum of all prime numbers between 1 and 100 using a `for` loop. 252 | **Expected Output:** 253 | ``` 254 | The sum of prime numbers between 1 and 100 is 1060. 255 | ``` 256 | 257 | 30. **Question 30:** 258 | **Question:** Write a C program that generates and displays a magic square of order 3. A magic square is a square matrix in which the sum of the numbers in each row, column, and both main diagonals is the same. 259 | **Expected Output:** 260 | ``` 261 | Magic Square: 262 | 2 7 6 263 | 9 5 1 264 | 4 3 8 265 | ``` 266 | 267 | 31. **Question 31:** 268 | **Question:** Create a C program that prints a right-angled triangle pattern of asterisks using nested `for` loops. 269 | **Expected Output:** 270 | ``` 271 | * 272 | ** 273 | *** 274 | **** 275 | ***** 276 | ``` 277 | 278 | 32. **Question 32:** 279 | **Question:** Develop a program that prints a hollow square pattern of asterisks with a user-specified side length. 280 | **Expected Output:** 281 | ``` 282 | Enter the side length of the square: 5 283 | ***** 284 | * * 285 | * * 286 | * * 287 | ***** 288 | ``` 289 | 290 | 33. **Question 33:** 291 | **Question:** Write a C program that prints a mirrored right-angled triangle pattern of numbers. 292 | **Expected Output:** 293 | ``` 294 | 1 295 | 12 296 | 123 297 | 1234 298 | 12345 299 | ``` 300 | 301 | 34. **Question 34:** 302 | **Question:** Create a program that prints a pyramid pattern of asterisks with a user-specified height. 303 | **Expected Output:** 304 | ``` 305 | * 306 | *** 307 | ***** 308 | ******* 309 | ********* 310 | ``` 311 | 312 | 35. **Question 35:** 313 | **Question:** Develop a C program that prints a diamond pattern of numbers with a user-specified number of rows. 314 | **Expected Output:** 315 | ``` 316 | 1 317 | 121 318 | 12321 319 | 1234321 320 | 123454321 321 | 1234321 322 | 12321 323 | 121 324 | 1 325 | ``` 326 | 327 | 36. **Question 36:** 328 | **Question:** Write a C program that prints a right-angled triangle pattern of uppercase letters starting from 'A'. 329 | **Expected Output:** 330 | ``` 331 | A 332 | AB 333 | ABC 334 | ABCD 335 | ABCDE 336 | ``` 337 | 338 | 37. **Question 37:** 339 | **Question:** Create a program that prints a hollow right-angled triangle pattern of asterisks with a user-specified height. 340 | **Expected Output:** 341 | ``` 342 | Enter the height of the triangle: 5 343 | * 344 | ** 345 | * * 346 | * * 347 | ***** 348 | ``` 349 | 350 | 38. **Question 38:** 351 | **Question:** Develop a C program that prints an inverted pyramid pattern of numbers. 352 | **Expected Output:** 353 | ``` 354 | 12345 355 | 1234 356 | 123 357 | 12 358 | 1 359 | ``` 360 | 361 | 39. **Question 39:** 362 | **Question:** Write a program that prints a square pattern of numbers with each row starting from 1 and incrementing by 1. 363 | **Expected Output:** 364 | ``` 365 | 12345 366 | 12345 367 | 12345 368 | 12345 369 | 12345 370 | ``` 371 | 372 | 40. **Question 40:** 373 | **Question:** Create a C program that prints a pattern of the letter 'X' formed by asterisks. 374 | **Expected Output:** 375 | ``` 376 | * * 377 | * * 378 | * * 379 | * * 380 | * 381 | * * 382 | * * 383 | * * 384 | * * 385 | ``` 386 | 387 | 41. **Question 41:** 388 | **Question:** Write a C program to calculate the sum of the first 10 natural numbers using a `while` loop. 389 | **Expected Output:** 390 | ``` 391 | The sum of the first 10 natural numbers is 55. 392 | ``` 393 | 394 | 42. **Question 42:** 395 | **Question:** Create a C program that prints a hollow square pattern of asterisks with a user-specified side length. 396 | **Expected Output:** 397 | ``` 398 | Enter the side length of the square: 5 399 | ***** 400 | * * 401 | * * 402 | * * 403 | ***** 404 | ``` 405 | 406 | 43. **Question 43:** 407 | **Question:** Write a C program that checks if a given number is a power of two (2^n). 408 | **Expected Output:** 409 | ``` 410 | Enter a number: 16 411 | 16 is a power of 2. 412 | ``` 413 | 414 | 44. **Question 44:** 415 | **Question:** Create a C program to find the factorial of a user-entered number using a `while` loop. 416 | **Expected Output:** 417 | ``` 418 | Enter a number: 5 419 | The factorial of 5 is 120. 420 | ``` 421 | 422 | 45. **Question 45:** 423 | **Question:** Develop a program that calculates the sum of all odd numbers from 1 to 100 using a `for` loop. 424 | **Expected Output:** 425 | ``` 426 | The sum of odd numbers from 1 to 100 is 2500. 427 | ``` 428 | 429 | 46. **Question 46:** 430 | **Question:** Write a C program that calculates the sum of the digits of a user-entered integer. 431 | **Expected Output:** 432 | ``` 433 | Enter an integer: 12345 434 | The sum of the digits is 15. 435 | ``` 436 | 437 | 47. **Question 47:** 438 | **Question:** Create a program that calculates the LCM (Least Common Multiple) of two user-entered numbers. 439 | **Expected Output:** 440 | ``` 441 | Enter two numbers (separated by a space): 12 18 442 | The LCM of 12 and 18 is 36. 443 | ``` 444 | 445 | 48. **Question 48:** 446 | **Question:** Develop a C program that checks if a user-entered string is a palindrome (reads the same forwards and backwards). 447 | **Expected Output:** 448 | ``` 449 | Enter a string: radar 450 | "radar" is a palindrome. 451 | ``` 452 | 453 | 49. **Question 49:** 454 | **Question:** Write a C program that calculates the sum of all the multiples of 3 and 5 between 1 and 100. 455 | **Expected Output:** 456 | ``` 457 | The sum of multiples of 3 and 5 between 1 and 100 is 2418. 458 | ``` 459 | 460 | 50. **Question 50:** 461 | **Question:** Create a program that finds and displays the first N prime numbers. 462 | **Expected Output:** 463 | ``` 464 | Enter the value of N: 10 465 | The first 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29 466 | ``` 467 | 468 | 51. **Question 51:** 469 | **Question:** Develop a program that checks if a user-entered year is a leap year using a logical operator. 470 | **Expected Output:** 471 | ``` 472 | Enter a year: 2024 473 | 2024 is a leap year. 474 | ``` 475 | 476 | 52. **Question 52:** 477 | **Question:** Write a C program that calculates and displays the GCD (greatest common divisor) of two user-entered numbers. 478 | **Expected Output:** 479 | ``` 480 | Enter two numbers (separated by a space): 24 18 481 | The GCD of 24 and 18 is 6. 482 | ``` 483 | 484 | 53. **Question 53:** 485 | **Question:** Create a program that calculates the sum of squares of the first N natural numbers. 486 | **Expected Output:** 487 | ``` 488 | Enter the value of N: 4 489 | The sum of squares of the first 4 natural numbers is 30. 490 | ``` 491 | 492 | 54. **Question 54:** 493 | **Question:** Develop a program that finds the smallest and largest elements in an array of integers. 494 | **Expected Output:** 495 | ``` 496 | Enter the number of elements in the array: 6 497 | Enter the elements (separated by spaces): 18 7 42 10 31 55 498 | The smallest element in the array is 7, and the largest element is 55. 499 | ``` 500 | 501 | 55. **Question 55:** 502 | **Question:** Write a C program that generates and displays a random password of a specified length (e.g., 8 characters) using a logical approach. 503 | **Expected Output:** 504 | ``` 505 | Your random password: K4rW8p7X 506 | ``` 507 | 508 | 56. **Question 56:** 509 | **Question:** Create a program that checks if a user-entered number is a perfect number. 510 | **Expected Output:** 511 | ``` 512 | Enter a number: 28 513 | 28 is a perfect number. 514 | ``` 515 | 516 | 57. **Question 57:** 517 | **Question:** Develop a C program that prints a pattern of stars in the shape of a right-angled triangle using nested `for` loops. 518 | **Expected Output:** 519 | ``` 520 | * 521 | ** 522 | *** 523 | **** 524 | ***** 525 | ``` 526 | 527 | 58. **Question 58:** 528 | **Question:** Write a program that calculates the sum of even numbers between 1 and 50 using a `while` loop. 529 | **Expected Output:** 530 | ``` 531 | The sum of even numbers from 1 to 50 is 650. 532 | ``` 533 | 534 | 59. **Question 59:** 535 | **Question:** Create a C program that checks if a given number is a palindrome using a logical approach. 536 | **Expected Output:** 537 | ``` 538 | Enter a number: 121 539 | 121 is a palindrome. 540 | ``` 541 | 542 | 60. **Question 60:** 543 | **Question:** Write a C program that checks if a user-entered string is a palindrome using logical operations. 544 | **Expected Output:** 545 | ``` 546 | Enter a string: radar 547 | "radar" is a palindrome. 548 | ``` 549 | 550 | 61. **Question 61:** 551 | **Question:** Develop a C program that finds and displays the first N Fibonacci numbers. 552 | **Expected Output:** 553 | ``` 554 | Enter the value of N: 8 555 | The first 8 Fibonacci numbers are: 0 1 1 2 3 5 8 13 556 | ``` 557 | 558 | 62. **Question 62:** 559 | **Question:** Write a C program to reverse a user-entered string without using any built-in string functions. 560 | **Expected Output:** 561 | ``` 562 | Enter a string: programming 563 | Reversed string: gnimmargorp 564 | ``` 565 | 566 | 63. **Question 63:** 567 | **Question:** Create a program that checks if a given year is a leap year or not using a logical approach. 568 | **Expected Output:** 569 | ``` 570 | Enter a year: 2100 571 | 2100 is not a leap year. 572 | ``` 573 | 574 | 64. **Question 64:** 575 | **Question:** Develop a C program that calculates the product of digits in a user-entered integer. 576 | **Expected Output:** 577 | ``` 578 | Enter an integer: 12345 579 | The product of the digits is 120. 580 | ``` 581 | 582 | 65. **Question 65:** 583 | **Question:** Write a program that determines if a user-entered number is prime or composite. 584 | **Expected Output:** 585 | ``` 586 | Enter a number: 17 587 | 17 is a prime number. 588 | ``` 589 | 590 | 66. **Question 66:** 591 | **Question:** Create a C program that counts and displays the number of words in a user-entered sentence. 592 | **Expected Output:** 593 | ``` 594 | Enter a sentence: This is a sample sentence. 595 | The number of words in the sentence is 5. 596 | ``` 597 | 598 | 67. **Question 67:** 599 | **Question:** Develop a program that calculates the sum of all natural numbers divisible by 3 or 5 between 1 and 100. 600 | **Expected Output:** 601 | ``` 602 | The sum of natural numbers divisible by 3 or 5 between 1 and 100 is 2418. 603 | ``` 604 | 605 | 68. **Question 68:** 606 | **Question:** Write a C program to check if a user-entered number is an Armstrong number (narcissistic number). 607 | **Expected Output:** 608 | ``` 609 | Enter a number: 153 610 | 153 is an Armstrong number. 611 | ``` 612 | 613 | 69. **Question 69:** 614 | **Question:** Create a program that calculates the area of a triangle when the user provides the lengths of its three sides. 615 | **Expected Output:** 616 | ``` 617 | Enter the lengths of three sides (separated by spaces): 5 12 13 618 | The area of the triangle is 30 square units. 619 | ``` 620 | 621 | 70. **Question 70:** 622 | **Question:** Develop a C program to check if a user-entered number is a strong number. 623 | **Expected Output:** 624 | ``` 625 | Enter a number: 145 626 | 145 is a strong number. 627 | ``` 628 | 629 | 71. **Question 71:** 630 | **Question:** Write a C program that checks if a user-entered number is a palindrome using a logical approach. 631 | **Expected Output:** 632 | ``` 633 | Enter a number: 121 634 | 121 is a palindrome. 635 | ``` 636 | 637 | 72. **Question 72:** 638 | **Question:** Create a program that calculates the sum of squares of the first N even natural numbers. 639 | **Expected Output:** 640 | ``` 641 | Enter the value of N: 4 642 | The sum of squares of the first 4 even natural numbers is 120. 643 | ``` 644 | 645 | 73. **Question 73:** 646 | **Question:** Develop a C program that checks if a user-entered year is a leap year without using logical operators. 647 | **Expected Output:** 648 | ``` 649 | Enter a year: 2024 650 | 2024 is a leap year. 651 | ``` 652 | 653 | 74. **Question 74:** 654 | **Question:** Write a program that calculates the sum of cubes of the first N odd natural numbers. 655 | **Expected Output:** 656 | ``` 657 | Enter the value of N: 5 658 | The sum of cubes of the first 5 odd natural numbers is 135. 659 | ``` 660 | 661 | 75. **Question 75:** 662 | **Question:** Create a C program that checks if a user-entered string is a pangram (contains all English alphabet letters). 663 | **Expected Output:** 664 | ``` 665 | Enter a string: The quick brown fox jumps over the lazy dog. 666 | The string is a pangram. 667 | ``` 668 | 669 | 76. **Question 76:** 670 | **Question:** Develop a program that calculates and displays the HCF (Highest Common Factor) of two user-entered numbers. 671 | **Expected Output:** 672 | ``` 673 | Enter two numbers (separated by a space): 24 36 674 | The HCF of 24 and 36 is 12. 675 | ``` 676 | 677 | 77. **Question 77:** 678 | **Question:** Write a C program that calculates the sum of the squares of prime numbers between 1 and 50. 679 | **Expected Output:** 680 | ``` 681 | The sum of squares of prime numbers between 1 and 50 is 2418. 682 | ``` 683 | 684 | 78. **Question 78:** 685 | **Question:** Create a program that checks if a user-entered number is an abundant number. 686 | **Expected Output:** 687 | ``` 688 | Enter a number: 12 689 | 12 is an abundant number. 690 | ``` 691 | 692 | 79. **Question 79:** 693 | **Question:** Develop a C program that checks if a given string is a palindrome using pointers. 694 | **Expected Output:** 695 | ``` 696 | Enter a string: racecar 697 | "racecar" is a palindrome. 698 | ``` 699 | 700 | 80. **Question 80:** 701 | **Question:** Write a program that calculates the sum of digits of a user-entered number using a logical approach. 702 | **Expected Output:** 703 | ``` 704 | Enter a number: 12345 705 | The sum of the digits is 15. 706 | ``` 707 | 708 | 81. **Question 81:** 709 | **Question:** Create a C program to find and display the prime factors of a user-entered number. 710 | **Expected Output:** 711 | ``` 712 | Enter a number: 60 713 | The prime factors of 60 are: 2 3 5 714 | ``` 715 | 716 | 82. **Question 82:** 717 | **Question:** Develop a program that calculates the difference between the sum of squares and the square of the sum of the first N natural numbers. 718 | **Expected Output:** 719 | ``` 720 | Enter the value of N: 5 721 | The difference is 170. 722 | ``` 723 | 724 | 83. **Question 83:** 725 | **Question:** Write a C program that checks if a user-entered number is a strong number using logical operations. 726 | **Expected Output:** 727 | ``` 728 | Enter a number: 145 729 | 145 is a strong number. 730 | ``` 731 | 732 | 84. **Question 84:** 733 | **Question:** Create a program that calculates and displays the LCM (Least Common Multiple) of three user-entered numbers. 734 | **Expected Output:** 735 | ``` 736 | Enter three numbers (separated by spaces): 12 18 24 737 | The LCM of 12, 18, and 24 is 72. 738 | ``` 739 | 740 | 85. **Question 85:** 741 | **Question:** Develop a C program that calculates the sum of natural numbers divisible by both 3 and 5 between 1 and 100. 742 | **Expected Output:** 743 | ``` 744 | The sum of natural numbers divisible by both 3 and 5 between 1 and 100 is 315. 745 | ``` 746 | 747 | 86. **Question 86:** 748 | **Question:** Write a program that checks if a user-entered number is a Kaprekar number. 749 | **Expected Output:** 750 | ``` 751 | Enter a number: 9 752 | 9 is a Kaprekar number. 753 | ``` 754 | 755 | 87. **Question 87:** 756 | **Question:** Create a C program to find the sum of the series: 1 + 1/4 + 1/9 + 1/16 + ... + 1/n^2. 757 | **Expected Output:** 758 | ``` 759 | Enter the value of n: 4 760 | The sum of the series is approximately 1.42361. 761 | ``` 762 | 763 | 88. **Question 88:** 764 | **Question:** Develop a program that checks if a user-entered sentence is a palindrome (ignoring spaces and case). 765 | **Expected Output:** 766 | ``` 767 | Enter a sentence: A man, a plan, a canal, Panama. 768 | The sentence is a palindrome. 769 | ``` 770 | 771 | 89. **Question 89:** 772 | **Question:** Write a C program that calculates and displays the difference between the sum of even-indexed elements and odd-indexed elements in an array. 773 | **Expected Output:** 774 | ``` 775 | Enter the number of elements in the array: 5 776 | Enter the elements (separated by spaces): 4 7 2 9 6 777 | The difference is 7. 778 | ``` 779 | 780 | 90. **Question 90:** 781 | **Question:** Create a program that calculates the value of π using the Monte Carlo method for a user-specified number of iterations. 782 | **Expected Output:** 783 | ``` 784 | Enter the number of iterations: 1000000 785 | The value of π is approximately 3.14159. 786 | ``` 787 | 788 | 91. **Question 91:** 789 | **Question:** Write a C program that generates the first N prime numbers and displays them in a spiral pattern. 790 | **Expected Output:** 791 | ``` 792 | Enter the value of N: 10 793 | Prime Numbers in a Spiral: 794 | 17 16 15 14 13 795 | 18 5 4 3 12 796 | 19 6 1 2 11 797 | 20 7 8 9 10 798 | 21 22 23 24 25 799 | ``` 800 | 801 | 92. **Question 92:** 802 | **Question:** Create a program that simulates a basic ATM machine. The user can withdraw, deposit, or check the balance. 803 | **Expected Output:** (Interaction example) 804 | ``` 805 | Welcome to the ATM! 806 | Select an option: 807 | 1. Withdraw 808 | 2. Deposit 809 | 3. Check Balance 810 | 4. Exit 811 | Enter your choice: 1 812 | Enter the amount to withdraw: 100 813 | Successfully withdrawn $100. Current balance: $900 814 | ``` 815 | 816 | 93. **Question 93:** 817 | **Question:** Develop a C program that simulates a simple tic-tac-toe game for two players. 818 | **Expected Output:** (Sample game interaction) 819 | ``` 820 | Player 1, enter your move (row and column): 2 1 821 | Board after move: 822 | 1 - - 823 | X - - 824 | - - - 825 | Player 2, enter your move (row and column): 1 2 826 | Board after move: 827 | 1 O - 828 | X - - 829 | - - - 830 | ... 831 | ``` 832 | 833 | 94. **Question 94:** 834 | **Question:** Write a C program to find and display the longest word in a user-entered sentence. 835 | **Expected Output:** 836 | ``` 837 | Enter a sentence: The quick brown fox jumps over the lazy dog. 838 | The longest word in the sentence is "jumps". 839 | ``` 840 | 841 | 95. **Question 95:** 842 | **Question:** Create a program that generates a random maze and finds a path from the start to the end point. 843 | **Expected Output:** 844 | ``` 845 | Random Maze: 846 | # # # # # # # # # # # 847 | S # # # 848 | # # # # # # # # # 849 | # # # # # 850 | # # # # # # # # # 851 | # # # E 852 | # # # # # # # # # # # 853 | Path: 854 | S * * * * * * * 855 | * # * # 856 | # # # # # # # # 857 | # # # # # 858 | # # # # # # # # 859 | # # # * 860 | # # # # # # # # # # 861 | ``` 862 | 863 | 96. **Question 96:** 864 | **Question:** Develop a C program that simulates a simple Blackjack card game between the user and the computer. 865 | **Expected Output:** (Sample game interaction) 866 | ``` 867 | Welcome to Blackjack! 868 | Player's Hand: 7 9 869 | Computer's Hand: 5 ? 870 | Do you want to hit or stand? (h/s): h 871 | Player's Hand: 7 9 Q 872 | ... 873 | ``` 874 | 875 | 97. **Question 97:** 876 | **Question:** Write a program to calculate the sum of prime numbers in the Fibonacci sequence up to a user-entered limit. 877 | **Expected Output:** 878 | ``` 879 | Enter the limit: 50 880 | The sum of prime Fibonacci numbers up to 50 is 104. 881 | ``` 882 | 883 | 98. **Question 98:** 884 | **Question:** Create a C program that counts the number of occurrences of each word in a user-entered text document. 885 | **Expected Output:** (Sample input and output) 886 | ``` 887 | Enter the text: 888 | This is a sample text. This is a sample document. 889 | Word Count: 890 | "This" occurs 2 times. 891 | "is" occurs 2 times. 892 | "a" occurs 2 times. 893 | "sample" occurs 2 times. 894 | "text." occurs 1 time. 895 | "document." occurs 1 time. 896 | ``` 897 | 898 | 99. **Question 99:** 899 | **Question:** Develop a program that calculates and displays the sum of digits of factorial of a user-entered number. 900 | **Expected Output:** 901 | ``` 902 | Enter a number: 5 903 | The sum of digits of 5! is 3. 904 | ``` 905 | 906 | 100. **Question 100:** 907 | **Question:** Write a C program that generates and displays the first N numbers of the Lucas sequence. 908 | **Expected Output:** 909 | ``` 910 | Enter the value of N: 8 911 | The first 8 Lucas numbers are: 2 1 3 4 7 11 18 29 912 | ``` 913 | 914 | 915 | 916 | -------------------------------------------------------------------------------- /program to Check Whether a Number is Positive or Negative or Zero: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int A; 6 | 7 | printf("Enter the number A: "); 8 | scanf("%d", &A); 9 | 10 | if (A > 0) 11 | printf("%d is positive.", A); 12 | else if (A < 0) 13 | printf("%d is negative.", A); 14 | else if (A == 0) 15 | printf("%d is zero.", A); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /program to Find the Largest Number Among Three Numbers: -------------------------------------------------------------------------------- 1 | // 1. Start 2 | // 2. Read the three numbers to be compared, as A, B and C. 3 | // 3. Check if A is greater than B. 4 | 5 | // 3.1 If true, then check if A is greater than C. 6 | // 3.1.1 If true, print 'A' as the greatest number. 7 | // 3.1.2 If false, print 'C' as the greatest number. 8 | 9 | // 3.2 If false, then check if B is greater than C. 10 | // 3.1.1 If true, print 'B' as the greatest number. 11 | // 3.1.2 If false, print 'C' as the greatest number. 12 | // 4. End 13 | 14 | #include 15 | 16 | int main() 17 | { 18 | int A, B, C; 19 | 20 | printf("Enter the numbers A, B and C: "); 21 | scanf("%d %d %d", &A, &B, &C); 22 | 23 | if (A >= B && A >= C) 24 | printf("%d is the largest number.", A); 25 | 26 | if (B >= A && B >= C) 27 | printf("%d is the largest number.", B); 28 | 29 | if (C >= A && C >= B) 30 | printf("%d is the largest number.", C); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /program to demonstrate between the given intervals using pow() an armstrong number: -------------------------------------------------------------------------------- 1 | 2 | 3 | // C program to demonstrate an armstrong number 4 | // between the given intervals using pow() 5 | 6 | #include 7 | #include 8 | int main() 9 | { 10 | 11 | int s = 1, e = 500, num1, n, arm = 0, i, num2, c; 12 | // iterating the for loop using the given intervals 13 | for (i = s; i <= e; i++) { 14 | num1 = i; 15 | num2 = i; 16 | // finding the number of digits 17 | while (num1 != 0) { 18 | num1 = num1 / 10; 19 | ++c; 20 | } 21 | // finding the armstrong number 22 | while (num2 != 0) { 23 | n = num2 % 10; 24 | arm = arm + pow(n, 3); 25 | num2 = num2 / 10; 26 | } 27 | // if number is equal to the arm then it is a 28 | // armstrong number 29 | if (arm == i) { 30 | printf("%d\n", i); 31 | } 32 | arm = 0; 33 | c = 0; 34 | } 35 | return 0; 36 | } 37 | --------------------------------------------------------------------------------