├── helloworld └── helloword.c ├── ASCII └── ASCII.C ├── README.md ├── cube_of └── cube_of.c ├── single_digit └── single_digit.c ├── table └── table.c ├── triangle └── triangle.c ├── oddeven └── oddeven.c ├── hcf └── hcf.c ├── converting └── converting.c ├── G.C.D └── G.C.D.c ├── time └── time.c ├── count_bit └── count_bit.c ├── finding_third_angle └── finding_third_angle.c ├── Palindrome_pattern └── Palindrome_pattern.c ├── counting_zero └── counting_zero.c ├── power └── power.c ├── yes_no └── yes_no.c ├── character_reader └── character_reader.c ├── binary_to_decimal └── binary_to_decimal.c ├── countingvowels └── countingvowels.c ├── star_triangle └── star_triangle.c ├── find_9 └── find_9.c ├── frequency_of_letters └── frequency_of_letters.c ├── without_sign_multiple └── without_sign_multiple.c ├── decimal_to_octal └── decimal_to_octal.c ├── e_power └── e_power.c ├── palindrome └── palindrome.c ├── leap_year └── leap_year.c ├── LCM └── LCM.c ├── octal_to_decimal └── octal_to_decimal.c ├── search_array └── search_array.c ├── read_words └── read_words.c ├── integertype └── inetegertype.c ├── armstrong └── armstrong.c ├── cube_or_not └── cube_or_not.c ├── occurence └── occurence.c ├── roots_qe └── roots_qe.c ├── largest_and_smallest_number └── largest_and_smallest_number.c ├── octal_to_binary └── octal_to_binary.c ├── determinant_matrix └── determinant_matrix.c ├── converting_time └── converting_time.c ├── fibrico_series └── fibrico_series.c ├── volume_circle └── volume_circle.c ├── dynamic_memory └── dynamic_memory.c ├── temperature └── temperature.c ├── Sum_A.P └── Sum_A.P.c ├── quadrant └── quadrant.c ├── daysofmonth └── daysofmonth.c ├── structure_records └── structure_records.c ├── max_product └── max_product.c ├── counting_string └── counting_string.c ├── currency_convert └── currency_convert.c ├── max_column_value └── max_column_value.c ├── guess_number └── guess_number.c ├── matrix_transpose └── matrix_transpose.c ├── upper_triangle └── upper_triangle.c ├── anagram └── anagram.c ├── divisors_9 └── divisors_9.c ├── delete_array └── delete_array.c ├── diamond_pattern └── diamond_pattern.c ├── aboudant_number └── aboudant_number.c ├── joshphine_ring └── joshphine_ring.c ├── non_repeating_array └── non_repeating_array.c ├── identity_matrix └── identity_matrix.c ├── binomial_coefficient_table └── binomial_cofficient_table.c ├── automorphic_number └── automorphic_number.c ├── add_inches └── add_inches.c ├── calculating_emi └── calculating_emi.c ├── decimal_to_hexadecimal └── decimal_to_hexadecimal.c ├── numbersname └── numbersname.c ├── switchcase2 └── switchcase2.c ├── notes └── notes.c ├── convertor └── convertor.c ├── finding_angles_on_clock └── finding_angles_on_clock.c ├── percentage_divisor └── percentage_divisor.c ├── standard_derivation └── standard_derivation.c ├── rearranging_numbers └── rearranging_numbers.c ├── matrix_addition └── matrix_addition.c ├── addition_of_matrix └── addition_of_matrix.c ├── subtraction_matrix └── subtraction_matrix.c ├── ugly_number └── ugly_number.c ├── hollow_diamond_pattern └── hollow_diamond_pattern.c ├── LICENSE ├── Disarium_Number └── Disarium_Number.c ├── Kapersker_number └── Kapresker_number.c ├── maximum_value_row └── maximum_value_row.c ├── checking_subset └── checking_subset.c ├── switchcase └── switchcase.c ├── counting_alpha_number └── counting_alpha_number.c ├── electricity_bill └── electricity_bill.c ├── saving └── saving.c ├── sum_max_column_row └── sum_max_column_row.c ├── calculte_median └── calculate_median.c ├── multiplying_matrix └── multiplying_matrix.c ├── password_conformation └── password_conformation.c ├── dice └── dice.c └── singly_linked_number └── singly_linked_number.c /helloworld/helloword.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | printf("Hello, C language"); 5 | return 0; 6 | } -------------------------------------------------------------------------------- /ASCII/ASCII.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char c; 5 | printf("Enter the alphabet which ASCII do you want : "); 6 | scanf("%c",&c); 7 | printf("The ASCII code of %c is : %d",c,c); 8 | return 0; 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 100DaysOfCode challenge on C programming language 2 | #100DaysOfCode - learning c programming by coding one program each day. 3 | # You can find 100 C programs/ codes in this repository..... 4 | #Challenge Completed 5 | 6 | -------------------------------------------------------------------------------- /cube_of/cube_of.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int i,ctr; 5 | printf("Input number of terms : "); 6 | scanf("%d", &ctr); 7 | for(i=1;i<=ctr;i++) 8 | { 9 | printf("Number is : %d and cube of the %d is :%d \n",i,i, (i*i*i)); 10 | } 11 | } -------------------------------------------------------------------------------- /single_digit/single_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int addDigits(int num) { 4 | return num - (num - 1) / 9 * 9; 5 | } 6 | 7 | int main() { 8 | int n; 9 | printf("Enter the number : "); 10 | scanf("%d",&n); 11 | printf("\nInitial number is %d, Single digit number is %d.", n, addDigits(n)); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /table/table.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j; 5 | printf("Let me know, which interger's multiplication table you want ? "); 6 | scanf("%d",&i); 7 | printf("\n The multiplication table of %d is:\n",i); 8 | for(j = 1; j <= 10; j++) { 9 | printf("\t %d * %d = %d\n", i, j, i*j); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /triangle/triangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j; 5 | char name[20]; 6 | printf("Enter your name : "); 7 | scanf("%[^\n]",&name); 8 | for(i = 0; name[i] != 0 ; i++ ) { 9 | for(j = 0; j <= i; j++) { 10 | printf("%c\n ",name[j]); 11 | } 12 | printf(" \n"); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /oddeven/oddeven.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | long long integer; 5 | printf("Enter your phone number : "); // To check your phone number, whether is it even or odd. 6 | scanf("%lld",&integer); 7 | if(integer % 2 == 0) { 8 | printf("\nGiven integer %lld is even ", integer); 9 | } 10 | else { 11 | printf("\nGiven integer %lld is odd ", integer); 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /hcf/hcf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n1, n2, i, hcf; 5 | 6 | printf("\n\tEnter two integers: "); 7 | scanf("%d %d", &n1, &n2); 8 | 9 | for(i=1; i <= n1 && i <= n2; ++i) { 10 | if(n1%i==0 && n2%i==0){ 11 | hcf = i; 12 | } 13 | } 14 | 15 | printf("\n\tH.C.F of %d and %d is %d", n1, n2, hcf); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /converting/converting.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | float cm, meter, km; 5 | 6 | 7 | printf("Enter length in centimeter: "); 8 | scanf("%f", &cm); 9 | 10 | 11 | meter = cm / 100.0; 12 | km = cm / 100000.0; 13 | 14 | printf("Length in Meter = %.2f m \n", meter); 15 | printf("Length in Kilometer = %.2f km", km); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /G.C.D/G.C.D.c: -------------------------------------------------------------------------------- 1 | #include 2 | int hcf(int n1, int n2); 3 | int main() { 4 | int n1, n2; 5 | printf("Enter two positive integers: "); 6 | scanf("%d %d", &n1, &n2); 7 | printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2)); 8 | return 0; 9 | } 10 | 11 | int hcf(int n1, int n2) { 12 | if (n2 != 0) 13 | return hcf(n2, n1 % n2); 14 | else 15 | return n1; 16 | } -------------------------------------------------------------------------------- /time/time.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int main() { 6 | time_t s, val = 1; 7 | struct tm* current_time; 8 | 9 | s = time(NULL); 10 | 11 | current_time = localtime(&s); 12 | 13 | printf("%02d:%02d:%02d", 14 | current_time->tm_hour, 15 | current_time->tm_min, 16 | current_time->tm_sec); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /count_bit/count_bit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int count_bit_1(int n) { 4 | int counter; 5 | 6 | for (counter = 0; n; counter++) { 7 | n &= n-1; 8 | } 9 | return counter; 10 | } 11 | 12 | int main(int argc, char *argv[]) { 13 | int num; 14 | 15 | printf("Please input a number:"); 16 | scanf("%d", &num); 17 | printf("Number in hex is %x\n", num); 18 | 19 | printf("%d bit '1' in %d\n", count_bit_1(num), num); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /finding_third_angle/finding_third_angle.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int ang1, ang2, ang3; /*are three angles of a triangle */ 5 | 6 | 7 | printf("Input two angles of triangle separated by comma : "); 8 | scanf("%d, %d", &ang1, &ang2); 9 | 10 | ang3 = 180 - (ang1 + ang2); /* Calculates the third angle */ 11 | 12 | printf("Third angle of the triangle : %d\n", ang3); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Palindrome_pattern/Palindrome_pattern.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int main() { 6 | int i,j,k,l,n; 7 | printf("Enter the number of rows : "); 8 | scanf("%d",&n); 9 | for(i = 1; i <= n; i++) { 10 | for(k = 1; k <= i; k++) { 11 | printf("%d ",k); 12 | } 13 | for(l = i-1; l >= 1; l--) { 14 | printf("%d ",l); 15 | } 16 | printf("\n "); 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /counting_zero/counting_zero.c: -------------------------------------------------------------------------------- 1 | static int trailing_Zeroes(int n) 2 | { 3 | int number = 0; 4 | while (n > 0) { 5 | number += n / 5; 6 | n /= 5; 7 | } 8 | return number; 9 | } 10 | int main(void) 11 | { 12 | int n = 4; 13 | printf("\nNumber of trailing zeroes of factorial %d is %d ", n, trailing_Zeroes(n)); 14 | n = 5; 15 | printf("\nNumber of trailing zeroes of factorial %d is %d ", n, trailing_Zeroes(n)); 16 | return 0; 17 | } -------------------------------------------------------------------------------- /power/power.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int power(int n1, int n2); 4 | 5 | int main() { 6 | 7 | printf("Enter base number: "); 8 | scanf("%d", &base); 9 | 10 | printf("\n\nEnter Power factor: "); 11 | scanf("%d", &exp); 12 | 13 | printf("\n\n\n\t\t\t%d^%d = %d", base, exp, power(base, exp)); 14 | 15 | return 0; 16 | } 17 | 18 | int power(int b, int e) { 19 | if(e == 0) 20 | return 1; 21 | 22 | return (b*power(b, e-1)); 23 | } -------------------------------------------------------------------------------- /yes_no/yes_no.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | char answer; 6 | 7 | printf("\nWould you like to play? Enter Y or N: \n"); 8 | scanf(" %c", &answer); 9 | 10 | printf("\n answer is %c\n", answer); 11 | while (answer == 'Y'){ 12 | 13 | printf("Success!"); 14 | 15 | printf("\nDo you want to play again? Y or N: \n"); 16 | 17 | scanf(" %c", &answer); 18 | printf("\n answer is %c\n", answer); 19 | 20 | } 21 | printf("GoodBye!"); 22 | return 0; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /character_reader/character_reader.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char str[1000], ch; 5 | int count = 0; 6 | 7 | printf("Write your paragraph : "); 8 | fgets(str, sizeof(str), stdin); 9 | 10 | printf("Press your desire letter to find its total number : "); 11 | scanf("%c",&ch); 12 | 13 | for (int i = 0; str[i] != '\0'; ++i) { 14 | if(ch ==str[i]) 15 | count++; 16 | } 17 | 18 | printf("The total number of %c is : %d",ch,count); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /binary_to_decimal/binary_to_decimal.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int to_decimal( int n) { 6 | int dec = 0, i = 0, rem; 7 | while (n!=0) { 8 | rem = n%10; 9 | n /= 10; 10 | dec += rem * pow(2,i); 11 | ++i; 12 | } 13 | return dec; 14 | } 15 | 16 | int main() { 17 | int n; 18 | printf("\n\tEnter a binary number "); 19 | scanf("%d", &n); 20 | printf("\n\tDecimal number of given %d is : %d\n ",n, to_decimal(n)); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /countingvowels/countingvowels.c: -------------------------------------------------------------------------------- 1 | include 2 | int main() { 3 | int i = 0, count = 0; 4 | char s[1000]; 5 | 6 | printf("Input a string\n"); 7 | scanf("%s",&s); 8 | 9 | while (s[i] != '\0') { 10 | if (s[i] == 'a' || s[i] == 'A' || s[i] == 'e' || s[i] == 'E' || s[i] == 'i' || s[i] == 'I' || s[i] =='o' || s[i]=='O' || s[i] == 'u' || s[i] == 'U') 11 | count++; 12 | i++; 13 | } 14 | 15 | printf("Number of vowels in the string: %d", count); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /star_triangle/star_triangle.c: -------------------------------------------------------------------------------- 1 | // C program to print full pyramid pattern using stars 2 | #include 3 | 4 | int main() { 5 | int i, j, n, k = 0; 6 | printf("Enter the length of triangle : "); 7 | scanf("%d",&n); 8 | 9 | for(i = 1; i <= n; ++i, k = 0) { 10 | for(j = 1; j <= n - i; ++j) { 11 | printf (" "); 12 | } 13 | 14 | while(k != 2 * i-1) { 15 | printf("*"); 16 | ++k; 17 | } 18 | 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /find_9/find_9.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | 5 | int find(int num, int digit) { 6 | int counter = 0; 7 | 8 | do { 9 | 10 | if (num % 10 == digit) 11 | counter++; 12 | 13 | num = num / 10; 14 | } while (num != 0); 15 | 16 | return counter; 17 | } 18 | 19 | int main(void){ 20 | int begin = 1; 21 | int end = 100; 22 | int i = 0; 23 | int sum = 0; 24 | 25 | 26 | for (i = begin; i <= end; i++) { 27 | sum += find(i, 9); 28 | } 29 | 30 | printf("sum = %d \n", sum); 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /frequency_of_letters/frequency_of_letters.c: -------------------------------------------------------------------------------- 1 | /* C Program to Find the Frequency of Characters in a String */ 2 | 3 | #include 4 | #include 5 | 6 | int main() { 7 | char str[100]; 8 | int i; 9 | int freq[256] = {0}; 10 | printf("\n\tEnter the string : "); 11 | scanf("%s",&str); 12 | 13 | for(i = 0; str[i] != '\0'; i++) { 14 | freq[str[i]]++; 15 | } 16 | 17 | for(i = 0; i < 256; i++) { 18 | if(freq[i] != 0) { 19 | printf("\n\t%c = %d\n", i, freq[i]); 20 | } 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /without_sign_multiple/without_sign_multiple.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float multiply(float x, float y); 4 | 5 | int main() { 6 | 7 | float a, b; 8 | printf("Enter two number: "); 9 | scanf("%f %f",&a, &b); 10 | 11 | float result = multiply(a,b); 12 | printf("Result = %.2f",result); 13 | 14 | return 0; 15 | } 16 | 17 | 18 | float multiply(float x, float y) { 19 | 20 | if(y==0) return 0; 21 | 22 | else if(y>0) return( x+ multiply(x,y-1) ); 23 | 24 | else return -multiply(x,-y); 25 | } -------------------------------------------------------------------------------- /decimal_to_octal/decimal_to_octal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int to_octal(int dec); 5 | 6 | int main() { 7 | 8 | int dec; 9 | 10 | printf("\n\tEnter a decimal number: "); 11 | scanf("%d", &dec); 12 | 13 | printf("\n\tOctal number of given decimal %d is : %d\n",dec, to_octal(dec)); 14 | 15 | return 0; 16 | } 17 | 18 | int to_octal(int dec) { 19 | int octal = 0, i = 1; 20 | 21 | while (dec != 0) { 22 | octal += (dec % 8) * i; 23 | 24 | dec /= 8; 25 | i *= 10; 26 | } 27 | 28 | return octal; 29 | } -------------------------------------------------------------------------------- /e_power/e_power.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | float Taylor_exponential(int n, float x) 5 | { 6 | float exp_sum = 1; 7 | for (int i = n - 1; i > 0; --i ) 8 | exp_sum = 1 + x * exp_sum / i; 9 | return exp_sum; 10 | } 11 | int main(void) 12 | { 13 | int n = 25; 14 | float x = 5.0; 15 | 16 | if (n>0 && x>0) 17 | { 18 | printf("value of n = %d and x = %d ", n, x ); 19 | printf("\ne^x = %f",Taylor_exponential(n,x)); 20 | } 21 | } -------------------------------------------------------------------------------- /palindrome/palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, originalN, reverseN = 0, remainder; 6 | 7 | printf("Let me know the integer that you want to check for palindrome number"); 8 | scanf("%d",&n); 9 | 10 | originalN = n; 11 | 12 | while(n! = 0) { 13 | remainder = n % 10; 14 | reverseN = reverseN * 10 + remainder; 15 | n /= 10; 16 | } 17 | 18 | if(originalN == reverseN) { 19 | printf("Your integer %d is a palindrome ", originalN); 20 | } 21 | else { 22 | printf("Your integer %d is a not palindrome", originalN); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /leap_year/leap_year.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int year; 5 | printf("Enter the year : \n "); 6 | scanf("%d",&year); 7 | 8 | if(year % 400 == 0) { 9 | printf("%d is a leap year ",year); 10 | } 11 | 12 | else if(year % 100 == 0) { 13 | printf("%d is not a leap year. ",year); 14 | } 15 | 16 | else if(year % 4 == 0) { 17 | printf("%d is a leap year.",year); 18 | } 19 | 20 | else { 21 | printf("%d is not a leap year",year); 22 | } 23 | 24 | return 0; 25 | 26 | } -------------------------------------------------------------------------------- /LCM/LCM.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int find_lcm(int, int); 4 | 5 | int main() { 6 | int a, b, lcm; 7 | printf("\n\n Enter 2 integers to find LCM of:\n"); 8 | scanf("%d%d", &a, &b); 9 | 10 | lcm = find_lcm(a,b); 11 | printf("\n\n LCM of %d and %d is: %d\n\n", a, b, lcm); 12 | return 0; 13 | } 14 | 15 | int find_lcm(int a, int b) { 16 | static int temp = 1; 17 | if(temp%a == 0 && temp%b == 0) { 18 | return temp; 19 | } 20 | else { 21 | temp++; 22 | find_lcm(a,b); 23 | return temp; 24 | } 25 | } -------------------------------------------------------------------------------- /octal_to_decimal/octal_to_decimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int octal_to_decimal(int oct) { 5 | int dec = 0, i = 0; 6 | 7 | while(oct != 0) { 8 | dec += (oct % 10) * pow(8,i); 9 | ++i; 10 | oct /= 10; 11 | } 12 | 13 | i = 1; 14 | 15 | return dec; 16 | } 17 | 18 | int main() { 19 | int oct; 20 | 21 | printf("\n\tEnter an octal number: "); 22 | scanf("%d", &oct); 23 | 24 | printf("\n\tDecimal Equivalent : %d\n",octal_to_decimal(oct)); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /search_array/search_array.c: -------------------------------------------------------------------------------- 1 | // C program to search an element in an array 2 | 3 | #include 4 | 5 | int main () { 6 | 7 | int array[100], ele, c, n; 8 | 9 | printf ("\n\tEnter the number of elements of the array : "); 10 | scanf ("%d", &n); 11 | 12 | printf ("\n\tInput the array elements : "); 13 | for (c = 0; c < n; c++) 14 | scanf ("%d", &array[c]); 15 | 16 | printf ("\n\tEnter element : "); 17 | scanf ("%d", &ele); 18 | for (c = 0; c < n; c++) { 19 | if (array[c] == ele) { 20 | printf ("\n\tElement found\n"); 21 | } 22 | 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /read_words/read_words.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define str_size 100 6 | 7 | void main() { 8 | 9 | char str[str_size]; 10 | int i, wrd; 11 | 12 | printf("Input the string : "); 13 | fgets(str, sizeof str, stdin); 14 | 15 | i = 0; 16 | wrd = 1; 17 | 18 | 19 | while(str[i]!='\0') { 20 | 21 | if(str[i]==' ' || str[i]=='\n' || str[i]=='\t') { 22 | wrd++; 23 | } 24 | 25 | i++; 26 | } 27 | 28 | printf("Total number of words in the string is : %d\n", wrd-1); 29 | } -------------------------------------------------------------------------------- /integertype/inetegertype.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i; 5 | printf("Enter any integer\n : "); 6 | scanf("%d",&i); 7 | 8 | if( i > 0) { 9 | printf("Given integer %d is positive\n",i); 10 | } 11 | else if( i < 0) { 12 | printf("Given interger %d is negetive\n",i); 13 | } 14 | else if( i == 0) { 15 | printf("0 is non positive and non negative integer\n); 16 | } 17 | else { 18 | printf("Invalid input \n Please press an integer\n); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /armstrong/armstrong.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (){ 4 | int n,originalN, remainder, result= 0; 5 | printf("Let me know your desire integer to check armstrong number"); 6 | scanf("%d",&n); 7 | originalN= n; 8 | while(originalN != 0) { 9 | remainder = originalN % 10; 10 | result = result +(remainder * remainder * remainder); 11 | originalN /= 10; 12 | } 13 | if(result == n) { 14 | printf("Your integer is an armstrong\n"); 15 | } 16 | else { 17 | printf("Your given integer is not n armstrong\n"); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /cube_or_not/cube_or_not.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static bool is_PowerOf_Three(int n) { 5 | #if 0 6 | if (n == 1) return true; 7 | if (n == 0 || n % 3) return false; 8 | return is_PowerOf_Three(n / 3); 9 | #else 10 | return (n > 0 && (1162261467 % n) == 0); 11 | #endif 12 | } 13 | int main(void) 14 | { 15 | int n = 9; 16 | printf("\nIf %d is power of three? %d", n, is_PowerOf_Three(n)); 17 | n = 81; 18 | printf("\n\nIf %d is power of three? %d", n, is_PowerOf_Three(n)); 19 | n = 45; 20 | printf("\n\nIf %d is power of three? %d", n, is_PowerOf_Three(n)); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /occurence/occurence.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int occurrence(int num,int d) { 4 | int rem, count; 5 | count = 0; 6 | while(num > 0) { 7 | rem = num % 10; 8 | if(rem == d) 9 | count++; 10 | num /= 10; 11 | } 12 | return count; 13 | } 14 | 15 | int main() { 16 | int num, d, count; 17 | 18 | printf("\n\tEnter a number: "); 19 | scanf("%d",&num); 20 | printf("\n\tEnter digit to search: "); 21 | scanf("%d",&d); 22 | 23 | count = occurrence(num,d); 24 | 25 | printf("\n\tTotal occurrence of digit is: \n\t%d in number:\n\t %d.",count,num); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /roots_qe/roots_qe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int a, b, c, d; 6 | double root1, root2; 7 | 8 | printf(" Enter a, b and c : \n"); 9 | scanf("%d%d%d", &a, &b, &c); 10 | 11 | d = b*b - 4*a*c; 12 | 13 | if (d < 0) { 14 | printf(" First root = %.2lf + i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a)); 15 | printf(" Second root = %.2lf - i%.2lf\n", -b/(double)(2*a), sqrt(-d)/(2*a)); 16 | } 17 | else { 18 | root1 = (-b + sqrt(d))/(2*a); 19 | root2 = (-b - sqrt(d))/(2*a); 20 | 21 | printf(" First root = %.2lf\n", root1); 22 | printf(" Second root = %.2lf\n", root2); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /largest_and_smallest_number/largest_and_smallest_number.c: -------------------------------------------------------------------------------- 1 | // C program to find the smallest and largest element in an array 2 | 3 | #include 4 | 5 | int main(){ 6 | int a[50],i,n,large,small; 7 | printf("\n\tEnter the number of elements : "); 8 | scanf("%d",&n); 9 | printf("\n\tInput the array elements : "); 10 | for(i=0;ilarge) 18 | large=a[i]; 19 | 20 | if(a[i] 2 | #include 3 | 4 | long long oct_to_bin(int oct) { 5 | int dec = 0, i = 0; 6 | long long bin = 0; 7 | 8 | while(oct != 0) { 9 | dec += (oct % 10) * pow(8,i); 10 | ++i; 11 | oct /= 10; 12 | } 13 | 14 | i = 1; 15 | 16 | while (dec != 0) { 17 | bin += (dec % 2) * i; 18 | dec /= 2; 19 | i *= 10; 20 | } 21 | 22 | return bin; 23 | } 24 | 25 | 26 | int main() { 27 | int oct; 28 | 29 | printf("\n\tEnter an octal number: "); 30 | scanf("%d", &oct); 31 | 32 | printf("\n\tBinary number of octal (%d) is : %lld\n",oct, oct_to_bin(oct)); 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /determinant_matrix/determinant_matrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int a[2][2], i, j; 6 | long determinant; 7 | 8 | printf("\n\nEnter the 4 elements of the array: "); 9 | for(i = 0; i < 2; i++) 10 | for(j = 0; j < 2; j++) 11 | scanf("%d", &a[i][j]); 12 | 13 | printf("\n\nThe entered matrix is: \n\n"); 14 | for(i = 0; i < 2; i++) { 15 | for(j = 0; j < 2; j++) { 16 | printf("%d\t", a[i][j]); 17 | } 18 | printf("\n"); 19 | } 20 | 21 | determinant = a[0][0]*a[1][1] - a[1][0]*a[0][1]; 22 | printf("\n\nDterminant of 2x2 matrix is : %d - %d = %d", a[0][0]*a[1][1], a[1][0]*a[0][1], determinant); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /converting_time/converting_time.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int inputSecond; 6 | 7 | 8 | int hours,minutes,seconds; 9 | int remainingSeconds; 10 | 11 | 12 | int secondsInHour = 60 * 60; 13 | int secondsInMinute = 60; 14 | 15 | //4 16 | printf("Enter seconds : "); 17 | scanf("%d",&inputSecond); 18 | 19 | //5 20 | hours = (inputSecond/secondsInHour); 21 | 22 | //6 23 | remainingSeconds = inputSecond - (hours * secondsInHour); 24 | minutes = remainingSeconds/secondsInMinute; 25 | 26 | 27 | remainingSeconds = remainingSeconds - (minutes*secondsInMinute); 28 | seconds = remainingSeconds; 29 | 30 | 31 | printf("%d hour, %d minutes and %d seconds",hours,minutes,seconds); 32 | } -------------------------------------------------------------------------------- /fibrico_series/fibrico_series.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Fibo(int ); 4 | 5 | int main() { 6 | int k, n; 7 | long int i = 0, j = 1; 8 | printf("\n Enter the length of the Fibonacci series: "); 9 | scanf("%d", &n); 10 | 11 | printf("\n\n first %d terms of Fibonacci series are:\n\n\n",n); 12 | Fibo(n); 13 | return 0; 14 | } 15 | 16 | void Fibo(int aj) { 17 | static long int first = 0, second = 1, sum; 18 | if(aj > 1) { 19 | sum = first + second; 20 | first = second; 21 | second = sum; 22 | printf("%ld ", sum); 23 | Fibo(aj-1); // recursive call 24 | } 25 | else { 26 | 27 | printf("\n\n\n"); 28 | } 29 | } -------------------------------------------------------------------------------- /volume_circle/volume_circle.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | float myradius; /* radius of the sphere */ 4 | float myvolume; /* volume of the sphere (to be computed) */ 5 | char line_text[50]; /* a line from the keyboard */ 6 | 7 | /* the value of pi to 50 places, from wikipedia */ 8 | const float PI = 3.14159265358979323846264338327950288419716939937510; 9 | 10 | int main() { 11 | printf("Input the radius of the sphere : "); 12 | fgets(line_text, sizeof(line_text), stdin); 13 | sscanf(line_text, "%f", &myradius); 14 | 15 | myvolume = (4.0 / 3.0) * PI * (myradius * myradius * myradius); /* volumn=(4/3) * pi * r^3*/ 16 | printf("The volume of sphere is %f.\n", myvolume); 17 | 18 | return(0); 19 | } -------------------------------------------------------------------------------- /dynamic_memory/dynamic_memory.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, i, *ptr, sum = 0; 6 | 7 | printf("\n\nEnter number of elements: "); 8 | scanf("%d", &n); 9 | 10 | ptr = (int *) malloc(n*sizeof(int)); 11 | 12 | if(ptr == NULL) { 13 | printf("\n\nError! Memory not allocated\n"); 14 | return 0; 15 | } 16 | 17 | printf("\n\nEnter elements of array: \n\n"); 18 | for(i = 0; i < n; i++) { 19 | scanf("%d", ptr+i); 20 | sum = sum + *(ptr + i); 21 | } 22 | 23 | printf("\n\nThe elements of the array are: "); 24 | for(i = 0; i < n; i++) { 25 | printf("%d ",ptr[i]); 26 | } 27 | 28 | free(ptr); 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /temperature/temperature.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char ch; 5 | float celsius, fahrenheit; 6 | 7 | printf("\n\tHello dear users!\n\t Would you want to continue the program?(y/n) "); 8 | scanf("%c",&ch); 9 | 10 | if(ch == 'N' || ch == 'n'){ 11 | printf("\t**************Thankyou!!!!**************"); 12 | } 13 | 14 | else if(ch == 'y' || ch == 'Y') { 15 | 16 | printf("\n\tEnter temperature in Celsius: "); 17 | scanf("%f", &celsius); 18 | 19 | fahrenheit = (celsius * 9 / 5) + 32; 20 | 21 | printf("\n\t%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit); 22 | } 23 | else { 24 | printf("\n\tInvalid option."); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Sum_A.P/Sum_A.P.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int a, n, d, tn, i; 6 | int sum = 0; 7 | 8 | printf(" \n\t Enter the First Number of an A.P Series: "); 9 | scanf("%d", &a); 10 | 11 | printf("\n\t Enter the Total Numbers in this A.P Series: "); 12 | scanf("%d", &n); 13 | 14 | printf("\n\t Enter the Common Difference: "); 15 | scanf("%d", &d); 16 | 17 | sum = (n * (2 * a + (n - 1) * d)) / 2; 18 | 19 | tn = a + (n - 1) * d; 20 | 21 | printf("\n The Sum of Series A.P. : "); 22 | 23 | for(i = a; i <= tn; i = i + d) { 24 | if(i != tn) { 25 | printf("%d + ", i); 26 | } 27 | else { 28 | printf("%d = %d", i, sum); 29 | } 30 | } 31 | printf("\n"); 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /quadrant/quadrant.c: -------------------------------------------------------------------------------- 1 | // C program to find the quadrant in which the given coordinates lie 2 | 3 | #include 4 | int main() { 5 | int a,b; 6 | printf("\n\tEnter the components of coordinates( x) : "); 7 | scanf("%d",&a); 8 | printf("\n\tEnter the components of coordinates( y) : "); 9 | scanf("%d",&b); 10 | if(a > 0 && b > 0) 11 | printf("\n\tIst Quadrant"); 12 | 13 | else if(a < 0 && b > 0) { 14 | printf("\n\tIInd Quadrant"); 15 | } 16 | 17 | else if(a < 0 && b < 0) { 18 | printf("\n\tIIIrd Quadrant"); 19 | } 20 | 21 | else if(a > 0 && b < 0) { 22 | printf("\n\tIVth Quadrant"); 23 | } 24 | 25 | else if(a == 0 && b == 0) { 26 | printf("\n\tOrigin"); 27 | } 28 | else { 29 | printf("\n\tInvalid input"); 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /daysofmonth/daysofmonth.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | int main() { 5 | 6 | int year, month; 7 | printf("\n\tEnter the year : "); 8 | scanf("%d",&year); 9 | printf("\n\tEnter the month of %d year in digit : ",year); 10 | scanf("%d",&month); 11 | 12 | if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { 13 | printf("\n\tNumber of days is 31"); 14 | } 15 | else if((month == 2) && ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))) { 16 | printf("\n\tNumber of days is 29"); 17 | } 18 | else if(month == 2) { 19 | printf("\n\tNumber of days is 28"); 20 | } 21 | else { 22 | printf("\n\tNumber of days is 30"); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /structure_records/structure_records.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct records { 5 | int marks; 6 | char sub[30]; 7 | }; 8 | 9 | int main() { 10 | struct records *ptr; 11 | int i, numrecords; 12 | printf("\nEnter the number of records: "); 13 | scanf("%d", &numrecords); 14 | 15 | printf("\nEnter the name of the subject and marks respectively:\n "); 16 | ptr = (struct records *)malloc(numrecords * sizeof(struct records)); 17 | for (i = 0; i < numrecords; ++i) { 18 | scanf("%s %d", (ptr + i)->sub, &(ptr + i)->marks); 19 | } 20 | 21 | printf("\n\tDisplaying Information:\n"); 22 | for (i = 0; i < numrecords; ++i) 23 | printf("\t%s\t : \t%d\n", (ptr + i)->sub, (ptr + i)->marks); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /max_product/max_product.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int integer_break(int n) { 6 | if (n == 2) { 7 | return 1; 8 | } 9 | 10 | else if (n == 3) { 11 | return 2; 12 | } 13 | 14 | else if (n % 3 == 0) { 15 | return (int) pow(3, n / 3); 16 | } 17 | 18 | else if (n % 3 == 1) { 19 | return 2 * 2 * (int) pow(3, (n - 4) / 3); 20 | } 21 | 22 | else { 23 | return 2 * (int) pow(3, n / 3); 24 | } 25 | 26 | } 27 | 28 | 29 | int main() { 30 | 31 | int n; 32 | printf("Enter the value : "); 33 | scanf("%d",&n); 34 | 35 | printf("\n Maximum product of %d after breaking the integer %d ", n, integer_break(n)); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /counting_string/counting_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int get_input_type(char c) { 4 | if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') 5 | return 1; 6 | 7 | return 0; 8 | } 9 | 10 | int main() { 11 | char * str = "Don't ask what your country can do for you, but ask what you can do for your country."; 12 | char c; 13 | 14 | int state = 0; 15 | int input = 0; 16 | int counter = 0; 17 | 18 | printf("Lets, count how many words in string:\n"); 19 | printf("<%s>\n", str); 20 | 21 | while ((c = *str++) != '\0') { 22 | input = get_input_type(c); 23 | 24 | if (state == 0 && input == 1) { 25 | state = 1; 26 | } 27 | else if (state == 1 && input == 0) { 28 | counter++; 29 | state = 0; 30 | } 31 | } 32 | 33 | printf("find %d words.\n", counter); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /currency_convert/currency_convert.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | float r, d, t, code; 6 | 7 | printf("Enter your code\n 1: for rupees to dollar\n 2: For dollar to rupee "); 8 | scanf("%f",&code); 9 | 10 | if(code == 1) { 11 | 12 | printf("Enter your Nepali amount : "); 13 | scanf("%f",&r); 14 | 15 | d = r / (117.25); 16 | printf("You have dollar %0.2f ",d); 17 | 18 | } 19 | 20 | else if (code == 2) { 21 | printf("Enter your dollar amount : "); 22 | scanf("%f",&d); 23 | 24 | r = d * (117.25); 25 | printf("You have rupees %0.2f",r); 26 | 27 | } 28 | 29 | else { 30 | printf("Invalid code"); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /max_column_value/max_column_value.c: -------------------------------------------------------------------------------- 1 | /* C Program to find the maximum element in each column of a matrix */ 2 | #include 3 | 4 | void maxi_col(int mat[][3], int m, int n) { 5 | int i,j; 6 | printf(" Column having maximum value :\n" ); 7 | for(i = 0; i < n; i++) { 8 | int max = mat[0][i]; 9 | for(j = 1; j < m; j++) { 10 | if(mat[j][i] > max) { 11 | max = mat[j][i]; 12 | } 13 | } 14 | printf("%d\n",max); 15 | } 16 | } 17 | 18 | int main() { 19 | int m, n; 20 | printf(" Enter the type of matrix :\n"); 21 | scanf("%d %d",&m,&n); 22 | 23 | int i, j; 24 | int mat1[m][n]; 25 | printf(" Enter the elements of matrix :\n"); 26 | for(i = 0; i < m; i++) { 27 | for(j = 0; j < n; j++) { 28 | scanf("%d",&mat1[i][j]); 29 | } 30 | } 31 | maxi_col(mat1,m,n); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /guess_number/guess_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int i,num=51,flag=1,guess,count=0; 6 | printf("Guess the number\n"); 7 | scanf("%d",&guess); 8 | do { 9 | if(num==guess) { 10 | flag=0; 11 | } 12 | 13 | else if(guess 2 | 3 | int main() { 4 | int m, n, c, d, matrix[10][10], transpose[10][10]; 5 | printf("\nEnter the type og matrix: "); 6 | scanf("%d %d", &m, &n); 7 | 8 | printf("\nEnter the components of matrix 1 and matrix 2 :\n"); 9 | for (c = 0; c < m; c++) { 10 | for(d = 0; d < n; d++) { 11 | scanf("%d", &matrix[c][d]); 12 | } 13 | } 14 | 15 | for (c = 0; c < m; c++) { 16 | for( d = 0 ; d < n ; d++ ) { 17 | transpose[d][c] = matrix[c][d]; 18 | } 19 | } 20 | 21 | printf("Transpose of matrix :\n " ); 22 | for (c = 0; c < n; c++) { 23 | for (d = 0; d < m; d++) 24 | printf("%d\t", transpose[c][d]); 25 | printf("\n"); 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /upper_triangle/upper_triangle.c: -------------------------------------------------------------------------------- 1 | /* C program to check if the given matrix is upper triangular or not */ 2 | 3 | #include 4 | 5 | int main() { 6 | int n; 7 | printf("\nEnter the matrix elements :\n"); 8 | scanf("%d",&n); 9 | 10 | int flag = 0; 11 | int mat[n][n]; 12 | int i, j; 13 | 14 | printf("\nEnter the elements of matrix:\n"); 15 | 16 | for(i = 0; i < n; i++) { 17 | for(j = 0; j < n; j++) { 18 | scanf("%d",&mat[i][j]); 19 | } 20 | } 21 | 22 | for (i = 1; i < n; i++) { 23 | for (j = 0; j < i; j++) { 24 | if (mat[i][j] != 0) { 25 | flag = 0; 26 | } 27 | else { 28 | flag = 1; 29 | } 30 | } 31 | } 32 | 33 | if (flag == 1) { 34 | printf("Upper Triangular Matrix"); 35 | } 36 | else { 37 | printf("Not an Upper Triangular Matrix"); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /anagram/anagram.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int check_anagram(char [], char []); 4 | 5 | int main() { 6 | char a[100], b[100]; 7 | 8 | printf("\nEnter two strings : \n"); 9 | scanf("%s %s",&a,&b); 10 | 11 | if (check_anagram(a, b) == 1) { 12 | printf("The strings %s and %s are anagrams\n",a,b); 13 | } 14 | else { 15 | printf("The strings %s and %s are not anagrams\n",a,b); 16 | } 17 | 18 | return 0; 19 | } 20 | 21 | int check_anagram(char a[], char b[]) { 22 | 23 | int first[26] = {0}, second[26] = {0}, c = 0; 24 | 25 | 26 | while (a[c] != '\0') { 27 | first[a[c]-'a']++; 28 | c++; 29 | } 30 | 31 | c = 0; 32 | 33 | while (b[c] != '\0') { 34 | second[b[c]-'a']++; 35 | c++; 36 | } 37 | 38 | for (c = 0; c < 26; c++) { 39 | if (first[c] != second[c]) 40 | return 0; 41 | } 42 | 43 | return 1; 44 | } -------------------------------------------------------------------------------- /divisors_9/divisors_9.c: -------------------------------------------------------------------------------- 1 | // C program to find number of integers with exactly 9 divisors 2 | 3 | #include 4 | 5 | int count_no_of_divisors(int num) { 6 | int count = 0; 7 | for (int i = 1; i <= num; i++) { 8 | if (num % i == 0) 9 | count = count + 1; 10 | } 11 | return count; 12 | } 13 | 14 | void check_9_factors(int n) { 15 | int c = 0; 16 | for (int i = 1; i <= n; i++) { 17 | if (count_no_of_divisors(i) == 9) { 18 | printf("%d ", i); 19 | c = c + 1; 20 | } 21 | } 22 | printf("\n\n\tTotal = %d\n", c); 23 | } 24 | 25 | int main() { 26 | int n; 27 | printf("\n\tEnter the number : "); 28 | scanf("%d", &n); 29 | printf("\n\tThe number which has exactly 9 divisors : "); 30 | check_9_factors(n); 31 | return 0; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /delete_array/delete_array.c: -------------------------------------------------------------------------------- 1 | /* C program to delete an element in an array */ 2 | 3 | #include 4 | 5 | int main(){ 6 | int array[100], position, c, n; 7 | 8 | printf("\n\tEnter the number of elements of the array : "); 9 | scanf("%d", &n); 10 | 11 | printf("\n\tInput the array elements : "); 12 | 13 | for (c = 0; c < n; c++) { 14 | scanf("%d", &array[c]); 15 | } 16 | 17 | printf("\n\tEnter the position : "); 18 | scanf("%d", &position); 19 | 20 | if (position >= n + 1) { 21 | printf("\n\tDeletion not possible.\n"); 22 | } 23 | else { 24 | for (c = position - 1; c < n - 1; c++) 25 | array[c] = array[c + 1]; 26 | 27 | printf("\n\tArray after deletion : "); 28 | 29 | for (c = 0; c < n - 1; c++) 30 | printf("\n\t%d", array[c]); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /diamond_pattern/diamond_pattern.c: -------------------------------------------------------------------------------- 1 | /* C program – hollow diamond pattern printing using stars */ 2 | 3 | #include 4 | 5 | int main() { 6 | int i, j, space, k = 0, n; 7 | printf("\n\tEnter the number of rows : "); 8 | scanf("%d",&n); 9 | for (i = 1; i <= n; i++) { 10 | for (j = 1; j <= n - i; j++) { 11 | printf(" "); 12 | } 13 | while (k != (2 * i - 1)) { 14 | if (k == 0 || k == 2 * i - 2) 15 | printf("*"); 16 | else 17 | printf(" "); 18 | k++; 19 | } 20 | k = 0; 21 | printf("\n"); 22 | } 23 | n--; 24 | for (i = n; i >= 1; i--) { 25 | for (j = 0; j <= n - i; j++) { 26 | printf(" "); 27 | } 28 | k = 0; 29 | while (k != (2 * i - 1)) { 30 | if (k == 0 || k == 2 * i - 2) 31 | printf("*"); 32 | else 33 | printf(" "); 34 | k++; 35 | } 36 | printf("\n"); 37 | } 38 | } -------------------------------------------------------------------------------- /aboudant_number/aboudant_number.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | int getSum(int n) { 6 | 7 | int sum = 0; 8 | for (int i = 1; i <= sqrt(n); i++) { 9 | if (n % i==0) { 10 | if (n / i == i){ 11 | sum = sum + i; 12 | } 13 | else { 14 | sum = sum + i; 15 | sum = sum + (n / i); 16 | } 17 | } 18 | } 19 | sum = sum - n; 20 | return sum; 21 | } 22 | 23 | bool checkAbundant(int n) { 24 | return getSum(n) > n; 25 | 26 | } 27 | 28 | int main() { 29 | 30 | int n; 31 | 32 | printf(" Input an integer number: "); 33 | scanf("%d",&n); 34 | 35 | checkAbundant(n)? printf(" The number is Abundant.\n") 36 | :printf(" The number is not Abundant.\n"); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /joshphine_ring/joshphine_ring.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define all_num 100 4 | #define count_num 3 5 | #define out_num 3 6 | 7 | 8 | int people[all_num]; 9 | 10 | int main() { 11 | int left, pos, step, i; 12 | 13 | int counter = 0; 14 | 15 | left = all_num; 16 | pos = 0; 17 | step = 0; 18 | 19 | 20 | for (i = 0; i < all_num; i++) 21 | people[i] = i + 1; 22 | 23 | 24 | while (left > 0) { 25 | 26 | if (people[pos] > 0) 27 | step++; 28 | 29 | if (step == out_num && people[pos] != 0) { 30 | printf("%d out \n", people[pos]); 31 | people[pos] = 0; 32 | left--; 33 | } 34 | 35 | #if 1 36 | pos = ++pos % all_num; 37 | step = step % count_num; 38 | #else 39 | pos++; 40 | if (pos == all_num) 41 | pos = 0; 42 | 43 | if (step == count_num) 44 | step = 0; 45 | #endif 46 | } 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /non_repeating_array/non_repeating_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int non_repeating_elements(int arr[], int n) { 5 | int i,j; 6 | int count = 1; 7 | for(i = 0; i < n; i++) { 8 | for(j = 0; j < n; j++) { 9 | if(arr[i] == arr[j] && i != j) 10 | break; 11 | } 12 | if(j == n ) { 13 | printf("\n\tNon-repeating element [%d] : %d \n",count,arr[i]); 14 | ++count; 15 | } 16 | } 17 | return -1; 18 | } 19 | 20 | int main() { 21 | int n,i; 22 | printf("\n\tEnter the number of elements : "); 23 | scanf("%d",&n); 24 | int arr[n]; 25 | printf("\n\tInput the array elements : "); 26 | for(i = 0; i < n; i++) { 27 | scanf("%d",&arr[i]); 28 | } 29 | non_repeating_elements(arr, n); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /identity_matrix/identity_matrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int i, j, rows, columns, a[10][10], Flag = 1; 6 | 7 | printf("\n Enter Number of rows and columns : "); 8 | scanf("%d %d", &i, &j); 9 | 10 | printf("\n Enter the Matrix Elements \n"); 11 | for(rows = 0; rows < i; rows++) { 12 | for(columns = 0; columns < j; columns++) { 13 | scanf("%d", &a[rows][columns]); 14 | } 15 | } 16 | 17 | for(rows = 0; rows < i; rows++) { 18 | for(columns = 0; columns < j; columns++) { 19 | if(a[rows][columns] != 1 && a[columns][rows] != 0) { 20 | Flag = 0; 21 | break; 22 | } 23 | } 24 | } 25 | if(Flag == 1) { 26 | printf("\n The Matrix that you entered is an Identity Matrix "); 27 | } 28 | else { 29 | printf("\n The Matrix that you entered is Not an Identity Matrix "); 30 | } 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /binomial_coefficient_table/binomial_cofficient_table.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX 10 4 | 5 | int main() { 6 | int n, a, bi_nom; 7 | printf("Mx "); 8 | for (n = 0; n <= 10; ++n) { 9 | printf("%d ", n); 10 | } 11 | printf("\n----------------------------------------------------------\n"); 12 | n=0; 13 | 14 | do { 15 | a = 0, bi_nom = 1; 16 | printf("%2d", n); 17 | while(a <= n) { 18 | if(n == 0 || a == 0){ 19 | printf("%4d", bi_nom); 20 | } 21 | else { 22 | bi_nom=bi_nom* (n - a + 1)/a; 23 | printf("%4d", bi_nom); 24 | } 25 | a=a + 1; 26 | } 27 | printf("\n"); 28 | n=n + 1; 29 | } 30 | while(n <= MAX); 31 | printf("----------------------------------------------------------"); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /automorphic_number/automorphic_number.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | bool chkAutomor(int num1) { 6 | 7 | int sqno = num1 * num1; 8 | 9 | while (num1 > 0) { 10 | if (num1 % 10 != sqno % 10) { 11 | return false; 12 | } 13 | num1 /= 10; 14 | sqno /= 10; 15 | } 16 | return true; 17 | } 18 | 19 | int main() { 20 | 21 | int num; 22 | printf("\n\n Check whether a number is an Authomorphic Number or not: \n"); 23 | printf(" ------------------------------------------------------------\n"); 24 | printf(" Input a number: "); 25 | scanf("%d",&num); 26 | 27 | if( chkAutomor(num)) { 28 | printf(" The given number is an Automorphic Number.\n"); 29 | } 30 | 31 | else { 32 | printf(" The given number is not an Authomorphic Number.\n"); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /add_inches/add_inches.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Distance { 4 | int feet; 5 | float inch; 6 | } d1, d2, result; 7 | 8 | int main() { 9 | // take first distance input 10 | printf("Enter 1st distance\n"); 11 | printf("Enter feet: "); 12 | scanf("%d", &d1.feet); 13 | printf("Enter inch: "); 14 | scanf("%f", &d1.inch); 15 | 16 | // take second distance input 17 | printf("\nEnter 2nd distance\n"); 18 | printf("Enter feet: "); 19 | scanf("%d", &d2.feet); 20 | printf("Enter inch: "); 21 | scanf("%f", &d2.inch); 22 | 23 | // adding distances 24 | result.feet = d1.feet + d2.feet; 25 | result.inch = d1.inch + d2.inch; 26 | 27 | // convert inches to feet if greater than 12 28 | while (result.inch >= 12.0) { 29 | result.inch = result.inch - 12.0; 30 | ++result.feet; 31 | } 32 | printf("\nSum of distances = %d\'-%.1f\"", result.feet, result.inch); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /calculating_emi/calculating_emi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | float calculate_emi(float principal, float rate, float time); 6 | 7 | int main() { 8 | 9 | float principal, rate, time, emi; 10 | 11 | printf("Enter the value of principal\n"); 12 | scanf("%f",&principal); 13 | 14 | printf("Enter the value of time\n"); 15 | scanf("%f",&time); 16 | 17 | printf("Enter the value of rate\n"); 18 | scanf("%f",&rate); 19 | 20 | emi = calculate_emi(principal, rate, time); 21 | printf("You have to pay %f Monthly EMI!!\n", emi); 22 | 23 | return 0; 24 | } 25 | 26 | float calculate_emi(float principal, float rate, float time) { 27 | 28 | float emi; 29 | 30 | rate = rate / (12 * 100); 31 | time = time * 12; 32 | emi = (principal * rate * pow(1 + rate, time)) / (pow(1 + rate, time) - 1); 33 | 34 | return emi; 35 | } -------------------------------------------------------------------------------- /decimal_to_hexadecimal/decimal_to_hexadecimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int number,count,i; 5 | char hex[32]; 6 | 7 | printf("\n\tEnter decimal number: "); 8 | scanf("%d",&number); 9 | count=0; 10 | while(number > 0) { 11 | 12 | switch(number%16) { 13 | case 10: 14 | hex[count]='A'; 15 | break; 16 | 17 | case 11: 18 | hex[count]='B'; 19 | break; 20 | 21 | case 12: 22 | hex[count]='C'; 23 | break; 24 | 25 | case 13: 26 | hex[count]='D'; 27 | break; 28 | 29 | case 14: 30 | hex[count]='E'; 31 | break; 32 | 33 | case 15: 34 | hex[count]='F'; 35 | break; 36 | 37 | default: 38 | hex[count]=(number % 16)+0x30; 39 | } 40 | number=number / 16; 41 | count++; 42 | } 43 | 44 | printf("\tHexadecimal value is: "); 45 | for(i=(count-1); i>=0;i--) 46 | printf("%c",hex[i]); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /numbersname/numbersname.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void pw(long,char[]); 4 | char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"}; 5 | char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"}; 6 | 7 | 8 | void main() { 9 | long n; 10 | printf("\n\tEnter the number : "); 11 | scanf("%ld",&n); 12 | if(n <= 0) 13 | printf("\n\tEnter numbers greater than 0"); 14 | else 15 | { 16 | pw( (n / 10000000),"crore"); 17 | pw(( (n / 100000) % 100),"lakh"); 18 | pw( ( (n / 1000) % 100),"thousand"); 19 | pw( ( (n / 100) % 10),"hundred"); 20 | pw( (n % 100)," "); 21 | } 22 | return ; 23 | } 24 | 25 | 26 | void pw(long n,char ch[]) { 27 | (n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]); 28 | if(n)printf("%s ",ch); 29 | } 30 | -------------------------------------------------------------------------------- /switchcase2/switchcase2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | char operator; 5 | int first, second; 6 | float result; 7 | 8 | printf("Let me know your operator( +, _, *, /, % )"); 9 | scanf("%c\n",&operator); 10 | 11 | printf("Enter your first integer : "); 12 | scanf(" %d",&first); 13 | 14 | printf("Enter your second integer :"); 15 | scanf("%d",&second); 16 | 17 | switch(operator) { 18 | case '+' : 19 | result = first + second; 20 | break; 21 | 22 | case '-': 23 | result = first - second; 24 | break; 25 | 26 | case '*': 27 | result = first * second; 28 | break; 29 | 30 | case '/' : 31 | result = (float)first / (float)second ; 32 | break; 33 | 34 | case '%' : 35 | result = first % second; 36 | break; 37 | 38 | default : 39 | printf("Invalid operator....."); 40 | break; 41 | 42 | } 43 | printf("The result of %d %c %d = %f\n", first, operator, second, result); 44 | 45 | return 0; 46 | } 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /notes/notes.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int amt, total; 4 | printf("Input the amount: "); 5 | scanf("%d",&amt); 6 | 7 | total = (int)amt/100; 8 | 9 | printf("There are: "); 10 | 11 | printf("\n%d Note(s) of 100.00\n", total); 12 | 13 | amt = amt-(total*100); 14 | 15 | total = (int)amt/50; 16 | 17 | printf("%d Note(s) of 50.00\n", total); 18 | 19 | amt = amt-(total*50); 20 | 21 | total = (int)amt/20; 22 | 23 | printf("%d Note(s) of 20.00\n", total); 24 | 25 | amt = amt-(total*20); 26 | 27 | total = (int)amt/10; 28 | 29 | printf("%d Note(s) of 10.00\n", total); 30 | 31 | amt = amt-(total*10); 32 | 33 | total = (int)amt/5; 34 | 35 | printf("%d Note(s) of 5.00\n", total); 36 | 37 | amt = amt-(total*5); 38 | 39 | total = (int)amt/2; 40 | 41 | printf("%d Note(s) of 2.00\n", total); 42 | 43 | amt = amt-(total*2); 44 | 45 | total = (int)amt/1; 46 | 47 | printf("%d Note(s) of 1.00\n", total); 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /convertor/convertor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | float cm, meter, km; 6 | int hour, min, sec; 7 | int choice; 8 | 9 | printf("Which unit you want to convert(length(1) / time(2) )? : "); 10 | scanf("%d",&choice); 11 | 12 | if(choice == 1){ 13 | 14 | printf("Enter length in centimeter: "); 15 | scanf("%f", &cm); 16 | 17 | meter = cm / 100.0; 18 | km = cm / 100000.0; 19 | 20 | printf("Length in Meter = %.2f m \n", meter); 21 | printf("Length in Kilometer = %.4f km", km); 22 | } 23 | 24 | else if(choice == 2){ 25 | printf("Enter hour : "); 26 | scanf("%d",&hour); 27 | 28 | min = hour * 60; 29 | sec = hour * 3600; 30 | 31 | printf(" %d Hour in minutes is : %d min\n", hour, min); 32 | printf(" %d Hour in sec : %d sec",hour, sec); 33 | 34 | } 35 | else { 36 | printf("Thankyou!!!"); 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /finding_angles_on_clock/finding_angles_on_clock.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int calcAngle(int hour, int min) { 5 | if (hour == 12){ 6 | hour = 0; 7 | } 8 | 9 | if (min == 60) { 10 | min = 0; 11 | } 12 | 13 | int hour_angle = (int)(0.5 * (hour * 60 + min)); 14 | int minute_angle = (int)(6 * min); 15 | 16 | int angle = abs(hour_angle - minute_angle); 17 | int ang = 360 - angle; 18 | return (ang > angle) ? angle : ang; 19 | } 20 | 21 | int main(void) { 22 | 23 | int hour; 24 | printf("Enter the hour : "); 25 | scanf("%d",&hour); 26 | 27 | int min; 28 | printf("\nEnter the minutes :\n "); 29 | scanf("%d",&min); 30 | 31 | if (hour <0 || min < 0 || hour > 12 || min > 60) { 32 | printf("\nWrong input..!"); 33 | } 34 | 35 | else { 36 | printf("\nAngle between hour and minute hands %d degree",calcAngle(hour, min)); 37 | } 38 | } -------------------------------------------------------------------------------- /percentage_divisor/percentage_divisor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int rl,phy,che,ca,total; 7 | float per; 8 | char nm[20],div[10]; 9 | printf("Input the Roll Number of the student :"); 10 | scanf("%d",&rl); 11 | printf("Input the Name of the Student :"); 12 | scanf("%s",nm); 13 | printf("Input the marks of Physics, Chemistry and Computer Application : "); 14 | scanf("%d%d%d",&phy,&che,&ca); 15 | total = phy+che+ca; 16 | per = total/3.0; 17 | if (per>=60) 18 | strcpy(div,"First"); 19 | else 20 | if (per<60&&per>=48) 21 | strcpy(div,"Second"); 22 | else 23 | if (per<48&&per>=36) 24 | strcpy(div,"Pass"); 25 | else 26 | strcpy(div,"Fail"); 27 | 28 | printf("\nRoll No : %d\nName of Student : %s\n",rl,nm); 29 | printf("Marks in Physics : %d\nMarks in Chemistry : %d\nMarks in Computer Application : %d\n",phy,che,ca); 30 | printf("Total Marks = %d\nPercentage = %5.2f\nDivision = %s\n",total,per,div); 31 | } -------------------------------------------------------------------------------- /standard_derivation/standard_derivation.c: -------------------------------------------------------------------------------- 1 | /* 2 | * C program to input real numbers and find the mean, variance 3 | * and standard deviation 4 | */ 5 | #include 6 | #include 7 | #define MAXSIZE 10 8 | 9 | void main() { 10 | float x[MAXSIZE]; 11 | int i, n; 12 | float average, variance, std_deviation, sum = 0, sum1 = 0; 13 | 14 | printf("\n\tEnter the value of N : "); 15 | scanf("%d", &n); 16 | printf("\n\tEnter %d real numbers : ", n); 17 | for (i = 0; i < n; i++){ 18 | scanf("%f", &x[i]); 19 | } 20 | for (i = 0; i < n; i++){ 21 | sum = sum + x[i]; 22 | } 23 | average = sum / (float)n; 24 | for (i = 0; i < n; i++){ 25 | sum1 = sum1 + pow((x[i] - average), 2); 26 | } 27 | variance = sum1 / (float)n; 28 | std_deviation = sqrt(variance); 29 | printf("\n\tAverage of all elements = %.2f\n", average); 30 | printf("\n\tvariance of all elements = %.2f\n", variance); 31 | printf("\n\tStandard deviation = %.2f\n", std_deviation); 32 | } -------------------------------------------------------------------------------- /rearranging_numbers/rearranging_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void rearrange_positions(int arr[], int n) { 5 | int i,j; 6 | j = 0; 7 | for(i = 0; i < n; i++) { 8 | if(arr[i] < 0) { 9 | if(i != j) { 10 | int temp = arr[i]; 11 | arr[i] = arr[j]; 12 | arr[j] = temp; 13 | } 14 | j++; 15 | } 16 | } 17 | } 18 | 19 | int main() { 20 | int n,i; 21 | printf("\n\tEnter the number of elements : "); 22 | scanf("%d",&n); 23 | int arr[n]; 24 | printf("\n\tInput the array elements : "); 25 | for(i = 0; i < n; i++) { 26 | scanf("%d",&arr[i]); 27 | } 28 | printf("\n\tOriginal array : "); 29 | for(i = 0; i < n; i++) { 30 | printf("%d ",arr[i]); 31 | } 32 | printf("\n"); 33 | rearrange_positions(arr, n); 34 | printf("\n\tRearranged array : "); 35 | for(i = 0; i < n; i++) { 36 | printf("%d ",arr[i]); 37 | } 38 | printf("\n"); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /matrix_addition/matrix_addition.c: -------------------------------------------------------------------------------- 1 | /* C Program to perform matrix operations ,matrix addition, matrix subtraction, matrix multiplication – addition */ 2 | #include 3 | 4 | int main() { 5 | int m , n; 6 | printf("\n\tEnter number of rows and columns of mat1 matrix: "); 7 | scanf("%d %d", &m, &n); 8 | printf("\n\tEnter the elements of matrix 1 : "); 9 | int i, j; 10 | int mat1[m][n], mat2[m][n], mat3[m][n]; 11 | for(i = 0; i < m; i++) { 12 | for(j = 0; j < n; j++) 13 | scanf("%d",&mat1[i][j]); 14 | } 15 | printf("\n\tEnter the elements of matrix 2 :"); 16 | for(i = 0; i < n; i++) { 17 | for(j = 0; j < n; j++) 18 | scanf("%d",&mat2[i][j]); 19 | } 20 | 21 | for(i = 0; i < m; i++) { 22 | for(j = 0; j < n; j++) { 23 | mat3[i][j] = mat1[i][j] + mat2[i][j]; 24 | } 25 | } 26 | 27 | for(i = 0; i < m; i++) { 28 | for(j = 0; j < n; j++) 29 | printf("\n\tResult : %d ", mat3[i][j]); 30 | printf("\t\n"); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /addition_of_matrix/addition_of_matrix.c: -------------------------------------------------------------------------------- 1 | /* C Program to perform matrix operations ,matrix addition, matrix subtraction, matrix multiplication – addition */ 2 | #include 3 | 4 | int main() { 5 | int m , n; 6 | printf("\n\tEnter number of rows and columns of mat1 matrix: "); 7 | scanf("%d %d", &m, &n); 8 | printf("\n\tEnter the elements of matrix 1 : "); 9 | int i, j; 10 | int mat1[m][n], mat2[m][n], mat3[m][n]; 11 | for(i = 0; i < m; i++) { 12 | for(j = 0; j < n; j++) 13 | scanf("%d",&mat1[i][j]); 14 | } 15 | printf("\n\tEnter the elements of matrix 2 :"); 16 | for(i = 0; i < n; i++) { 17 | for(j = 0; j < n; j++) 18 | scanf("%d",&mat2[i][j]); 19 | } 20 | 21 | for(i = 0; i < m; i++) { 22 | for(j = 0; j < n; j++) { 23 | mat3[i][j] = mat1[i][j] + mat2[i][j]; 24 | } 25 | } 26 | 27 | for(i = 0; i < m; i++) { 28 | for(j = 0; j < n; j++) 29 | printf("\n\tResult : %d ", mat3[i][j]); 30 | printf("\t\n"); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /subtraction_matrix/subtraction_matrix.c: -------------------------------------------------------------------------------- 1 | /* C Program to perform matrix operations ,matrix addition, matrix subtraction, matrix multiplication – subtraction */ 2 | #include 3 | 4 | int main() { 5 | int m, n; 6 | printf("\n\tEnter the number of rows and columns of mat1 matrix: "); 7 | scanf("%d %d",&m,&n); 8 | int i, j; 9 | printf("\n\tEnter the elements of matrix 1 : "); 10 | int mat1[m][n], mat2[m][n], mat3[m][n]; 11 | for(i = 0; i < m; i++) { 12 | for(j = 0; j < n; j++) 13 | scanf("%d",&mat1[i][j]); 14 | } 15 | printf("\n\tEnter the second matrix's elements : "); 16 | for(i = 0; i < n; i++) { 17 | for(j = 0; j < n; j++) 18 | scanf("%d",&mat2[i][j]); 19 | } 20 | 21 | for(i = 0; i < m; i++) { 22 | for(j = 0; j < n; j++) { 23 | mat3[i][j] = mat1[i][j] - mat2[i][j]; 24 | } 25 | } 26 | 27 | for(i = 0; i < m; i++) { 28 | for(j = 0; j < n; j++) 29 | printf("%d ", mat3[i][j]); 30 | printf("\n"); 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /ugly_number/ugly_number.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | int main() 4 | { 5 | int n,x=0; 6 | printf("\n\n Check whether a given number is an ugly number:\n"); 7 | printf("----------------------------------------------------\n"); 8 | printf("Input an integer number: "); 9 | scanf("%d",&n); 10 | 11 | if (n <= 0) { 12 | printf("Input a correct number."); 13 | } 14 | while (n != 1) 15 | { 16 | if (n % 5 == 0) 17 | { 18 | n /= 5; 19 | } 20 | else if (n % 3 == 0) 21 | { 22 | n /= 3; 23 | } 24 | else if (n % 2 == 0) 25 | { 26 | n /= 2; 27 | } 28 | else 29 | { 30 | printf("It is not an ugly number.\n"); 31 | x = 1; 32 | break; 33 | } 34 | } 35 | if (x==0) 36 | { 37 | printf("It is an ugly number.\n"); 38 | } 39 | } -------------------------------------------------------------------------------- /hollow_diamond_pattern/hollow_diamond_pattern.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int i, j, n; 5 | printf("\n\tEnter the number of rows : "); 6 | scanf("%d", &n); 7 | 8 | for(i = 0; i < n; i++) { 9 | for(j = 0; j < (2 * n); j++) { 10 | if(i + j <= n - 1) { 11 | printf("*"); 12 | } 13 | else{ 14 | printf(" "); 15 | } 16 | if((i + n) <= j) { 17 | printf("*"); 18 | } 19 | else{ 20 | printf(" "); 21 | } 22 | } 23 | printf("\n"); 24 | } 25 | 26 | for(i = 0; i < n; i++) { 27 | for(j = 0; j < (2 * n); j++) { 28 | if(i >= j) { 29 | printf("*"); 30 | } 31 | else{ 32 | printf(" "); 33 | } 34 | if(i >= (2 * n - 1) - j) { 35 | printf("*"); 36 | } 37 | else{ 38 | printf(" "); 39 | } 40 | } 41 | printf("\n"); 42 | } 43 | return 0; 44 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gita Khanal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Disarium_Number/Disarium_Number.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | # include 5 | 6 | 7 | int DigiCount(int n) { 8 | 9 | int ctr_digi = 0; 10 | int tmpx = n; 11 | while(tmpx) { 12 | tmpx = tmpx / 10; 13 | ctr_digi++; 14 | } 15 | return ctr_digi; 16 | } 17 | 18 | bool chkDisarum(int n) { 19 | 20 | int ctr_digi = DigiCount(n); 21 | int s = 0; 22 | int x = n; 23 | int pr; 24 | while (x) { 25 | pr = x % 10; 26 | s = s + pow(pr, ctr_digi--); 27 | x = x / 10; 28 | } 29 | return (s == n); 30 | } 31 | 32 | int main() { 33 | 34 | int dino; 35 | 36 | printf("\n\n Check whether a number is Disarium Number or not: \n"); 37 | printf(" ------------------------------------------------------\n"); 38 | printf(" Input a number: "); 39 | scanf("%d",&dino); 40 | 41 | if( chkDisarum(dino)) { 42 | printf(" The given number is a Disarium Number.\n"); 43 | } 44 | 45 | else { 46 | printf(" The given number is not a Disarium Number.\n"); 47 | } 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Kapersker_number/Kapresker_number.c: -------------------------------------------------------------------------------- 1 | # include 2 | # include 3 | # include 4 | 5 | bool chkkaprekar(int n) 6 | { 7 | if (n == 1) 8 | return true; 9 | int sqr_n = n * n; 10 | int ctr_digits = 0; 11 | while (sqr_n) 12 | { 13 | ctr_digits++; 14 | sqr_n /= 10; 15 | } 16 | sqr_n = n*n; 17 | for (int r_digits=1; r_digits 3 | 4 | void display(int result[], int n) { 5 | int i; 6 | printf("\nThe maximum value having element on each rows are : "); 7 | for(i = 0; i < n; i++) { 8 | printf("%d ", result[i]); 9 | } 10 | } 11 | 12 | void maxi_row(int mat[][3], int m, int n) { 13 | int i = 0, j; 14 | int max = 0; 15 | int result[m]; 16 | while (i < m) { 17 | for ( j = 0; j < n; j++) { 18 | if (mat[i][j] > max) { 19 | max = mat[i][j]; 20 | } 21 | } 22 | result[i] = max; 23 | max = 0; 24 | i++; 25 | } 26 | display(result, m); 27 | } 28 | 29 | 30 | int main() { 31 | int m, n; 32 | printf("\nEnter the type of matrix : "); 33 | scanf("%d %d",&m,&n); 34 | int i, j; 35 | int mat1[m][n]; 36 | printf("\nEnter the components of matrix :\n "); 37 | for(i = 0; i < m; i++) { 38 | for(j = 0; j < n; j++) { 39 | scanf("%d",&mat1[i][j]); 40 | } 41 | } 42 | 43 | maxi_row(mat1,m,n); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /checking_subset/checking_subset.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int SubsetArray(int *arr1 , int arr1_size, int *arr2, int arr2_size) { 4 | 5 | int i, j; 6 | for (i = 0; i < arr2_size; i++) { 7 | for (j = 0; j < arr1_size; j++) { 8 | if(arr2[i] == arr1[j]){ 9 | break; 10 | } 11 | } 12 | if(j == arr1_size) { 13 | return 0; 14 | } 15 | } 16 | return 1; 17 | } 18 | 19 | int main() { 20 | int arr1[] = {4, 8, 7, 11, 6, 9, 5, 0, 2}; 21 | int arr2[] = {5, 4, 2, 0, 6}; 22 | 23 | int n1 = sizeof(arr1)/sizeof(arr1[0]); 24 | int i; 25 | int n2 = sizeof(arr2)/sizeof(arr2[0]); 26 | 27 | printf("The given first array is : "); 28 | for(i = 0; i < n1; i++) { 29 | printf("%d ", arr1[i]); 30 | } 31 | printf("\n"); 32 | 33 | printf("The given second array is : "); 34 | for(i = 0; i < n2; i++) { 35 | printf("%d ", arr2[i]); 36 | } 37 | printf("\n"); 38 | 39 | if(SubsetArray(arr1, 9, arr2, 4)) 40 | printf("The second array is the subset of first array."); 41 | else 42 | printf("The second array is not a subset of first array"); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /switchcase/switchcase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int day; 5 | printf("Enter the number of the day : "); 6 | scanf("%d",&day); 7 | switch(day) { 8 | case 1: 9 | printf("It's a Monday\n Open : 10am \n Close : 6pm\n"); 10 | break ; 11 | 12 | case 2: 13 | printf("It's a Tuesday\n Open : 10am\n Close : 6pm\n Meeting : 2pm to 3pm\n"); 14 | break; 15 | 16 | case 3: 17 | printf("It's a Wednesday\n Open : 10am \n Close : 4pm\n "); 18 | break; 19 | 20 | case 4: 21 | printf("It's a Thursday\n Open : 10am \n Close : 5pm \n Meeting : 12pm to 2pm\n"); 22 | break; 23 | 24 | case 5: 25 | printf("It's a Friday\n Open : 10am \n Close: 3pm\n"); 26 | break; 27 | 28 | case 6: 29 | printf("It's a Saturday\n Holiday!!!!!!"); 30 | break; 31 | 32 | case 7: 33 | printf("It's a Sunday\n Holiday !!!!!!"); 34 | break; 35 | 36 | default : 37 | printf("Sorry!!! \n Please enter the number 1 to 7\n"); 38 | 39 | 40 | } 41 | return 0; 42 | } -------------------------------------------------------------------------------- /counting_alpha_number/counting_alpha_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | #define str_size 100 //Declare the maximum size of the string 7 | 8 | void main() 9 | { 10 | char str[str_size]; 11 | int alp, digit, splch, i; 12 | alp = digit = splch = i = 0; 13 | 14 | 15 | printf("\n\nCount total number of alphabets, digits and special characters :\n"); 16 | printf("--------------------------------------------------------------------\n"); 17 | printf("Input the string : "); 18 | fgets(str, sizeof str, stdin); 19 | 20 | /* Checks each character of string*/ 21 | 22 | while(str[i]!='\0') 23 | { 24 | if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')) 25 | { 26 | alp++; 27 | } 28 | else if(str[i]>='0' && str[i]<='9') 29 | { 30 | digit++; 31 | } 32 | else 33 | { 34 | splch++; 35 | } 36 | 37 | i++; 38 | } 39 | 40 | printf("Number of Alphabets in the string is : %d\n", alp); 41 | printf("Number of Digits in the string is : %d\n", digit); 42 | printf("Number of Special characters in the string is : %d\n\n", splch); 43 | } -------------------------------------------------------------------------------- /electricity_bill/electricity_bill.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() { 5 | 6 | int id, unit; 7 | float chg, surchg=0, gramt,netamt; 8 | char name[25]; 9 | 10 | printf("Input Customer ID :"); 11 | scanf("%d",&id); 12 | 13 | printf("Input the name of the customer :"); 14 | scanf("%s",name); 15 | 16 | printf("Input the unit consumed by the customer : "); 17 | scanf("%d",&unit); 18 | 19 | if (unit <200 ) { 20 | chg = 1.20; 21 | } 22 | else if (unit>=200 && unit<400){ 23 | chg = 1.50; 24 | } 25 | else if (unit>=400 && unit<600){ 26 | chg = 1.80; 27 | } 28 | else { 29 | chg = 2.00; 30 | } 31 | gramt = unit * chg; 32 | 33 | if (gramt > 300) { 34 | surchg = gramt * 15 / 100.0; 35 | netamt = gramt + surchg; 36 | } 37 | 38 | if (netamt < 100) 39 | netamt = 100; 40 | printf("\nElectricity Bill\n"); 41 | printf("Customer IDNO :%d\n",id); 42 | printf("Customer Name :%s\n",name); 43 | printf("unit Consumed :%d\n",unit); 44 | printf("Amount Charges @Rs. %4.2f per unit :%8.2f\n",chg,gramt); 45 | printf("Surchage Amount :%8.2f\n",surchg); 46 | printf("Net Amount Paid By the Customer :%8.2f\n",netamt); 47 | 48 | } -------------------------------------------------------------------------------- /saving/saving.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct expenses{ 4 | int salary, food, clothes, entertainment, internet; 5 | char others[10]; 6 | int other, total, saving; 7 | 8 | } p; 9 | int main() { 10 | printf ("\t Your Salary : "); 11 | scanf("%d",&p.salary); 12 | 13 | printf("\n*************MONTHLY-EXPENSES****************\n"); 14 | printf("On Food : Rs. "); 15 | scanf("%d",&p.food); 16 | 17 | printf("\nOn Clothes or footwears : Rs. "); 18 | scanf("%d",&p.clothes); 19 | 20 | printf("\nOn your entertainment : Rs. "); 21 | scanf("%d",&p.entertainment); 22 | 23 | printf("\nOn internet + mobile recharge : Rs. "); 24 | scanf("%d",&p.internet); 25 | 26 | printf("\nYour additional place of expenses : " ); 27 | scanf("%s",&p.others); 28 | 29 | printf("\nOn %s : Rs. ", p.others); 30 | scanf("%d",&p.other); 31 | 32 | p.total = p.food + p.clothes + p.entertainment + p.internet + p.other; 33 | printf(" \nTotal expenses : Rs. %d\n ",p.total); 34 | 35 | p.saving = p.salary - p.total; 36 | printf("****************************************************************"); 37 | printf(" \t\n Your total monthly saving is :Rs. %d ", p.saving); 38 | printf("****************************************************************"); 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /sum_max_column_row/sum_max_column_row.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int m, n, row, col, sum = 0, row_ind = 0, col_ind = 0; 5 | printf("\nEnter the type of matrix:\n "); 6 | scanf("%d %d",&m,&n); 7 | 8 | int row_arr[m]; 9 | int i, j; 10 | int mat[m][n]; 11 | printf("Enter the elements of matrix:\n"); 12 | for(i = 0; i < m; i++) { 13 | for(j = 0; j < n; j++) { 14 | scanf("%d",&mat[i][j]); 15 | } 16 | } 17 | 18 | int z = 0; 19 | 20 | printf("Sum of rows is:\n"); 21 | for(row=0; row 2 | 3 | void Array_sort(int *array , int n) { 4 | 5 | int i=0 , j=0 , temp=0; 6 | 7 | for(i=0 ; iarray[j+1]) { 10 | temp = array[j]; 11 | array[j] = array[j+1]; 12 | array[j+1] = temp; 13 | } 14 | } 15 | } 16 | 17 | printf("\nThe array after sorting is..\n"); 18 | for(i=0 ; i 2 | 3 | int main() { 4 | int m, n, p, q, c, d, k, sum = 0; 5 | int mat1[10][10], mat2[10][10], mat3[10][10]; 6 | 7 | printf("\n\tEnter number of rows and columns of mat1 matrix: "); 8 | scanf("%d%d", &m, &n); 9 | printf("\n\tEnter elements of matrix 1 : "); 10 | 11 | for (c = 0; c < m; c++) { 12 | for (d = 0; d < n; d++) { 13 | scanf("%d", &mat1[c][d]); 14 | } 15 | } 16 | 17 | printf("\n\tEnter number of rows and columns of mat2 matrix : "); 18 | scanf("%d %d", &p, &q); 19 | 20 | if (n != p) { 21 | printf("\n\tThe matrices can’t be multiplied with each other. "); 22 | } 23 | else { 24 | printf("\n\tEnter elements of matrix2 "); 25 | 26 | for (c = 0; c < p; c++) { 27 | for (d = 0; d < q; d++) { 28 | scanf("%d", &mat2[c][d]); 29 | } 30 | } 31 | } 32 | 33 | for (c = 0; c < m; c++) { 34 | for (d = 0; d < q; d++) { 35 | for (k = 0; k < p; k++) { 36 | sum = sum + mat1[c][k]*mat2[k][d]; 37 | } 38 | 39 | mat3[c][d] = sum; 40 | sum = 0; 41 | } 42 | } 43 | 44 | printf("\n\tProduct of the matrices:\n "); 45 | 46 | for (c = 0; c < m; c++) { 47 | for (d = 0; d < q; d++) { 48 | printf("%d\t", mat3[c][d]); 49 | 50 | printf("\n"); 51 | } 52 | } 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /password_conformation/password_conformation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | 6 | char name[25], pwd[25], ver[25]; 7 | int i, a, digi = 0, up = 0, low = 0, schar = 0; 8 | 9 | printf("Enter your Name: "); 10 | scanf("%s",&name); 11 | 12 | printf("Hello %s, Enter your password:\n",name); 13 | scanf("%s",&pwd); 14 | 15 | a = strlen(pwd); 16 | 17 | if(a < 5) { 18 | printf("Error: Password should contain minimum 5 characters "); 19 | } 20 | 21 | else if(a > 12) { 22 | printf("Error: Password shouldn't exceed 12 characters "); 23 | } 24 | 25 | else { 26 | for(i = 0; pwd[i] != NULL; i++) { 27 | if(pwd[i] >= 'A' && pwd[i] <= 'Z') { 28 | up++; 29 | } 30 | 31 | if(pwd[i] >= 'a' && pwd[i] <= 'z') { 32 | low++; 33 | } 34 | 35 | if(pwd[i] >= '0' && pwd[i]<='9') { 36 | digi++; 37 | } 38 | 39 | if(pwd[i]=='@'||pwd[i]=='#'||pwd[i]=='$' || pwd[i] == '&') { 40 | schar++; 41 | } 42 | } 43 | } 44 | 45 | if(up == 0) { 46 | printf("There must be at least one Uppercase\n"); 47 | } 48 | 49 | if(low == 0){ 50 | printf("There must be at least one Lowercase\n"); 51 | } 52 | 53 | if(digi == 0){ 54 | printf("There must be at least one Digit\n"); 55 | } 56 | 57 | if(schar == 0){ 58 | printf("There must be at least one Special Character among($,#,@,&) \n"); 59 | } 60 | 61 | else { 62 | printf("Confirm your Password\n"); 63 | scanf("%s",&ver); 64 | 65 | if(strcmp(pwd,ver) == 0){ 66 | printf("Welcome %s, your Password Verified",name); 67 | } 68 | 69 | else{ 70 | printf("Password did not match"); 71 | } 72 | 73 | } 74 | 75 | return 0; 76 | 77 | } -------------------------------------------------------------------------------- /dice/dice.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | int i; 7 | int runTime; 8 | int dice1; 9 | int dice2; 10 | int dice3; 11 | int temp; 12 | int total; 13 | char guess; 14 | int count = 0; 15 | 16 | srand(time(NULL)); 17 | 18 | printf("How many times do you want to play?\n"); 19 | scanf("%d\n", &runTime); 20 | 21 | 22 | dice1 = ( (rand() % 6) + 1); 23 | dice2 = ( (rand() % 6) + 1); 24 | dice3 = ( (rand() % 6) + 1); 25 | total = (dice1 + dice2 + dice3); 26 | 27 | if(runTime != 0){ 28 | 29 | printf("Dice 1: %d\n", dice1); 30 | printf("Dice 2: %d\n", dice2); 31 | printf("Dice 3: %d\n", dice3); 32 | printf("-------------------\n"); 33 | printf("Total: %d\n\n", total); 34 | 35 | temp = total; 36 | 37 | printf("Do you think the next total what will than the previous total? (h, s, l) \n"); 38 | scanf("%c", &guess); 39 | 40 | for(i = 0; i < runTime - 1; i++){ 41 | dice1 = ( (rand() % 6) + 1); 42 | dice2 = ( (rand() % 6) + 1); 43 | dice3 = ( (rand() % 6) + 1); 44 | total = (dice1 + dice2 + dice3); 45 | 46 | printf("Die 1: %d\n", dice1); 47 | printf("Die 2: %d\n", dice2); 48 | printf("Die 3: %d\n", dice3); 49 | printf("-------------------"); 50 | printf("Total: %d\n", total); 51 | 52 | if( (total > temp) && (guess == 'h') ){ 53 | printf("You guessed correctly!\n"); 54 | count++; 55 | } 56 | else if( (total == temp) && (guess == 's') ){ 57 | printf("You guessed correctly!\n"); 58 | count++; 59 | } 60 | else if( (total < temp) && (guess == 'l') ){ 61 | printf("You guessed correctly!\n"); 62 | count++; 63 | } 64 | else{ 65 | printf("You guessed incorrectly :(\n"); 66 | } 67 | 68 | temp = total; 69 | printf("Do you think the next total will be higher, the same, or lower than the previous total? (h, s, l) \n"); 70 | scanf(" %c", &guess); 71 | 72 | } 73 | printf("You got a total of %d guesses correct!", count); 74 | } 75 | else{ 76 | printf("Goodbye."); 77 | } 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /singly_linked_number/singly_linked_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int num; //Data of the node 7 | struct node *nextptr; //Address of the next node 8 | }*stnode; 9 | 10 | void createNodeList(int n); // function to create the list 11 | void displayList(); // function to display the list 12 | 13 | int main() 14 | { 15 | int n; 16 | printf("\n\n Linked List : To create and display Singly Linked List :\n"); 17 | printf("-------------------------------------------------------------\n"); 18 | 19 | printf(" Input the number of nodes : "); 20 | scanf("%d", &n); 21 | createNodeList(n); 22 | printf("\n Data entered in the list : \n"); 23 | displayList(); 24 | return 0; 25 | } 26 | void createNodeList(int n) 27 | { 28 | struct node *fnNode, *tmp; 29 | int num, i; 30 | stnode = (struct node *)malloc(sizeof(struct node)); 31 | 32 | if(stnode == NULL) //check whether the fnnode is NULL and if so no memory allocation 33 | { 34 | printf(" Memory can not be allocated."); 35 | } 36 | else 37 | { 38 | // reads data for the node through keyboard 39 | 40 | printf(" Input data for node 1 : "); 41 | scanf("%d", &num); 42 | stnode->num = num; 43 | stnode->nextptr = NULL; // links the address field to NULL 44 | tmp = stnode; 45 | // Creating n nodes and adding to linked list 46 | for(i=2; i<=n; i++) 47 | { 48 | fnNode = (struct node *)malloc(sizeof(struct node)); 49 | if(fnNode == NULL) 50 | { 51 | printf(" Memory can not be allocated."); 52 | break; 53 | } 54 | else 55 | { 56 | printf(" Input data for node %d : ", i); 57 | scanf(" %d", &num); 58 | 59 | fnNode->num = num; // links the num field of fnNode with num 60 | fnNode->nextptr = NULL; // links the address field of fnNode with NULL 61 | 62 | tmp->nextptr = fnNode; // links previous node i.e. tmp to the fnNode 63 | tmp = tmp->nextptr; 64 | } 65 | } 66 | } 67 | } 68 | void displayList() 69 | { 70 | struct node *tmp; 71 | if(stnode == NULL) 72 | { 73 | printf(" List is empty."); 74 | } 75 | else 76 | { 77 | tmp = stnode; 78 | while(tmp != NULL) 79 | { 80 | printf(" Data = %d\n", tmp->num); // prints the data of current node 81 | tmp = tmp->nextptr; // advances the position of current node 82 | } 83 | } 84 | } --------------------------------------------------------------------------------