├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── Hello_world ├── Hello_world.c ├── README.md ├── Sum and Difference of Two Numbers ├── Sum and Difference of Two Numbers_HR.c ├── a.out ├── check_the_even_num_array ├── check_the_even_num_array.c ├── find_sum_in_array ├── find_sum_in_array.c ├── frequency_of_number ├── frequency_of_number.c ├── function_in_c ├── function_in_c.c ├── greatest_and_smallest_num_array ├── greatest_and_smallest_num_array.c ├── highest_dublicate_test.c ├── highest_duplicate_array ├── highest_duplicate_array.c ├── new ├── new2 ├── new2.c ├── pattern ├── pattern.c ├── pattern_using_if.c ├── playing_with_characters_HR.c ├── simple_swap ├── simple_swap.c ├── strg ├── string_length ├── string_length.c ├── strlenth_function.c ├── struct_basic.c ├── test ├── test.c ├── voting_age └── voting_age.c /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [] 7 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Disabled" 3 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc-11 build active file", 6 | "command": "/usr/bin/gcc-11", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}/${fileBasenameNoExtension}" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Hello_world: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/Hello_world -------------------------------------------------------------------------------- /Hello_world.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int y = printf("hello world!\n"); 6 | 7 | return 0; 8 | 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C-Basic 2 | my learning C programs 3 | 4 | FOR OUTPUT IN TERMINAL : 5 | 6 | $ gcc filename.c 7 | $ ./a.out 8 | 9 | <============================> 10 | 11 | My Learning C Program Codes 12 | 13 | <============================> 14 | 15 | it's all code for my learning purpose 16 | -------------------------------------------------------------------------------- /Sum and Difference of Two Numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/Sum and Difference of Two Numbers -------------------------------------------------------------------------------- /Sum and Difference of Two Numbers_HR.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int a,b; 9 | float c,d; 10 | 11 | scanf("%d %d",&a,&b); 12 | printf("%d %d\n",a+b,a-b); 13 | 14 | scanf("%f %f",&c,&d); 15 | printf("%.1f %.1f",c+d,c-d); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/a.out -------------------------------------------------------------------------------- /check_the_even_num_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/check_the_even_num_array -------------------------------------------------------------------------------- /check_the_even_num_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int n; 5 | printf("Enter number of elements in the array: "); 6 | scanf("%d", &n); 7 | 8 | int array[n]; 9 | 10 | //take the n number of input 11 | for(int i=0;i 2 | 3 | int main(){ 4 | 5 | int arr[] = {1,2,3,4,6,3,5,3}; 6 | int n = 8; 7 | int sum = 7; 8 | 9 | for(int i=0;i 2 | 3 | int main(){ 4 | 5 | 6 | int array[] = {1, 7 | 2, 8 | 6, 9 | 4, 10 | 8, 11 | 5, 12 | 9, 13 | 7, 14 | 8, 15 | 10, 16 | 1, 17 | 6, 18 | 3, 19 | 8, 20 | 6, 21 | 10, 22 | 3, 23 | 8, 24 | 2, 25 | 7, 26 | 6, 27 | 5, 28 | 7, 29 | 6, 30 | 8, 31 | 6, 32 | 7, 33 | 5, 34 | 6, 35 | 6, 36 | 5, 37 | 6, 38 | 7, 39 | 5, 40 | 6, 41 | 4, 42 | 8, 43 | 6, 44 | 8, 45 | 10}; 46 | 47 | int count = 0; 48 | printf("value%13s\n","frequency"); //%13s for the space 49 | for(int i=1;i<=10;i++){ 50 | for(int j=1;j<=40;j++){ 51 | if(array[j] == i){ //check the i in array[j] 52 | count++; //adding the count 53 | } 54 | } 55 | 56 | printf("%d%13d\n",i,count); 57 | count = 0; 58 | } 59 | 60 | return 0; 61 | 62 | } -------------------------------------------------------------------------------- /function_in_c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/function_in_c -------------------------------------------------------------------------------- /function_in_c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int max(int x, int y){ 4 | if(x > y){ 5 | return x; 6 | }else{ 7 | return y; 8 | } 9 | } 10 | int main() { 11 | int a, b, c, d; 12 | scanf("%d %d %d %d", &a, &b, &c, &d); 13 | int left_max = max(a, b); 14 | int right_max = max(c, d); 15 | int final_max = max(left_max, right_max); 16 | printf("%d", final_max); 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /greatest_and_smallest_num_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/greatest_and_smallest_num_array -------------------------------------------------------------------------------- /greatest_and_smallest_num_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n,arr[10]; 6 | 7 | printf("Enter the number of elements:"); 8 | scanf("%d", &n); 9 | 10 | for (int i = 0; i < n; i++) { 11 | printf("Enter number %d:",i+1); 12 | scanf("%d", &arr[i]); 13 | } 14 | 15 | int max = arr[0]; 16 | int min = arr[0]; 17 | 18 | for (int i = 1; i < n;i++ ) { 19 | if ( max < arr[i]) { 20 | max = arr[i]; 21 | } 22 | 23 | if ( min > arr[i]) { 24 | min = arr[i]; 25 | } 26 | } 27 | 28 | printf("Largest number = %d\n", max); 29 | printf("smallest number = %d\n", min); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /highest_dublicate_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | 6 | int array[] = {2,4,5,2,2,3,4,4,5,2,3,3,4,5,6,6,2,2,2}; 7 | int arr[10]; 8 | 9 | 10 | int count = 0; 11 | 12 | for (int i = 1; i <= 10 ; i++) 13 | { 14 | for (int j = 0; j <= 19; j++) 15 | { 16 | if(array[j] == i){ 17 | count++; 18 | } 19 | } 20 | int a[10],out; 21 | a[out] = count; 22 | int b; 23 | 24 | for (out = 0; out <= count ; out++) 25 | { for (b = a + 1; b < 10; b++) 26 | { 27 | if(a[out] > a[b] ){ 28 | a[out] = out; 29 | } 30 | } 31 | } 32 | 33 | printf("%d\n",out); 34 | 35 | count = 0; 36 | 37 | 38 | } 39 | 40 | } 41 | 42 | 43 | -------------------------------------------------------------------------------- /highest_duplicate_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/highest_duplicate_array -------------------------------------------------------------------------------- /highest_duplicate_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // [2, 2, 2, 1, 1, 3, 4, 4] 5 | int main() { 6 | // Write C code here 7 | int a; 8 | int arr[] = {2, 2, 2, 1, 1, 3, 4, 4}; 9 | int n = 8; 10 | 11 | // find the number with max frequency postive numbers 12 | // using one for loop 13 | // sort the array in ascending order -- bubble sort 14 | 15 | for (int i = 0; i < n; ++i) 16 | { 17 | 18 | for (int j = i + 1; j < n; ++j) 19 | { 20 | 21 | if (arr[i] > arr[j]) 22 | { 23 | 24 | a = arr[i]; 25 | arr[i] = arr[j]; 26 | arr[j] = a; 27 | 28 | } 29 | 30 | } 31 | 32 | } 33 | 34 | for(int i = 0; i < n; i++){ 35 | printf("%d ", arr[i]); 36 | } 37 | 38 | printf("\n"); 39 | 40 | int val = 1; 41 | int max_val = -100; 42 | int number = -1; 43 | for(int i = 0; i < n-1; i++){ 44 | 45 | printf("curent_number: %d, val: %d, max_val: %d\n", arr[i], val, max_val); 46 | if(arr[i] == arr[i+1]){ 47 | val += 1; 48 | } 49 | else{ 50 | if(max_val < val){ 51 | max_val = val; 52 | number = arr[i]; 53 | } 54 | // for reset 55 | val = 1; 56 | } 57 | 58 | } 59 | 60 | printf("The max freq is: %d, and number is: %d", max_val, number); 61 | 62 | 63 | return 0; 64 | } -------------------------------------------------------------------------------- /new: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/new -------------------------------------------------------------------------------- /new2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/new2 -------------------------------------------------------------------------------- /new2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int, int); 4 | 5 | int main() 6 | { 7 | int a = 2, b = 5; 8 | 9 | swap(a, b); 10 | 11 | return 0; 12 | } 13 | 14 | void swap(int x, int y) 15 | { 16 | int temp; 17 | 18 | temp = x; 19 | x = y; 20 | y = temp; 21 | 22 | printf("a = %d and b = %d\n", x, y); 23 | 24 | 25 | } -------------------------------------------------------------------------------- /pattern: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/pattern -------------------------------------------------------------------------------- /pattern.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int i,j,n; //pattern1 start 6 | 7 | printf("enter the n:"); 8 | scanf("%d",&n); 9 | 10 | for(i=1;i<=n;i++){ 11 | for(j=1;j<=n;j++){ 12 | 13 | printf("*"); 14 | } 15 | printf("\n"); 16 | 17 | } 18 | } 19 | //pattern1 end 20 | 21 | /* int i,j,row,col; //pattern2 start 22 | 23 | printf("enter the row:"); 24 | scanf("%d",&row); 25 | 26 | printf("enter the col:"); 27 | scanf("%d",&col); 28 | 29 | for(i=1;i<=row;i++){ 30 | for(j=1;j<=col;j++){ 31 | 32 | printf("*"); 33 | } 34 | printf("\n"); 35 | } 36 | 37 | } //pattern2 end*/ 38 | 39 | 40 | /* int i,j,k,n; //pattern3 start 41 | 42 | printf("enter the num:"); 43 | scanf("%d",&n); 44 | 45 | for(i=n;i>=1;i--){ 46 | for(j=1;j<=i;j++){ 47 | printf("*"); 48 | } 49 | printf("\n"); 50 | 51 | } 52 | } //pattern3 end*/ 53 | 54 | 55 | /*int n; //pattern4 start 56 | 57 | printf("enter the num:"); 58 | scanf("%d",&n); 59 | 60 | for(int i=1;i<=n;i++){ 61 | for(int j=1;j<=i;j++){ 62 | printf("%d",j); 63 | } 64 | printf("\n"); 65 | 66 | } 67 | 68 | }//pattern 4 end*/ 69 | 70 | 71 | 72 | /* int n,i,j; 73 | 74 | printf("enter the num:"); 75 | scanf("%d",&n); 76 | 77 | for(i=1;i<=n;i++){ 78 | for(j=1;j<=i;j++){ 79 | printf("%d",j); 80 | 81 | } 82 | printf("\n"); 83 | } 84 | for(i=n-1;i>=1;i--){ 85 | for(j=1;j<=i;j++){ 86 | printf("%d",j); 87 | } 88 | printf("\n"); 89 | } 90 | 91 | 92 | }*/ 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /pattern_using_if.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int i,j,n; 6 | 7 | printf("enter the n:"); 8 | scanf("%d",&n); 9 | 10 | for (int i = 1; i <= 2 * n - 1; i++) //input(3)i=1;i<= 2 * n-1(2*3-1=5);i++ 11 | {//output(i = 4) 12 | int c; 13 | if (i > n) //check i > n (2 > n) 14 | { 15 | c = n - (i - n); //(n-(i-n)) (3-(4-3))(3-(1))c=2 16 | } 17 | else 18 | { 19 | c = i; //c = 2 20 | } 21 | for (int j = 1; j <= c; j++) //j=1;j=c(j=2);j++ 1,2 22 | { 23 | printf("%d", j); //printing(1,2) 24 | 25 | 26 | } 27 | printf("\n"); 28 | } 29 | } 30 | 31 | 32 | //EXPLANATION 33 | 34 | // n=3 35 | // i = 1; i <= 2 * n - 1; i++ 36 | // i<=(2*n-1)(2*3-1)i<=5 37 | // i=1 38 | // if(i>n)(1>3) no 39 | // else(c=i)(c=1) 40 | // j = 1; j <= c; j++ 41 | // j<=c(j<=1) 42 | // print(j)=1 -jloop end go to i 43 | 44 | // n=3 45 | // i=2;i<=5 46 | // if(i>n)(2>3) no 47 | // else(c=i)(c=2) 48 | // j = 1; j <= c; j++ 49 | // j<=c(j<=2) 50 | // print(j)=1,2 -jloop end go to i 51 | 52 | // n=3 53 | // i=3;i<=5 54 | // if(i>n)(3>3) no 55 | // else(c=i)(c=3) 56 | // j = 1; j <= c; j++ 57 | // j<=c(j<=3) 58 | // print(j)=1,2,3 -jloop end go to i 59 | 60 | // n=3 61 | // i=4;i<=5 62 | // if(i>n)(4>3) yes 63 | // c = n - (i - n); //(n-(i-n))(3-(4-3))(3-(1))c=2 64 | // j = 1; j <= c; j++ 65 | // j<=c(j<=2) 66 | // print(j)=1,2 -jloop end go to i 67 | 68 | // n=3 69 | // i=4;i<=5 70 | // if(i>n)(5>3) yes 71 | // c = n - (i - n); //(n-(i-n))(3-(4-3))(3-(2))c=1 72 | // j = 1; j <= c; j++ 73 | // j<=c(j<=1) 74 | // print(j)=1 -jloop end go to i 75 | 76 | 77 | -------------------------------------------------------------------------------- /playing_with_characters_HR.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | int main() 8 | { 9 | 10 | int n=100; 11 | char ch[n],s[n],sen[n]; 12 | 13 | scanf("%s %s %[^\n]%*c", &ch,&s,&sen); 14 | printf("%s\n%s\n%s", ch,s,sen); 15 | 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /simple_swap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/simple_swap -------------------------------------------------------------------------------- /simple_swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x = 10, y = 15; 5 | 6 | int temp; 7 | 8 | temp = x; 9 | x = y; 10 | y = temp; 11 | 12 | printf("x is %d , y is %d",x,y); 13 | } -------------------------------------------------------------------------------- /strg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/strg -------------------------------------------------------------------------------- /string_length: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/string_length -------------------------------------------------------------------------------- /string_length.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | int n = 100; 6 | int i = 0; 7 | char name[n]; 8 | int length = 0; 9 | 10 | printf("enter the name: "); 11 | fgets(name,n,stdin); 12 | 13 | while (name[i] != '\0') 14 | { 15 | length++; 16 | i++; 17 | 18 | } 19 | 20 | printf("length of string: %d\n",length-1); 21 | } -------------------------------------------------------------------------------- /strlenth_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int mystrlen(char *s) 5 | { 6 | int i = 0; 7 | while (*(s + i) != '\0') 8 | { 9 | i++; 10 | } 11 | 12 | return i; 13 | } 14 | 15 | int main() 16 | { 17 | char name[100]; 18 | printf("Enter name: "); 19 | fgets(name, 100, stdin); 20 | 21 | // find the string length 22 | int len = mystrlen(name); 23 | printf("len: %d\n", len); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /struct_basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Employee 4 | { 5 | char name[100]; 6 | int age; 7 | char address[2][10]; 8 | long phn; 9 | int id; 10 | }; 11 | 12 | 13 | int main() 14 | { 15 | struct Employee emp1; 16 | struct Employee emp[10]; 17 | emp1.age = 20; 18 | emp1.phn = 9876321892; 19 | printf("Employee 1 age is: %d\n", emp1.age); 20 | printf("Employee 1 age is: %ld\n", emp1.phn); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/test -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | float bp,da,hra,grpay; 6 | 7 | printf("enter the basic pay of vj: "); 8 | scanf("%f",&bp); 9 | 10 | da = 0.4*bp; 11 | hra = 0.2*bp; 12 | grpay = bp+da+hra; 13 | 14 | printf("\n Basic pay 0f vj %f",bp); 15 | printf("\ndearness allowance %f",da); 16 | printf("\nhouse rend allowance %f",hra); 17 | printf("\nGrosspay of vj is %f",grpay); 18 | 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /voting_age: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VIJAYWHAT/C-Basic/268ba4f3a146b8f12e9d2473d1cb42ff75cfdc24/voting_age -------------------------------------------------------------------------------- /voting_age.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int voting_age; 5 | 6 | 7 | printf("enter you age:"); 8 | scanf("%d",&voting_age); 9 | 10 | 11 | 12 | if(voting_age >= 18){ 13 | 14 | printf("Legal to vode,collect your voter id\n"); 15 | 16 | } 17 | 18 | /*else if(voting_age == 17) 19 | { 20 | printf("please wait for %d more year to vote\n",18-voting_age); 21 | } */ 22 | 23 | else{ 24 | 25 | 26 | const char *year = (voting_age == 17) ? "year" : "years"; 27 | 28 | printf("please wait for %d more %s to vote\n",18-voting_age,year); 29 | } 30 | 31 | } --------------------------------------------------------------------------------