C Program Nigga
C Program Nigga
C Program Nigga
Armstrong number c program: c programming code to check whether a number is armstrong or not. A number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are: 0, 1, 153, 370, 407.
C programming code
#include <stdio.h> int main() { int number, sum = 0, temp, remainder; printf("Enter an integer\n"); scanf("%d",&number); temp = number; while( temp != 0 ) { remainder = temp%10; sum = sum + remainder*remainder*remainder; temp = temp/10; } if ( number == sum ) printf("Entered number is an armstrong number.\n"); else printf("Entered number is not an armstrong number.\n"); return 0; }
Output of program:
We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.
C programming code
#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; }
Output of program:
C programming code
#include <stdio.h> int main() { int year; printf("Enter a year to check if it is a leap year\n"); scanf("%d", &year); if ( year%400 == 0) printf("%d is a leap year.\n", year); else if ( year%100 == 0) printf("%d is not a leap year.\n", year); else if ( year%4 == 0 ) printf("%d is a leap year.\n", year); else printf("%d is not a leap year.\n", year); return 0; }
Output of program:
C programming code
#include <stdio.h> #include <stdlib.h> #include <string.h> void sort_string(char*); int main() { char string[100]; printf("Enter some text\n"); gets(string); sort_string(string); printf("%s\n", string); return 0; } void sort_string(char *s) { int c, d = 0, length; char *pointer, *result, ch; length = strlen(s); result = (char*)malloc(length+1); pointer = s;
for ( ch = 'a' ; ch <= 'z' ; ch++ ) { for ( c = 0 ; c < length ; c++ ) { if ( *pointer == ch ) { *(result+d) = *pointer; d++; } pointer++; } pointer = s; } *(result+d) = '\0'; strcpy(s, result); free(result); }
Output of program:
C programming code
#include <stdio.h> int main() { int m, n, c, d, matrix[10][10], transpose[10][10];
printf("Enter the number of rows and columns of matrix "); scanf("%d%d",&m,&n); printf("Enter the elements of matrix \n"); for( c = 0 ; c < m ; c++ ) { for( d = 0 ; d < n ; d++ ) { scanf("%d",&matrix[c][d]); } } for( c = 0 ; c < m ; c++ ) { for( d = 0 ; d < n ; d++ ) { transpose[d][c] = matrix[c][d]; } } printf("Transpose of entered matrix :-\n"); for( c = 0 ; c < n ; c++ ) { for( d = 0 ; d < m ; d++ ) { printf("%d\t",transpose[c][d]); } printf("\n"); } return 0; }
Output of program:
Diamond pattern in c: This code print diamond pattern of stars. Diamond shape is as follows:
* *** ***** *** *
C programming code
#include <stdio.h> int main() { int n, c, k, space = 1; printf("Enter number of rows\n"); scanf("%d", &n); space = n - 1; for (k = 1; k <= n; k++) { for (c = 1; c <= space; c++) printf(" "); space--; for (c = 1; c <= 2*k-1; c++) printf("*"); printf("\n"); } space = 1; for (k = 1; k <= n - 1; k++) { for (c = 1; c <= space; c++) printf(" "); space++; for (c = 1 ; c <= 2*(n-k)-1; c++) printf("*"); printf("\n"); } return 0; }
Output of program:
} void Reverse() { char c; scanf("%c",&c); if( c != '\n') { Reverse(); printf("%c",c); } } Output Enter a sentence: margorp emosewa awesome program
#include <stdio.h> int main(){ printf("%s",__FILE__); } The output of this program is the location of this C programming file.
Output :
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
2. * C Program to Find the Number of Non Repeated Elements in an Array 3. */ 4. #include <stdio.h> 5. int main() 6. { 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. } printf("\n The array after removing duplicates is: "); for (i = 0; i < size; i++) } } } j = 0; } else if (*(ptr + i) == *(ptr + j)) { k = j; size--; while (k < size) { *(ptr + k) = *(ptr + k + 1); k++; printf("\n Enter size of the array: "); scanf("%d", &n); printf("\n Enter %d elements of an array: ", n); for (i = 0; i < n; i++) scanf("%d", &array[i]); size = n; ptr = array; for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { if (i == j) { continue; int array[50]; int *ptr; int i, j, k, size, n;
$ cc pgm76.c $ a.out Enter size of the array: 6 Enter 6 elements of an array: 12 10 4 10 12 56 The array after removing duplicates is: 12 10 4 56
5. 6. void main() 7. { 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. } printf("Enter size of array : "); scanf("%d", &n); int array[n - 1]; /* array size-1 */ printf("Enter elements into array : \n"); for (i = 0; i < n - 1; i++) scanf("%d", &array[i]); b = array[0]; for (i = 1; i < n - 1; i++) b = b ^ array[i]; for (i = 2, c = 1; i <= n; i++) c = c ^ i; c = c ^ b; printf("Missing element is : %d \n", c); int n, i, j, c, t, b;
$ cc bit30.c $ a.out Enter size of array : 6 Enter elements into array : 1 2 3 5 6 Missing element is : 4
This C Program uses recursive function & copies a string entered by user from one character array to another character array. Here is the source code of the C program to copy string using recursion. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.
1. /* 2. * C Program to Copy One String to Another using Recursion 3. */ 4. #include <stdio.h> 5. 6. void copy(char [], char [], int); 7. 8. int main() 9. { 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. } void copy(char str1[], char str2[], int index) { str2[index] = str1[index]; if (str1[index] == '\0') return; copy(str1, str2, index + 1); } printf("Enter string to copy: "); scanf("%s", str1); copy(str1, str2, 0); printf("Copying success.\n"); printf("The first string is: %s\n", str1); printf("The second string is: %s\n", str2); return 0; char str1[20], str2[20];
Copying success. The first string is: sanfoundry The second string is: sanfoundry
26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. } } } } } } else
i++; k = 0;
p[i][k++] = str[j]; for (i = 0;i < space;i++) { for (j = i + 1;j <= space;j++) { if ((strcmp(p[i], p[j]) > 0)) { strcpy(cmp, p[i]); strcpy(p[i], p[j]); strcpy(p[j], cmp); } //loop for sorting
printf("After sorting string is \n"); for (i = 0;i <= space;i++) { printf("%s ", p[i]);
$ cc string18.c $ a.out Enter the string welcome to sanfoundry's c programming class, welcome to c class again After sorting string is again c c class class programming sanfoundry's to to welcome welcome