The document contains code snippets for various C programming examples including programs to check prime numbers, palindrome numbers, factorials, reversing numbers, swapping variables, and printing patterns with stars. The examples cover basic programming concepts like loops, functions, user input, and conditional statements.
The document contains code snippets for various C programming examples including programs to check prime numbers, palindrome numbers, factorials, reversing numbers, swapping variables, and printing patterns with stars. The examples cover basic programming concepts like loops, functions, user input, and conditional statements.
The document contains code snippets for various C programming examples including programs to check prime numbers, palindrome numbers, factorials, reversing numbers, swapping variables, and printing patterns with stars. The examples cover basic programming concepts like loops, functions, user input, and conditional statements.
The document contains code snippets for various C programming examples including programs to check prime numbers, palindrome numbers, factorials, reversing numbers, swapping variables, and printing patterns with stars. The examples cover basic programming concepts like loops, functions, user input, and conditional statements.
#include<stdio.h> #include <stdio.h> main() int main() { { int n, c = 2; int n, reverse = 0, temp; printf("Enter a number to check if it is prime\n"); printf("Enter a number to check if it is a palindrome scanf("%d",&n); or not\n"); for ( c = 2 ; c <= n - 1 ; c++ ) scanf("%d",&n); { temp = n; if ( n%c == 0 ) while( temp != 0 ) { { printf("%d is not prime.\n", n); reverse = reverse * 10; break; reverse = reverse + temp%10; } temp = temp/10; } } if ( c == n ) if ( n == reverse ) printf("%d is prime.\n", n); printf("%d is a palindrome number.\n", n); else return 0; printf("%d is not a palindrome number.\n", n); } return 0; 2. Prime number program in c language } #include<stdio.h> 4. Factorial program in c using for loop #include <stdio.h> int main() int main() { { int n, i = 3, count, c; int c, n, fact = 1; printf("Enter a number to calculate it's factorial\n"); printf("Enter the number of prime numbers scanf("%d", &n); required\n"); for (c = 1; c <= n; c++) scanf("%d",&n); fact = fact * c; printf("Factorial of %d = %d\n", n, fact); if ( n >= 1 ) return 0; { } printf("First %d prime numbers are :\n",n); 5. C programming code to reverse a number printf("2\n"); } #include <stdio.h> int main() for ( count = 2 ; count <= n ; ) { { int n, reverse = 0; for ( c = 2 ; c <= i - 1 ; c++ ) printf("Enter a number to reverse\n"); { scanf("%d",&n); if ( i%c == 0 ) while (n != 0) break; { } reverse = reverse * 10; if ( c == i ) reverse = reverse + n%10; { n = n/10; printf("%d\n",i); } count++; printf("Reverse of entered number is = %d\n", } reverse); i++; return 0; } } return 0; } 6. Swapping of two numbers in c 8. Consider the pattern #include <stdio.h> * int main() ** { *** int x, y, temp; **** printf("Enter the value of x and y\n"); ***** scanf("%d%d", &x, &y); #include <stdio.h> printf("Before Swapping\nx = %d\ny = %d\n",x,y); int main() temp = x; { x = y; int n, c, k; y = temp; printf("Enter number of rows\n"); printf("After Swapping\nx = %d\ny = %d\n",x,y); scanf("%d",&n); return 0; for ( c = 1 ; c <= n ; c++ ) } { 7. C programming code for( k = 1 ; k <= c ; k++ ) * printf("*"); *** printf("\n"); ***** } ******* return 0; ********* } #include <stdio.h> int main() { int row, c, n, temp; printf("Enter the number of rows in pyramid of stars you wish to see "); scanf("%d",&n); temp = n; for ( row = 1 ; row <= n ; row++ ) { for ( c = 1 ; c < temp ; c++ ) printf(" "); temp--; for ( c = 1 ; c <= 2*row - 1 ; c++ ) printf("*"); printf("\n"); } return 0; }