From 20b90adee86e2e700c1028852862782103f9b1d0 Mon Sep 17 00:00:00 2001 From: Praveen Kumar <51860269+praveenkumar5108@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:32:38 +0530 Subject: [PATCH 001/394] greaterno Program to Find Largest of Two Numbers --- greaterno | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 greaterno diff --git a/greaterno b/greaterno new file mode 100644 index 00000000..44608557 --- /dev/null +++ b/greaterno @@ -0,0 +1,24 @@ +/* C Program to Find Largest of Two numbers */ + +#include + +int main() { + int a, b; + printf("Please Enter Two different values\n"); + scanf("%d %d", &a, &b); + + if(a > b) + { + printf("%d is Largest\n", a); + } + else if (b > a) + { + printf("%d is Largest\n", b); + } + else + { + printf("Both are Equal\n"); + } + + return 0; +} From 4f448b01509110fc3a5e562aae516290474199bd Mon Sep 17 00:00:00 2001 From: halkoo <47682505+halkoo@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:40:36 +0530 Subject: [PATCH 002/394] Arithmatic Operations C program to perform arithmetic operations such as addition, subtraction, multiplication, modulo division and division. --- Arithmatic Operations | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Arithmatic Operations diff --git a/Arithmatic Operations b/Arithmatic Operations new file mode 100644 index 00000000..d70e9993 --- /dev/null +++ b/Arithmatic Operations @@ -0,0 +1,7 @@ +#include +int main() +{ + int a,b; + scanf("%d%d",&a,&b); + printf("%d\n%d\n%d\n%d\n%d",(a+b),(a-b),(a*b),(a%b),(a/b)); +} From b678e6bb82b84818666e83a88afec6678d29f04b Mon Sep 17 00:00:00 2001 From: yashkumarjha <55932900+yashkumarjha@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:37:53 +0530 Subject: [PATCH 003/394] Largest no. This will take input of 3 nos and will give output as the largest no. among them. --- LargestNo. | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LargestNo. diff --git a/LargestNo. b/LargestNo. new file mode 100644 index 00000000..8c571177 --- /dev/null +++ b/LargestNo. @@ -0,0 +1,20 @@ +#include +int main() { + double n1, n2, n3; + printf("Enter three different numbers: "); + scanf("%lf %lf %lf", &n1, &n2, &n3); + + // if n1 is greater than both n2 and n3, n1 is the largest + if (n1 >= n2 && n1 >= n3) + printf("%.2f is the largest number.", n1); + + // if n2 is greater than both n1 and n3, n2 is the largest + if (n2 >= n1 && n2 >= n3) + printf("%.2f is the largest number.", n2); + + // if n3 is greater than both n1 and n2, n3 is the largest + if (n3 >= n1 && n3 >= n2) + printf("%.2f is the largest number.", n3); + + return 0; +} From 9f7aa87849495708aece9e3d7e816381026e5ee4 Mon Sep 17 00:00:00 2001 From: Shivam Kumar Sah <67648712+ShivamKumarSah@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:38:42 +0530 Subject: [PATCH 004/394] Linked List in C: Menu Driven Program Menu Driven Program to show implementation of linked list in C --- Linked_List_in_C | 267 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 267 insertions(+) create mode 100644 Linked_List_in_C diff --git a/Linked_List_in_C b/Linked_List_in_C new file mode 100644 index 00000000..271cc5a5 --- /dev/null +++ b/Linked_List_in_C @@ -0,0 +1,267 @@ +#include +#include +struct node +{ + int data; + struct node *next; +}; +struct node *head; + +void beginsert (); +void lastinsert (); +void randominsert(); +void begin_delete(); +void last_delete(); +void random_delete(); +void display(); +void search(); +void main () +{ + int choice =0; + while(choice != 9) + { + printf("\n\n*********Main Menu*********\n"); + printf("\nChoose one option from the following list ...\n"); + printf("\n===============================================\n"); + printf("\n1.Insert in begining\n2.Insert at last\n3.Insert at any random location\n4.Delete from Beginning\n + 5.Delete from last\n6.Delete node after specified location\n7.Search for an element\n8.Show\n9.Exit\n"); + printf("\nEnter your choice?\n"); + scanf("\n%d",&choice); + switch(choice) + { + case 1: + beginsert(); + break; + case 2: + lastinsert(); + break; + case 3: + randominsert(); + break; + case 4: + begin_delete(); + break; + case 5: + last_delete(); + break; + case 6: + random_delete(); + break; + case 7: + search(); + break; + case 8: + display(); + break; + case 9: + exit(0); + break; + default: + printf("Please enter valid choice.."); + } + } +} +void beginsert() +{ + struct node *ptr; + int item; + ptr = (struct node *) malloc(sizeof(struct node *)); + if(ptr == NULL) + { + printf("\nOVERFLOW"); + } + else + { + printf("\nEnter value\n"); + scanf("%d",&item); + ptr->data = item; + ptr->next = head; + head = ptr; + printf("\nNode inserted"); + } + +} +void lastinsert() +{ + struct node *ptr,*temp; + int item; + ptr = (struct node*)malloc(sizeof(struct node)); + if(ptr == NULL) + { + printf("\nOVERFLOW"); + } + else + { + printf("\nEnter value?\n"); + scanf("%d",&item); + ptr->data = item; + if(head == NULL) + { + ptr -> next = NULL; + head = ptr; + printf("\nNode inserted"); + } + else + { + temp = head; + while (temp -> next != NULL) + { + temp = temp -> next; + } + temp->next = ptr; + ptr->next = NULL; + printf("\nNode inserted"); + + } + } +} +void randominsert() +{ + int i,loc,item; + struct node *ptr, *temp; + ptr = (struct node *) malloc (sizeof(struct node)); + if(ptr == NULL) + { + printf("\nOVERFLOW"); + } + else + { + printf("\nEnter element value"); + scanf("%d",&item); + ptr->data = item; + printf("\nEnter the location after which you want to insert "); + scanf("\n%d",&loc); + temp=head; + for(i=0;inext; + if(temp == NULL) + { + printf("\ncan't insert\n"); + return; + } + + } + ptr ->next = temp ->next; + temp ->next = ptr; + printf("\nNode inserted"); + } +} +void begin_delete() +{ + struct node *ptr; + if(head == NULL) + { + printf("\nList is empty\n"); + } + else + { + ptr = head; + head = ptr->next; + free(ptr); + printf("\nNode deleted from the begining ...\n"); + } +} +void last_delete() +{ + struct node *ptr,*ptr1; + if(head == NULL) + { + printf("\nlist is empty"); + } + else if(head -> next == NULL) + { + head = NULL; + free(head); + printf("\nOnly node of the list deleted ...\n"); + } + + else + { + ptr = head; + while(ptr->next != NULL) + { + ptr1 = ptr; + ptr = ptr ->next; + } + ptr1->next = NULL; + free(ptr); + printf("\nDeleted Node from the last ...\n"); + } +} +void random_delete() +{ + struct node *ptr,*ptr1; + int loc,i; + printf("\n Enter the location of the node after which you want to perform deletion \n"); + scanf("%d",&loc); + ptr=head; + for(i=0;inext; + + if(ptr == NULL) + { + printf("\nCan't delete"); + return; + } + } + ptr1 ->next = ptr ->next; + free(ptr); + printf("\nDeleted node %d ",loc+1); +} +void search() +{ + struct node *ptr; + int item,i=0,flag; + ptr = head; + if(ptr == NULL) + { + printf("\nEmpty List\n"); + } + else + { + printf("\nEnter item which you want to search?\n"); + scanf("%d",&item); + while (ptr!=NULL) + { + if(ptr->data == item) + { + printf("item found at location %d ",i+1); + flag=0; + } + else + { + flag=1; + } + i++; + ptr = ptr -> next; + } + if(flag==1) + { + printf("Item not found\n"); + } + } + +} + +void display() +{ + struct node *ptr; + ptr = head; + if(ptr == NULL) + { + printf("Nothing to print"); + } + else + { + printf("\nprinting values . . . . .\n"); + while (ptr!=NULL) + { + printf("\n%d",ptr->data); + ptr = ptr -> next; + } + } +} + From a31a8bc9f58959af9964bda827a3f96e39224db1 Mon Sep 17 00:00:00 2001 From: Aditya Kolhatkar Date: Thu, 1 Oct 2020 20:39:17 +0530 Subject: [PATCH 005/394] Music Player Music Player Using C++ Programming Language --- Music Player | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Music Player diff --git a/Music Player b/Music Player new file mode 100644 index 00000000..6e08b928 --- /dev/null +++ b/Music Player @@ -0,0 +1,65 @@ + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include +#include +#include +#include + +#pragma comment(lib, "strmiids.lib") + +class Mp3 +{ +public: + Mp3(); + ~Mp3(); + + bool Load(LPCWSTR filename); + void Cleanup(); + + bool Play(); + bool Pause(); + bool Stop(); + + // Poll this function with msTimeout = 0, so that it return immediately. + // If the mp3 finished playing, WaitForCompletion will return true; + bool WaitForCompletion(long msTimeout, long* EvCode); + + // -10000 is lowest volume and 0 is highest volume, positive value > 0 will fail + bool SetVolume(long vol); + + // -10000 is lowest volume and 0 is highest volume + long GetVolume(); + + // Returns the duration in 1/10 millionth of a second, + // meaning 10,000,000 == 1 second + // You have to divide the result by 10,000,000 + // to get the duration in seconds. + __int64 GetDuration(); + + // Returns the current playing position + // in 1/10 millionth of a second, + // meaning 10,000,000 == 1 second + // You have to divide the result by 10,000,000 + // to get the duration in seconds. + __int64 GetCurrentPosition(); + + // Seek to position with pCurrent and pStop + // bAbsolutePositioning specifies absolute or relative positioning. + // If pCurrent and pStop have the same value, the player will seek to the position + // and stop playing. Note: Even if pCurrent and pStop have the same value, + // avoid putting the same pointer into both of them, meaning put different + // pointers with the same dereferenced value. + bool SetPositions(__int64* pCurrent, __int64* pStop, bool bAbsolutePositioning); + +private: + IGraphBuilder * pigb; + IMediaControl * pimc; + IMediaEventEx * pimex; + IBasicAudio * piba; + IMediaSeeking * pims; + bool ready; + // Duration of the MP3. + __int64 duration; + +}; From 9132952e4f6f161284e03ede543399f89f2c09dc Mon Sep 17 00:00:00 2001 From: srinivas1108 <62225416+srinivas1108@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:39:36 +0530 Subject: [PATCH 006/394] Create helloc --- helloc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 helloc diff --git a/helloc b/helloc new file mode 100644 index 00000000..bd384c49 --- /dev/null +++ b/helloc @@ -0,0 +1,6 @@ +#include +#include +void main() +{ +printf("Hello c ! Have a nice day:)"); +} From 97b82fbfcce353508da5964be928157846d31452 Mon Sep 17 00:00:00 2001 From: Abhra Kanti Dubey <58810632+abhrakantidubey@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:39:44 +0530 Subject: [PATCH 007/394] Create simple interest finder.c This is a basic SI finder in C program for Beginners --- simple interest finder.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 simple interest finder.c diff --git a/simple interest finder.c b/simple interest finder.c new file mode 100644 index 00000000..6e76f044 --- /dev/null +++ b/simple interest finder.c @@ -0,0 +1,12 @@ +#include +#include +void main() +{ + int p,n,r,si; + clrscr(); + printf("Enter Principle, Rate of interest & Time :"); + scanf("%d%d%d",&p,&r,&n); + si=(p*r*n)/100; + printf("Simple Interest is :%d",si); + getch(); +} From 74bc2a64c2c18c901588e1b5fd107ec4c249a8f1 Mon Sep 17 00:00:00 2001 From: Sainath <43644656+sainathbatchu@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:40:37 +0530 Subject: [PATCH 008/394] create leapyear in c to find leap year --- leapyear.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 leapyear.c diff --git a/leapyear.c b/leapyear.c new file mode 100644 index 00000000..7aa916e8 --- /dev/null +++ b/leapyear.c @@ -0,0 +1,19 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + else { + printf("%d is not a leap year.", year); + } + return 0; +} From 102b98695e359383348ddecb6c7ea5b17f15bdb2 Mon Sep 17 00:00:00 2001 From: Tanishq777 <52687608+Tanishq777@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:40:47 +0530 Subject: [PATCH 009/394] GCD of Two Numbers --- GCD Of numbers | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 GCD Of numbers diff --git a/GCD Of numbers b/GCD Of numbers new file mode 100644 index 00000000..a0b7eaa4 --- /dev/null +++ b/GCD Of numbers @@ -0,0 +1,19 @@ +import Scanner.*; +public class GCD { + + public static void main(String[] args) { + Scanner s=new Scanner(System.in); + int n1=s.nextInt(); + int n2=s.nextInt(); + int gcd = 1; + + for(int i = 1; i <= n1 && i <= n2; ++i) + { + // Checks if i is factor of both integers + if(n1 % i==0 && n2 % i==0) + gcd = i; + } + + System.out.printf("G.C.D of %d and %d is %d", n1, n2, gcd); + } +} From 2763bbe46132797fcd9a96147c920744078106a4 Mon Sep 17 00:00:00 2001 From: srinivas1108 <62225416+srinivas1108@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:42:10 +0530 Subject: [PATCH 010/394] hacktoberfest --- hacktoberfest | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 hacktoberfest diff --git a/hacktoberfest b/hacktoberfest new file mode 100644 index 00000000..5ded750d --- /dev/null +++ b/hacktoberfest @@ -0,0 +1,6 @@ +#include +#include +void main() +{ +printf("Hacktober fest is going on!!"); +} From 1a3b278d82548a053c88d04fbd1ecb89e4af1ff8 Mon Sep 17 00:00:00 2001 From: ajaynadar8 <56928693+ajaynadar8@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:42:57 +0530 Subject: [PATCH 011/394] Star_pattern_heart --- Star_pattern_heart | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Star_pattern_heart diff --git a/Star_pattern_heart b/Star_pattern_heart new file mode 100644 index 00000000..ee6ef145 --- /dev/null +++ b/Star_pattern_heart @@ -0,0 +1,40 @@ +#include +#include +#include + +void main(){ + + int n,i,j; + printf("Enter the value of n: "); + scanf("%d",&n); + + for( i = 0; i < n ; i++){ // upper part + + for ( j = 1; j <= 6*n-1 ; j++) + { + if( ( j >= n - i && j <= 2*n + i ) || ( j >= 4*n - i && j <= 5*n +i ) ){ + printf("*"); + }else { + printf(" "); + } + + } + + printf("\n"); + } + + for( i = 0; i < 3*n ; i++){ // lower part + + for ( j = 1; j <= 6*n-1 ; j++) + { + if(j >= 1 + i && j <= 6*n - i){ + printf("*"); + }else { + printf(" "); + } + + } + + printf("\n"); + } +} From afdc196bf4c92c7935929b25c6e66daf234c0dc3 Mon Sep 17 00:00:00 2001 From: Piyush Gupta <70501930+Piyush-Guptas@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:42:59 +0530 Subject: [PATCH 012/394] check tp prime no or not Program to Check Prime Number --- check to prime no or not | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 check to prime no or not diff --git a/check to prime no or not b/check to prime no or not new file mode 100644 index 00000000..4fba8ae0 --- /dev/null +++ b/check to prime no or not @@ -0,0 +1,27 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From 7ddbce25f4090c120189dfb03c3c756bfab3693e Mon Sep 17 00:00:00 2001 From: MANISH762000 <43494119+MANISH762000@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:43:00 +0530 Subject: [PATCH 013/394] Create ALGO_BUCKETSORT BUCKET SORT ALGORITHM --- ALGO_BUCKETSORT | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ALGO_BUCKETSORT diff --git a/ALGO_BUCKETSORT b/ALGO_BUCKETSORT new file mode 100644 index 00000000..a861eee9 --- /dev/null +++ b/ALGO_BUCKETSORT @@ -0,0 +1,49 @@ +#include +#include +#include +using namespace std; + +//Bucket Sort Program when integers are floating point numbers in some range + +void bucketSort(float *arr,int n) +{ + vector b[n]; + int i,j; + for(i=0;i>n; +int i; +for(i=0;i>arr[i]; + +bucketSort(arr,n); +cout<<"Sorted Array"< Date: Thu, 1 Oct 2020 20:43:38 +0530 Subject: [PATCH 014/394] Create SquareFill with stars This is the square full fill with * --- SquareFill with stars | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SquareFill with stars diff --git a/SquareFill with stars b/SquareFill with stars new file mode 100644 index 00000000..218b6d1e --- /dev/null +++ b/SquareFill with stars @@ -0,0 +1,26 @@ +#include +#include +void main() + +{ +int i,j; + +clrscr(); for(i=1;i<=5;i++) + +{ + +for(j=1;j<=5;j++) + +{ + +printf("*"); + +} + +printf("\n"); + +} + +getch(); + +} From 440b01fde7f93f2900f9b42a53a53515ca4923d7 Mon Sep 17 00:00:00 2001 From: souparnapal <72145624+souparnapal@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:43:46 +0530 Subject: [PATCH 015/394] prime number C Program to Check Whether a Number is Prime or Not --- prime number | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 prime number diff --git a/prime number b/prime number new file mode 100644 index 00000000..4fba8ae0 --- /dev/null +++ b/prime number @@ -0,0 +1,27 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From 3af996e8551ae5f48751c0e1918d447d1b566bec Mon Sep 17 00:00:00 2001 From: Sandydalvi2001 <69284228+Sandydalvi2001@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:44:05 +0530 Subject: [PATCH 016/394] Factorial of any number Easiest way to calculate of any number --- Factorial of any number | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Factorial of any number diff --git a/Factorial of any number b/Factorial of any number new file mode 100644 index 00000000..36027841 --- /dev/null +++ b/Factorial of any number @@ -0,0 +1,31 @@ +#include +void main() +{ +int n,i,fact=1; +printf("enter the number whose factorial is required:"); +scanf("%d",&n); +if(n==0) +{ +printf("\nFactorial of negative number doesn't exist"); +} +else +{ +for(i=1;i<=n;i++) +{ +fact=fact*i; +} +} +printf("\nFactorial of %d is :%d",n,fact); +getch(); +} + + + + + + + + + + + From d8073662299510733e1721d8421394437a1b908e Mon Sep 17 00:00:00 2001 From: Piyush Gupta <70501930+Piyush-Guptas@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:46:49 +0530 Subject: [PATCH 017/394] use of bitwise operators Program to use of bitwise operators --- use of bitwise operators | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 use of bitwise operators diff --git a/use of bitwise operators b/use of bitwise operators new file mode 100644 index 00000000..d41b5a26 --- /dev/null +++ b/use of bitwise operators @@ -0,0 +1,28 @@ +// C Program to demonstrate use of bitwise operators +#include +int main() +{ + // a = 5(00000101), b = 9(00001001) + unsigned char a = 5, b = 9; + + // The result is 00000001 + printf("a = %d, b = %d\n", a, b); + printf("a&b = %d\n", a & b); + + // The result is 00001101 + printf("a|b = %d\n", a | b); + + // The result is 00001100 + printf("a^b = %d\n", a ^ b); + + // The result is 11111010 + printf("~a = %d\n", a = ~a); + + // The result is 00010010 + printf("b<<1 = %d\n", b << 1); + + // The result is 00000100 + printf("b>>1 = %d\n", b >> 1); + + return 0; +} From a7cf892cff76a2c101b3b1191daa0173374f4742 Mon Sep 17 00:00:00 2001 From: Siddhesh Ambre <64468240+Siddhesh003@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:48:57 +0530 Subject: [PATCH 018/394] addition Addition of two integers --- addition | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 addition diff --git a/addition b/addition new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/addition @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} From 597d615e77a5f6c331b3aea4727d72e8cc460ccf Mon Sep 17 00:00:00 2001 From: Piyush Gupta <70501930+Piyush-Guptas@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:50:30 +0530 Subject: [PATCH 019/394] Print numbers Program to Print numbers --- Print numbers | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Print numbers diff --git a/Print numbers b/Print numbers new file mode 100644 index 00000000..2d7ee0f0 --- /dev/null +++ b/Print numbers @@ -0,0 +1,12 @@ +// Print numbers from 1 to 10 +#include + +int main() { + int i; + + for (i = 1; i < 11; ++i) + { + printf("%d ", i); + } + return 0; +} From 44e68b41841130b3a0060607c75604417e70e80b Mon Sep 17 00:00:00 2001 From: Shivansh2304 <72212391+Shivansh2304@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:55:08 +0530 Subject: [PATCH 020/394] Factorial Program to find factorial of a number in C. --- Factorial | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Factorial diff --git a/Factorial b/Factorial new file mode 100644 index 00000000..1663258b --- /dev/null +++ b/Factorial @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); +return 0; +} From 9a9ea76e76ac179c284c4673a004b9a3db77cc15 Mon Sep 17 00:00:00 2001 From: Ankitpal002 <65125815+Ankitpal002@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:55:29 +0530 Subject: [PATCH 021/394] Create square of a number create a square of a number --- square of a number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 square of a number diff --git a/square of a number b/square of a number new file mode 100644 index 00000000..6a11d55d --- /dev/null +++ b/square of a number @@ -0,0 +1,17 @@ +// by ankit pal +#include +#include + +int main() +{ + int number, Square; + + printf(" \n Please Enter any integer Value : "); + scanf("%d", &number); + + Square = number * number; + + printf("\n Square of a given number %d is = %d", number, Square); + + return 0; +} From 7dda99d34de138e7954b39590b140ebf827d1339 Mon Sep 17 00:00:00 2001 From: souparnapal <72145624+souparnapal@users.noreply.github.com> Date: Thu, 1 Oct 2020 20:57:42 +0530 Subject: [PATCH 022/394] reverse number C Program to Reverse an Integer --- reverse number | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 reverse number diff --git a/reverse number b/reverse number new file mode 100644 index 00000000..2555af0a --- /dev/null +++ b/reverse number @@ -0,0 +1,13 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + printf("Reversed number = %d", rev); + return 0; +} From 97b4051f25c45b26d9817bfaa4d90ee5c7171799 Mon Sep 17 00:00:00 2001 From: Mintu Konwar <31696314+mntknwr@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:05:49 +0530 Subject: [PATCH 023/394] sumoftwonum C program to find the sum of two number --- SumOfTwoNumber | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 SumOfTwoNumber diff --git a/SumOfTwoNumber b/SumOfTwoNumber new file mode 100644 index 00000000..666bd27d --- /dev/null +++ b/SumOfTwoNumber @@ -0,0 +1,10 @@ +#include +int main() +{ + int a, b, sum; + printf("\nEnter two no: "); + scanf("%d %d", &a, &b); + sum = a + b; + printf("Sum : %d", sum); + return(0); +} From a71be3e4c4e7d6129d52882177788d8d65472df8 Mon Sep 17 00:00:00 2001 From: Austin Noronha Date: Thu, 1 Oct 2020 21:08:26 +0530 Subject: [PATCH 024/394] Create check_prime_number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prime Numbers 1. A prime number is a whole number greater than 1, 2. Which is only divisible by 1 and itself. 3. First few prime numbers are : 2 3 5 7 11 13 17 19 23 ….. --- The progarm will ask for number and output if the number is a prime number or not. --- check_prime_number | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 check_prime_number diff --git a/check_prime_number b/check_prime_number new file mode 100644 index 00000000..9d10a632 --- /dev/null +++ b/check_prime_number @@ -0,0 +1,26 @@ +#include + +int main() { + int loop, number; + int prime = 1; + + printf("Enter a number"); + scanf("%d", &number); + + if(number <= 1){ + prime = 0; + } + else{ + for(loop = 2; loop < number; loop++) { + if((number % loop) == 0) { + prime = 0; + } + } + } + + if (prime == 1) + printf("%d is prime number.", number); + else + printf("%d is not a prime number.", number); + return 0; +} From e2e25c146224443b4eb26ce2edaa0e7880afb39e Mon Sep 17 00:00:00 2001 From: Ritesh-004 <72216225+Ritesh-004@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:22:09 +0530 Subject: [PATCH 025/394] Circle Program to create circle using concept of Computer Graphics. --- Circle | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Circle diff --git a/Circle b/Circle new file mode 100644 index 00000000..db312b54 --- /dev/null +++ b/Circle @@ -0,0 +1,14 @@ +#include +#include +#include +#include +int main() +{ + int gd=DETECT,gm; + initgraph(&gd, &gm, "c:\\turboc3\\bgi"); + circle(200,200,50); + getch(); + closegraph(); + return 0; +} + From d67dd40e2eafb3ab479c56ad8e34727e4f0e5336 Mon Sep 17 00:00:00 2001 From: Aryan405 <72143928+Aryan405@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:25:11 +0530 Subject: [PATCH 026/394] Code to sort an array --- CONTRIBUTING.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8b137891..1a1702a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1,35 @@ +#include + +int main(){ + int arr[100]; + int size , n; + printf("\n Enter the size of array \n"); + scanf("%d",&size); + printf("\n Enter the elements of array \n"); + for (int i = 0; i < size; i++) + { + scanf("%d",&arr[i]); + } + + for (int i = 0; i < size; i++) + { + for(int j=i+1; jarr[j]) + { + n = arr[i]; + arr[i] = arr[j]; + arr[j] = n; + } + + } + } + printf("\n The numbers arranged in ascending order is \n"); + for (int i = 0; i < size; i++) + { + printf("%d\n",arr[i]); + } + + + return 0; +} From 019a45a63e234ec6d097b4763a9b77f77b76961d Mon Sep 17 00:00:00 2001 From: Jyothi-R <72215882+Jyothi-R@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:32:52 +0530 Subject: [PATCH 027/394] passing address Pass Address to Function --- passing address | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 passing address diff --git a/passing address b/passing address new file mode 100644 index 00000000..ff18b664 --- /dev/null +++ b/passing address @@ -0,0 +1,22 @@ +#include +void swap(int *n1, int *n2); + +int main() +{ + int num1 = 5, num2 = 10; + + // address of num1 and num2 is passed + swap( &num1, &num2); + + printf("num1 = %d\n", num1); + printf("num2 = %d", num2); + return 0; +} + +void swap(int* n1, int* n2) +{ + int temp; + temp = *n1; + *n1 = *n2; + *n2 = temp; +} From e05d91435af24b1f1100147dea5d8c92ca87f070 Mon Sep 17 00:00:00 2001 From: Yadnesh02 <71370436+Yadnesh02@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:36:06 +0530 Subject: [PATCH 028/394] Create C++ Program to Find All Roots of a Quadratic Equation --- ... to Find All Roots of a Quadratic Equation | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 C++ Program to Find All Roots of a Quadratic Equation diff --git a/C++ Program to Find All Roots of a Quadratic Equation b/C++ Program to Find All Roots of a Quadratic Equation new file mode 100644 index 00000000..1024112d --- /dev/null +++ b/C++ Program to Find All Roots of a Quadratic Equation @@ -0,0 +1,35 @@ +#include +#include +using namespace std; + +int main() { + + float a, b, c, x1, x2, discriminant, realPart, imaginaryPart; + cout << "Enter coefficients a, b and c: "; + cin >> a >> b >> c; + discriminant = b*b - 4*a*c; + + if (discriminant > 0) { + x1 = (-b + sqrt(discriminant)) / (2*a); + x2 = (-b - sqrt(discriminant)) / (2*a); + cout << "Roots are real and different." << endl; + cout << "x1 = " << x1 << endl; + cout << "x2 = " << x2 << endl; + } + + else if (discriminant == 0) { + cout << "Roots are real and same." << endl; + x1 = (-b + sqrt(discriminant)) / (2*a); + cout << "x1 = x2 =" << x1 << endl; + } + + else { + realPart = -b/(2*a); + imaginaryPart =sqrt(-discriminant)/(2*a); + cout << "Roots are complex and different." << endl; + cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl; + cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl; + } + + return 0; +} From 3d2d15c3082721658cd1bafc643f856583cd9e61 Mon Sep 17 00:00:00 2001 From: ishikagoel5628 <47469060+ishikagoel5628@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:43:41 +0530 Subject: [PATCH 029/394] Create ugly numbers Check whether a given number is an ugly number --- ugly numbers | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ugly numbers diff --git a/ugly numbers b/ugly numbers new file mode 100644 index 00000000..11656cf1 --- /dev/null +++ b/ugly numbers @@ -0,0 +1,38 @@ +# include +# include + +int main() +{ +int n,x=0; + printf("Input an integer number: "); + scanf("%d",&n); + + if (n <= 0) { + printf("Input a correct number."); + } + while (n != 1) + { + if (n % 5 == 0) + { + n /= 5; + } + else if (n % 3 == 0) + { + n /= 3; + } + else if (n % 2 == 0) + { + n /= 2; + } + else + { + printf("It is not an ugly number.\n"); + x = 1; + break; + } + } + if (x==0) + { + printf("It is an ugly number.\n"); + } +} From 0905909bfa0d571b804c21fe0d54f7ba4b2d90c4 Mon Sep 17 00:00:00 2001 From: Vipinkumar24 <68346071+Vipinkumar24@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:46:43 +0530 Subject: [PATCH 030/394] C Program:- Leap Year A program to find leap year. --- Leap year | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Leap year diff --git a/Leap year b/Leap year new file mode 100644 index 00000000..18e38f36 --- /dev/null +++ b/Leap year @@ -0,0 +1,32 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + + else { + printf("%d is not a leap year.", year); + } + + return 0; +} +Output 1 + +Enter a year: 1900 +1900 is not a leap year. +Output 2 + +Enter a year: 2012 +2012 is a leap year. From 07c6348fa1c550923975f0c72e64c38c74a4db3e Mon Sep 17 00:00:00 2001 From: yashwant128 <72217097+yashwant128@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:55:32 +0530 Subject: [PATCH 031/394] Smaller number Smaller number in c programming language. --- Smaller number | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Smaller number diff --git a/Smaller number b/Smaller number new file mode 100644 index 00000000..edb632bf --- /dev/null +++ b/Smaller number @@ -0,0 +1,29 @@ +#include +int main() +{ + int a[10], Size, i, Smallest, Position; + + printf("\nPlease Enter the size of an array \n"); + scanf("%d",&Size); + + printf("\nPlease Enter %d elements of an array: \n", Size); + for(i=0; i a[i]) + { + Smallest = a[i]; + Position = i; + } + } + + printf("\nSmallest element in an Array = %d", Smallest); + printf("\nIndex position of the Smallest element = %d", Position); + + return 0; +} From fa3e245b64ce16af34d4ba6c50a818dc5f573095 Mon Sep 17 00:00:00 2001 From: HarshCoder08 <72196322+HarshCoder08@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:57:20 +0530 Subject: [PATCH 032/394] Create QuadraticRoots.c --- QuadraticRoots.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 QuadraticRoots.c diff --git a/QuadraticRoots.c b/QuadraticRoots.c new file mode 100644 index 00000000..5941be24 --- /dev/null +++ b/QuadraticRoots.c @@ -0,0 +1,35 @@ +#include +#include +using namespace std; + +int main() { + + float a, b, c, x1, x2, discriminant, realPart, imaginaryPart; + cout << "Enter coefficients a, b and c: "; + cin >> a >> b >> c; + discriminant = b*b - 4*a*c; + + if (discriminant > 0) { + x1 = (-b + sqrt(discriminant)) / (2*a); + x2 = (-b - sqrt(discriminant)) / (2*a); + cout << "Roots are real and different." << endl; + cout << "x1 = " << x1 << endl; + cout << "x2 = " << x2 << endl; + } + + else if (discriminant == 0) { + cout << "Roots are real and same." << endl; + x1 = (-b + sqrt(discriminant)) / (2*a); + cout << "x1 = x2 =" << x1 << endl; + } + + else { + realPart = -b/(2*a); + imaginaryPart =sqrt(-discriminant)/(2*a); + cout << "Roots are complex and different." << endl; + cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl; + cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl; + } + + return 0; +} From d4d85a1b991903f40c8ee86aea8a140764ce13d9 Mon Sep 17 00:00:00 2001 From: Prabhujeet <70204150+Prabhujeet@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:57:31 +0530 Subject: [PATCH 033/394] Create multiplication of 2 matrix Propose multiplication of two matrix --- multiplication of 2 matrix | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 multiplication of 2 matrix diff --git a/multiplication of 2 matrix b/multiplication of 2 matrix new file mode 100644 index 00000000..def03f7b --- /dev/null +++ b/multiplication of 2 matrix @@ -0,0 +1,82 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} From d9d46f7d2e2d7c0d8f3eb8cde5938769d85a844c Mon Sep 17 00:00:00 2001 From: gouryash <72168475+gouryash@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:58:12 +0530 Subject: [PATCH 034/394] revere number to reverse a number in c prograam --- reverse number | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 reverse number diff --git a/reverse number b/reverse number new file mode 100644 index 00000000..2555af0a --- /dev/null +++ b/reverse number @@ -0,0 +1,13 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + printf("Reversed number = %d", rev); + return 0; +} From 2065955cd27476464595616056241aca104843ae Mon Sep 17 00:00:00 2001 From: anchalmehta567 <49950601+anchalmehta567@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:59:49 +0530 Subject: [PATCH 035/394] Array Create an Array in C --- Array | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Array diff --git a/Array b/Array new file mode 100644 index 00000000..a328ddc9 --- /dev/null +++ b/Array @@ -0,0 +1,22 @@ +// Program to take 5 values from the user and store them in an array +// Print the elements stored in the array +#include + +int main() { + int values[5]; + + printf("Enter 5 integers: "); + + // taking input and storing it in an array + for(int i = 0; i < 5; ++i) { + scanf("%d", &values[i]); + } + + printf("Displaying integers: "); + + // printing elements of an array + for(int i = 0; i < 5; ++i) { + printf("%d\n", values[i]); + } + return 0; +} From 5b87d4306325ef112ae6588da2a2ef84a1dcc75d Mon Sep 17 00:00:00 2001 From: whitedevil9499 <65546942+whitedevil9499@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:01:26 +0530 Subject: [PATCH 036/394] greater_two_number largest of two number use C Programming --- greater_two_number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 greater_two_number diff --git a/greater_two_number b/greater_two_number new file mode 100644 index 00000000..236349e4 --- /dev/null +++ b/greater_two_number @@ -0,0 +1,16 @@ +#include +int main() +{ + +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} From 944c8e1020275625a2c5c52d6816507a0e6ee9c3 Mon Sep 17 00:00:00 2001 From: Chetan0308 <72188892+Chetan0308@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:15:34 +0530 Subject: [PATCH 037/394] Binary_Search Program to Search an elements in a given list using Binary Search. --- Binary_Search | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Binary_Search diff --git a/Binary_Search b/Binary_Search new file mode 100644 index 00000000..60e81e81 --- /dev/null +++ b/Binary_Search @@ -0,0 +1,40 @@ +#include +int binarySearch(int[], int, int, int); +void main () +{ + int arr[10] = {16, 19, 20, 23, 45, 56, 78, 90, 96, 100}; + int item, location=-1; + printf("Enter the item which you want to search "); + scanf("%d",&item); + location = binarySearch(arr, 0, 9, item); + if(location != -1) + { + printf("Item found at location %d",location); + } + else + { + printf("Item not found"); + } +} +int binarySearch(int a[], int beg, int end, int item) +{ + int mid; + if(end >= beg) + { + mid = (beg + end)/2; + if(a[mid] == item) + { + return mid+1; + } + else if(a[mid] < item) + { + return binarySearch(a,mid+1,end,item); + } + else + { + return binarySearch(a,beg,mid-1,item); + } + + } + return -1; +} From 2c566695d5890ad8296da1b1beb0bd67410ea1fa Mon Sep 17 00:00:00 2001 From: vandana-kotnala <72218336+vandana-kotnala@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:16:34 +0530 Subject: [PATCH 038/394] Create SMALLNO how to select a very small number (approximately 0) in a C code --- SMALLNO | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 SMALLNO diff --git a/SMALLNO b/SMALLNO new file mode 100644 index 00000000..b9fa1ddd --- /dev/null +++ b/SMALLNO @@ -0,0 +1,6 @@ +#define DELTA 1e-11 +.... + +if (abs(b-a) <= DELTA) { + (expression); +} From db6f323cf30e827b4b45453d8f848f56c57a9795 Mon Sep 17 00:00:00 2001 From: Pridhik ck <53297091+predhik@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:17:07 +0530 Subject: [PATCH 039/394] Create Fibonachi series To display fibonachi series --- Fibonachi series | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Fibonachi series diff --git a/Fibonachi series b/Fibonachi series new file mode 100644 index 00000000..145518c7 --- /dev/null +++ b/Fibonachi series @@ -0,0 +1,25 @@ +#include +int main() +{ + int count, first_term = 0, second_term = 1, next_term, i; + + //Ask user to input number of terms + printf("Enter the number of terms:\n"); + scanf("%d",&count); + + printf("First %d terms of Fibonacci series:\n",count); + for ( i = 0 ; i < count ; i++ ) + { + if ( i <= 1 ) + next_term = i; + else + { + next_term = first_term + second_term; + first_term = second_term; + second_term = next_term; + } + printf("%d\n",next_term); + } + + return 0; +} From 3ff14def0ce3763ed993925e578ac006beccb251 Mon Sep 17 00:00:00 2001 From: himanisingh528 <72160495+himanisingh528@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:17:48 +0530 Subject: [PATCH 040/394] Create greater of two number --- greater of two number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 greater of two number diff --git a/greater of two number b/greater of two number new file mode 100644 index 00000000..73c31935 --- /dev/null +++ b/greater of two number @@ -0,0 +1,15 @@ +#include +#include +int main() +{ + int a, b, big; + printf("Enter any two number: "); + scanf("%d%d", &a, &b); + if(a>b) + big=a; + else + big=b; + printf("\nBiggest of the two number is: %d", big); + getch(); + return 0; +} From 9a24dfead72c33769b0081d3c171c0fb75597ddf Mon Sep 17 00:00:00 2001 From: AryaHubGit <72212917+AryaHubGit@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:18:11 +0530 Subject: [PATCH 041/394] Create program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers. Developed by Arya Chakraborty --- ...ether there are two or three equal numbers | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers diff --git a/program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers b/program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers new file mode 100644 index 00000000..18327fe7 --- /dev/null +++ b/program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers @@ -0,0 +1,65 @@ + ++1 + +#include +using namespace std; + +// main function +int main(){ + + //create object and read the value and store it + double a,b,c,d; + cout<<"Enter number A: "; + cin>>a; + cout<<"Enter number B: "; + cin>>b; + cout<<"Enter number C: "; + cin>>c; + cout<<"Enter number D: "; + cin>>d; + cout< b && a > c && a > d) + { + cout<<"A is the greatest = "<a && b>c && b>d) + {cout<<"B is the greatest = "<a && c>b && c>d) + {cout<<"C is the greatest = "<a && d>b && d>c) + {cout<<"D is the greatest = "< Date: Thu, 1 Oct 2020 22:31:28 +0530 Subject: [PATCH 043/394] triangular patterns this helps to create a triangular pattern --- triangular patterns | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 triangular patterns diff --git a/triangular patterns b/triangular patterns new file mode 100644 index 00000000..70a1a944 --- /dev/null +++ b/triangular patterns @@ -0,0 +1,13 @@ +#include +int main() { + int i, j, rows; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 1; i <= rows; ++i) { + for (j = 1; j <= i; ++j) { + printf("* "); + } + printf("\n"); + } + return 0; +} From 2e4bb31dde935760eda72a8eb27d22668baa35d2 Mon Sep 17 00:00:00 2001 From: Krishna-Hegde <57755916+Krishna-Hegde@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:34:36 +0530 Subject: [PATCH 044/394] reversestr Program to reverse a string --- reversestr | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 reversestr diff --git a/reversestr b/reversestr new file mode 100644 index 00000000..32d4267f --- /dev/null +++ b/reversestr @@ -0,0 +1,16 @@ +#include +#include +int main() +{ + char s[100]; + + printf("Enter a string to reverse\n"); + gets(s); + + strrev(s); + + printf("Reverse of the string: %s\n", s); + + return 0; +} + From 149a4f01ee81e024a0b6137387459f302a1ad944 Mon Sep 17 00:00:00 2001 From: Mohd97 <53707412+Mohd97@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:39:09 +0530 Subject: [PATCH 045/394] maxinarray Program to maximum in an array --- maxinarray | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 maxinarray diff --git a/maxinarray b/maxinarray new file mode 100644 index 00000000..49ffb980 --- /dev/null +++ b/maxinarray @@ -0,0 +1,35 @@ +#include + +using namespace std; + +#define SIZE 50 //Defining max size of array + +int main() + +{ + int array[SIZE]; + int i, max, min, size; + // Input size of the array + cout<<"Enter size of the array: "; + cin>>size; + // Input array elements + cout<<"\n Enter "<>array[i]; + // Assume first element as maximum + max = array[0]; + + //Find maximum in all array elements. + for(i=1; i max) + max = array[i]; + + } + // Print maximum element + cout<<"\nMaximum element =" << max << "\n"; + + return 0; + +} From a4decc899debbc4840bff54ea3db974ac0169e89 Mon Sep 17 00:00:00 2001 From: ishikagoel5628 <47469060+ishikagoel5628@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:39:17 +0530 Subject: [PATCH 046/394] string task The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: deletes all the vowels, inserts a character "." before each consonant,replaces all uppercase consonants with corresponding lowercase ones. Vowels are letters "A", "O", "Y", "E", "U", "I", and the rest are consonants. --- string task | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 string task diff --git a/string task b/string task new file mode 100644 index 00000000..d06baad0 --- /dev/null +++ b/string task @@ -0,0 +1,20 @@ +#include +#include + int main() + { + int i,l; + char s[101]; + scanf("%s",s); + l=strlen(s); + for(i=0; i Date: Thu, 1 Oct 2020 22:46:49 +0530 Subject: [PATCH 047/394] bignumber Program to find the greatest of two numbers and greatest of three numbers --- bignumber | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 bignumber diff --git a/bignumber b/bignumber new file mode 100644 index 00000000..e2a39f2e --- /dev/null +++ b/bignumber @@ -0,0 +1,16 @@ +#include +int main() +{ +//Fill the code +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} From 8de52f8091a939a2212680651910a7fa800b67fc Mon Sep 17 00:00:00 2001 From: SSYT0035 <72152460+SSYT0035@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:51:29 +0530 Subject: [PATCH 048/394] Create addtwodistance.c initial commit --- addtwodistance.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 addtwodistance.c diff --git a/addtwodistance.c b/addtwodistance.c new file mode 100644 index 00000000..401af0d4 --- /dev/null +++ b/addtwodistance.c @@ -0,0 +1,38 @@ +// Program to add two distances (feet-inch) +#include +struct Distance +{ + int feet; + float inch; +} dist1, dist2, sum; + +int main() +{ + printf("1st distance\n"); + printf("Enter feet: "); + scanf("%d", &dist1.feet); + + printf("Enter inch: "); + scanf("%f", &dist1.inch); + printf("2nd distance\n"); + + printf("Enter feet: "); + scanf("%d", &dist2.feet); + + printf("Enter inch: "); + scanf("%f", &dist2.inch); + + // adding feet + sum.feet = dist1.feet + dist2.feet; + // adding inches + sum.inch = dist1.inch + dist2.inch; + + // changing to feet if inch is greater than 12 + while (sum.inch >= 12) + { + ++sum.feet; + sum.inch = sum.inch - 12; + } + + printf("Sum of distances = %d\'-%.1f\"", sum.feet, sum.inch); + return 0; From 927033df2c93b84792bf0f87097bf7b24235d948 Mon Sep 17 00:00:00 2001 From: ruchishrivastavatava <72220397+ruchishrivastavatava@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:53:51 +0530 Subject: [PATCH 049/394] swaptwonumber --- swaptwonumber | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 swaptwonumber diff --git a/swaptwonumber b/swaptwonumber new file mode 100644 index 00000000..5c7f9e45 --- /dev/null +++ b/swaptwonumber @@ -0,0 +1,21 @@ +#include +int main() { + double first, second, temp; + printf("Enter first number: "); + scanf("%lf", &first); + printf("Enter second number: "); + scanf("%lf", &second); + + // Value of first is assigned to temp + temp = first; + + // Value of second is assigned to first + first = second; + + // Value of temp (initial value of first) is assigned to second + second = temp; + + printf("\nAfter swapping, firstNumber = %.2lf\n", first); + printf("After swapping, secondNumber = %.2lf", second); + return 0; +} From bc6d19072055fc3315c996cc9a170ebcfe0d57b2 Mon Sep 17 00:00:00 2001 From: codeitbijay <72221165+codeitbijay@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:00:03 +0530 Subject: [PATCH 050/394] Create Check Armstrong number of n digits Program to find Armstrong number of n digits --- Check Armstrong number of n digits | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Check Armstrong number of n digits diff --git a/Check Armstrong number of n digits b/Check Armstrong number of n digits new file mode 100644 index 00000000..8d0605c7 --- /dev/null +++ b/Check Armstrong number of n digits @@ -0,0 +1,36 @@ + + + + +Check Armstrong Number of n digits +#include +#include + +int main() { + int num, originalNum, remainder, n = 0; + float result = 0.0; + + printf("Enter an integer: "); + scanf("%d", &num); + + originalNum = num; + + // store the number of digits of num in n + for (originalNum = num; originalNum != 0; ++n) { + originalNum /= 10; + } + + for (originalNum = num; originalNum != 0; originalNum /= 10) { + remainder = originalNum % 10; + + // store the sum of the power of individual digits in result + result += pow(remainder, n); + } + + // if num is equal to result, the number is an Armstrong number + if ((int)result == num) + printf("%d is an Armstrong number.", num); + else + printf("%d is not an Armstrong number.", num); + return 0; +} From 1d9d30ed7737d864fe08ee7899a568a034c9513c Mon Sep 17 00:00:00 2001 From: CJ077 <72221231+CJ077@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:01:24 +0530 Subject: [PATCH 051/394] Fibanocci_series A legend way to calculate fibanoci series --- fibanocci_series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibanocci_series diff --git a/fibanocci_series b/fibanocci_series new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/fibanocci_series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From b73fad28a7d2def56bc7d916b9378dbcbfc5d11d Mon Sep 17 00:00:00 2001 From: Kishan Biswakarma <34888085+amkishan@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:02:16 +0530 Subject: [PATCH 052/394] Create BitsSwap --- BitsSwap | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 BitsSwap diff --git a/BitsSwap b/BitsSwap new file mode 100644 index 00000000..40649690 --- /dev/null +++ b/BitsSwap @@ -0,0 +1,29 @@ + + +#include + +int swapBits(unsigned int x, unsigned int p1, unsigned int p2, unsigned int n) +{ + + unsigned int set1 = (x >> p1) & ((1U << n) - 1); + + unsigned int set2 = (x >> p2) & ((1U << n) - 1); + + + unsigned int xor = (set1 ^ set2); + + xor = (xor << p1) | (xor << p2); + + + unsigned int result = x ^ xor; + + return result; +} + + +int main() +{ + int res = swapBits(28, 0, 3, 2); + printf("\nResult = %d ", res); + return 0; +} From 26d6da955580406edb2eed0ff3f05d0ef7f75a51 Mon Sep 17 00:00:00 2001 From: Pritam Singha Roy <69103489+PritamSinghaRoy@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:06:24 +0530 Subject: [PATCH 053/394] bubble sorting --- bubble sorting | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bubble sorting diff --git a/bubble sorting b/bubble sorting new file mode 100644 index 00000000..a491d8db --- /dev/null +++ b/bubble sorting @@ -0,0 +1,32 @@ +#include + +int main(){ + + int count, temp, i, j, number[30]; + + printf("How many numbers are u going to enter?: "); + scanf("%d",&count); + + printf("Enter %d numbers: ",count); + + for(i=0;i=0;i--){ + for(j=0;j<=i;j++){ + if(number[j]>number[j+1]){ + temp=number[j]; + number[j]=number[j+1]; + number[j+1]=temp; + } + } + } + + printf("Sorted elements: "); + for(i=0;i Date: Thu, 1 Oct 2020 13:40:43 -0400 Subject: [PATCH 054/394] Create the hollow square star pattern --- the hollow square star pattern | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 the hollow square star pattern diff --git a/the hollow square star pattern b/the hollow square star pattern new file mode 100644 index 00000000..f6bd1e9b --- /dev/null +++ b/the hollow square star pattern @@ -0,0 +1,21 @@ +int main() +{ + int n; + printf("Enter the number of rows"); + scanf("%d",&n); + for(int i=1;i<=n;i++) + { + for(int j=1;j<=n;j++) + { + if(i==1 ||i==n||j==1||j==n) + { + printf("*"); + } + else + printf(" "); + } + printf("\n"); + } + + return 0; +} From 648a4f49cc3b2574913a4b89066fe29fdc5fccb9 Mon Sep 17 00:00:00 2001 From: beBhavyhere <52847477+Bhavykapadiya@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:18:35 +0530 Subject: [PATCH 055/394] Create Memory-management-in-c Program for Dynamic Memory Allocation using malloc(). --- Memory-management-in-c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Memory-management-in-c diff --git a/Memory-management-in-c b/Memory-management-in-c new file mode 100644 index 00000000..962e549b --- /dev/null +++ b/Memory-management-in-c @@ -0,0 +1,43 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + int n, i, *ptr, sum = 0; + + printf("\n\nEnter number of elements: "); + scanf("%d", &n); + + // dynamic memory allocation using malloc() + ptr = (int *) malloc(n*sizeof(int)); + + if(ptr == NULL) // if empty array + { + printf("\n\nError! Memory not allocated\n"); + return 0; // end of program + } + + printf("\n\nEnter elements of array: \n\n"); + for(i = 0; i < n; i++) + { + // storing elements at contiguous memory locations + scanf("%d", ptr+i); + sum = sum + *(ptr + i); + } + + // printing the array elements using pointer to the location + printf("\n\nThe elements of the array are: "); + for(i = 0; i < n; i++) + { + printf("%d ",ptr[i]); // ptr[i] is same as *(ptr + i) + } + + /* + freeing memory of ptr allocated by malloc + using the free() method + */ + free(ptr); + + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From 372b535fd6d8388cbb90bc058dc69408229e4a8f Mon Sep 17 00:00:00 2001 From: Ravindra3837 Date: Thu, 1 Oct 2020 23:29:34 +0530 Subject: [PATCH 056/394] febonacii number --- fibonacci | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibonacci diff --git a/fibonacci b/fibonacci new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/fibonacci @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 17d662e7ef1f83cd326be38d0137dffd23f2eaab Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Thu, 1 Oct 2020 23:35:11 +0530 Subject: [PATCH 057/394] Swapping two Numbers using a Temporary Variable --- Swapping two Numbers | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Swapping two Numbers diff --git a/Swapping two Numbers b/Swapping two Numbers new file mode 100644 index 00000000..0977acb5 --- /dev/null +++ b/Swapping two Numbers @@ -0,0 +1,14 @@ +Swapping two Numbers using a Temporary Variable + +#include +#include + +void main() +{ + int x = 10, y = 15, temp; + temp = x; + x = y; + y = temp; + printf("x = %d and y = %d", x, y); + getch(); +} From 26007009549a20c3dff822d450fa0fe0f7488b19 Mon Sep 17 00:00:00 2001 From: Ayushtripathy <55572895+Ayushtripathy@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:40:15 +0530 Subject: [PATCH 058/394] Create Stock_Span C++ Program For Stock Span --- Stock_Span | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Stock_Span diff --git a/Stock_Span b/Stock_Span new file mode 100644 index 00000000..f4d07e9c --- /dev/null +++ b/Stock_Span @@ -0,0 +1,29 @@ +#include +int* stockSpan(int *price, int size) { + // Write your code here + stack st; + st.push(0); + int *S=new int[size]; + // Span value of first element + S[0] = 1; + // Span values for rest of the elements + for (int i = 1; i < size; i++){ + while (!st.empty() && price[st.top()] < price[i]) + st.pop(); + + if(st.empty()){ + S[i] = i + 1; + } + else{ + S[i] = i - st.top(); + } + + // Push this element to stack + st.push(i); + } + return S; + +} + + + From 86803a22f225eec24fc7ef0d5edf2a793ea18df7 Mon Sep 17 00:00:00 2001 From: SunilBhadu <72160705+SunilBhadu@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:43:07 +0530 Subject: [PATCH 059/394] m%n remainder Program to get remainder 1 when N divides M . When two integers, say M and N are given. --- m%n remainder 1.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 m%n remainder 1.c diff --git a/m%n remainder 1.c b/m%n remainder 1.c new file mode 100644 index 00000000..e35522e2 --- /dev/null +++ b/m%n remainder 1.c @@ -0,0 +1,31 @@ +#include + + + +void main() + +{ + + int m,n; + + scanf("%d",&m); + + scanf("%d",&n); + + + + int rem = m%n; //% is used to find the remainder. + + + + if(rem==1) + + printf("1"); + + else + + printf("0"); + + + +} From 3de5b831861806f41f97bcd2b23185ed11162e90 Mon Sep 17 00:00:00 2001 From: Aman momin <67426740+momin786786@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:54:54 +0530 Subject: [PATCH 060/394] Smallest Number program to find smallest of two numbers in c --- Smallest | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Smallest diff --git a/Smallest b/Smallest new file mode 100644 index 00000000..ce10094c --- /dev/null +++ b/Smallest @@ -0,0 +1,38 @@ +#include + + +int main(void) +{ + + int num1,num2; + + printf("Enter two numbers:"); + scanf("%d %d",&num1,&num2); + + if(num1 Date: Thu, 1 Oct 2020 23:55:07 +0530 Subject: [PATCH 061/394] Copy String Without Using strcpy() C Program to Copy String Without Using strcpy() --- Copy String Without Using strcpy() | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Copy String Without Using strcpy() diff --git a/Copy String Without Using strcpy() b/Copy String Without Using strcpy() new file mode 100644 index 00000000..398acf7d --- /dev/null +++ b/Copy String Without Using strcpy() @@ -0,0 +1,14 @@ +#include +int main() { + char s1[100], s2[100], i; + printf("Enter string s1: "); + fgets(s1, sizeof(s1), stdin); + + for (i = 0; s1[i] != '\0'; ++i) { + s2[i] = s1[i]; + } + + s2[i] = '\0'; + printf("String s2: %s", s2); + return 0; +} From c6ff0282bcbc60b11397e20653f2a78dbe21b96d Mon Sep 17 00:00:00 2001 From: Vikas <72224550+Vikas09718@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:14:29 +0530 Subject: [PATCH 062/394] find prime numbers in a given range Upon execution of below program, the user would be asked to provide the from & to range and then the program would display all the prime numbers in sequential manner for the provided range. Using this program you can find out the prime numbers between 1 to 100, 100 to 999 etc. You just need to input the range, for e.g. if you want the prime numbers from 100 to 999 then enter numbers 100 and 999 when program prompts for input. --- find prime numbers in a given range | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 find prime numbers in a given range diff --git a/find prime numbers in a given range b/find prime numbers in a given range new file mode 100644 index 00000000..0dec61ad --- /dev/null +++ b/find prime numbers in a given range @@ -0,0 +1,30 @@ +#include +int main() +{ + int num1, num2, flag_var, i, j; + + /* Ask user to input the from/to range + * like 1 to 100, 10 to 1000 etc. + */ + printf("Enter two range(input integer numbers only):"); + //Store the range in variables using scanf + scanf("%d %d", &num1, &num2); + + //Display prime numbers for input range + printf("Prime numbers from %d and %d are:\n", num1, num2); + for(i=num1+1; i Date: Fri, 2 Oct 2020 00:16:14 +0530 Subject: [PATCH 063/394] Program to Convert Binary Number to Decimal Number This program converts binary number to equivalent decimal number. --- Convert Binary Number to Decimal Number | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Convert Binary Number to Decimal Number diff --git a/Convert Binary Number to Decimal Number b/Convert Binary Number to Decimal Number new file mode 100644 index 00000000..0fcc79c6 --- /dev/null +++ b/Convert Binary Number to Decimal Number @@ -0,0 +1,24 @@ +#include +#include +int binaryToDecimal(long binarynum) +{ + int decimalnum = 0, temp = 0, remainder; + while (binarynum!=0) + { + remainder = binarynum % 10; + binarynum = binarynum / 10; + decimalnum = decimalnum + remainder*pow(2,temp); + temp++; + } + return decimalnum; +} + +int main() +{ + long binarynum; + printf("Enter a binary number: "); + scanf("%ld", &binarynum); + + printf("Equivalent decimal number is: %d", binaryToDecimal(binarynum)); + return 0; +} From 9fe8d7c2fe5e9d3aac14c073fa13f785f1348c39 Mon Sep 17 00:00:00 2001 From: Madhu0299 <69695602+Madhu0299@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:18:46 +0530 Subject: [PATCH 064/394] Quick Sort Implementing Quick Sort algorithm --- Quick Sort | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Quick Sort diff --git a/Quick Sort b/Quick Sort new file mode 100644 index 00000000..b5b4638d --- /dev/null +++ b/Quick Sort @@ -0,0 +1,48 @@ +#include +void quicksort(int number[25],int first,int last){ + int i, j, pivot, temp; + + if(firstnumber[pivot]) + j--; + if(i Date: Fri, 2 Oct 2020 00:32:20 +0530 Subject: [PATCH 065/394] Create shutdown_using_c program to shutdown os(linux) using c --- shutdown_using_c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 shutdown_using_c diff --git a/shutdown_using_c b/shutdown_using_c new file mode 100644 index 00000000..d8b95254 --- /dev/null +++ b/shutdown_using_c @@ -0,0 +1,11 @@ +// C program to shutdown in Linux +#include +#include + +int main() +{ + // Running Linux OS command using system + system("shutdown -P now"); + + return 0; +} From 7c8e9cd3b45c6daf6b40e331bc892122ad2bc9d7 Mon Sep 17 00:00:00 2001 From: sameergceian <72225981+sameergceian@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:37:00 +0530 Subject: [PATCH 066/394] Create Gcd of any number using recursion in c --- Gcd of any number using recursion in c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Gcd of any number using recursion in c diff --git a/Gcd of any number using recursion in c b/Gcd of any number using recursion in c new file mode 100644 index 00000000..154c5f2b --- /dev/null +++ b/Gcd of any number using recursion in c @@ -0,0 +1,29 @@ +#include +int GetGCD(int temp1,int temp2); +main() +{ +int num1,num2,gcd,lcm,x; +printf("Enter number 1 and number 2\n"); +scanf("%d%d",&num1,&num2); +gcd=GetGCD(num1,num2); +lcm=(num1*num2)/gcd; +printf("gcd is %d\n",gcd); +printf("Lcm is %d\n",lcm); + +} +int GetGCD(int temp1,int temp2) +{ + if(temp2!=0) +{ + GetGCD(temp2,temp1%temp2); + +} + else +{ + return(temp1); + +} + +} + + From 041fc4f63f2c3cfa7f519bb99658ef03a1627b50 Mon Sep 17 00:00:00 2001 From: Shyam-123456 <72213963+Shyam-123456@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:09:25 +0700 Subject: [PATCH 067/394] substrect of two integers programe of substrect of two integer in c language --- substrect of two integers | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 substrect of two integers diff --git a/substrect of two integers b/substrect of two integers new file mode 100644 index 00000000..135a5f94 --- /dev/null +++ b/substrect of two integers @@ -0,0 +1,20 @@ +#include + +int main() +{ + int a,b,sub; + + //Read value of a + printf("Enter the first no.: "); + scanf("%d",&a); + + //Read value of b + printf("Enter the second no.: "); + scanf("%d",&b); + + //formula of subtraction + sub= a-b; + printf("subtract is = %d\n", sub); + + return 0; +} From 32c45f885bc7d00a32abd32feaf5badeec3f4dee Mon Sep 17 00:00:00 2001 From: Shyam-123456 <72213963+Shyam-123456@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:30:06 +0700 Subject: [PATCH 068/394] multiplication programe of multiplication of 2.12 and 3.88 --- multiplication of 2.12 and 3.88 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 multiplication of 2.12 and 3.88 diff --git a/multiplication of 2.12 and 3.88 b/multiplication of 2.12 and 3.88 new file mode 100644 index 00000000..b264583c --- /dev/null +++ b/multiplication of 2.12 and 3.88 @@ -0,0 +1,21 @@ +#include + +int main() +{ + float A, B, product = 0.0f; + + // Ask user to enter the two numbers + printf("Enter two floating numbers A and B : \n"); + + // Read two numbers from the user || A = 2.12, B = 3.88 + scanf("%f%f", &A, &B); + + // Calclulate the multiplication of A and B + // using '*' operator + product = A * B; + + // Print the product + printf("Product of A and B is: %f", product); + + return 0; +} From 276c89f78ce234cb636edbb8cc5ad15381be65eb Mon Sep 17 00:00:00 2001 From: tanishq502arora <44315955+tanishq502arora@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:01:31 +0530 Subject: [PATCH 069/394] Program to Find Roots of a Quadratic Equation The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and c are real numbers and a != 0 The term b2-4ac is known as the discriminant of a quadratic equation. It tells the nature of the roots. If the discriminant is greater than 0, the roots are real and different. If the discriminant is equal to 0, the roots are real and equal. If the discriminant is less than 0, the roots are complex and different. --- Roots of a Quadratic Equation | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Roots of a Quadratic Equation diff --git a/Roots of a Quadratic Equation b/Roots of a Quadratic Equation new file mode 100644 index 00000000..8430b53f --- /dev/null +++ b/Roots of a Quadratic Equation @@ -0,0 +1,31 @@ +#include +#include +int main() { + double a, b, c, discriminant, root1, root2, realPart, imagPart; + printf("Enter coefficients a, b and c: "); + scanf("%lf %lf %lf", &a, &b, &c); + + discriminant = b * b - 4 * a * c; + + // condition for real and different roots + if (discriminant > 0) { + root1 = (-b + sqrt(discriminant)) / (2 * a); + root2 = (-b - sqrt(discriminant)) / (2 * a); + printf("root1 = %.2lf and root2 = %.2lf", root1, root2); + } + + // condition for real and equal roots + else if (discriminant == 0) { + root1 = root2 = -b / (2 * a); + printf("root1 = root2 = %.2lf;", root1); + } + + // if roots are not real + else { + realPart = -b / (2 * a); + imagPart = sqrt(-discriminant) / (2 * a); + printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart); + } + + return 0; +} From 1b7a6bfbbde91065ba931be7bb1960125f6cd71f Mon Sep 17 00:00:00 2001 From: VighneshManjrekar <69366251+VighneshManjrekar@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:04:38 +0530 Subject: [PATCH 070/394] Create Armstrong.c --- Armstrong.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Armstrong.c diff --git a/Armstrong.c b/Armstrong.c new file mode 100644 index 00000000..12d5f697 --- /dev/null +++ b/Armstrong.c @@ -0,0 +1,24 @@ +#include +int main() { + int num, originalNum, remainder, result = 0; + printf("Enter a three-digit integer: "); + scanf("%d", &num); + originalNum = num; + + while (originalNum != 0) { + // remainder contains the last digit + remainder = originalNum % 10; + + result += remainder * remainder * remainder; + + // removing last digit from the orignal number + originalNum /= 10; + } + + if (result == num) + printf("%d is an Armstrong number.", num); + else + printf("%d is not an Armstrong number.", num); + + return 0; +} From ad6c781b2334133d64fb295282bcc298321e690b Mon Sep 17 00:00:00 2001 From: Shyam-123456 <72213963+Shyam-123456@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:36:42 +0700 Subject: [PATCH 071/394] add multiply divide substrect in one programe one combine programe of add multiply divide and substrect in c language --- add multiply divide and substract | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 add multiply divide and substract diff --git a/add multiply divide and substract b/add multiply divide and substract new file mode 100644 index 00000000..7189cf76 --- /dev/null +++ b/add multiply divide and substract @@ -0,0 +1,21 @@ +#include +int main() +{ + int first, second, add, subtract, multiply; + float divide; + + printf("Enter two integers\n"); + scanf("%d%d", &first, &second); + + add = first + second; + subtract = first - second; + multiply = first * second; + divide = first / (float)second; //typecasting + + printf("Sum = %d\n", add); + printf("Difference = %d\n", subtract); + printf("Multiplication = %d\n", multiply); + printf("Division = %.2f\n", divide); + + return 0; +} From 64f3e1b31d1dcff6406184bd3e1b4fe87d0dbb38 Mon Sep 17 00:00:00 2001 From: Madhu2699 <72226843+Madhu2699@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:11:42 +0530 Subject: [PATCH 072/394] Hello World Write a program to print Hello World --- Hello, World | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Hello, World diff --git a/Hello, World b/Hello, World new file mode 100644 index 00000000..d4421d7d --- /dev/null +++ b/Hello, World @@ -0,0 +1,5 @@ +#include +int main(){ + printf("Hello, World"); + return 0; +} From 64110d6d54fa490818e5a4b7dc6dcd837af9df0f Mon Sep 17 00:00:00 2001 From: Musharraf Date: Fri, 2 Oct 2020 01:12:16 +0530 Subject: [PATCH 073/394] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8b137891..be34dd87 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1 @@ - +contribution From 9c1da88787ba80f64ae6b67f79d3a42a0df1a547 Mon Sep 17 00:00:00 2001 From: DeadilyVirus <56110392+DeadilyVirus@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:13:59 +0530 Subject: [PATCH 074/394] Circular Queue Implementation Circular Queue Implementation Using C --- qcircle.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 qcircle.c diff --git a/qcircle.c b/qcircle.c new file mode 100644 index 00000000..f3ba40d5 --- /dev/null +++ b/qcircle.c @@ -0,0 +1,96 @@ +#include +#define max 10 +int queue[max]; +int front, rear; +void createQueue() +{ + front = rear = -1; +} +void insert() +{ + int num; + printf("Please enter the number to be inserted :\n"); + scanf("%d", &num); + if((front==0 && rear==max-1) || (front == rear+1)) + printf("Queue is FULL\n"); + else + { + if((front == -1) && (rear == -1)) + front = rear = 0; + else if((rear == max-1) && (front != -1)) + rear = 0; + else + rear++; + queue[rear] = num; + } +} +void DELETE() +{ + if((front == -1) && (rear == -1)) + printf("Queue is EMPTY\n"); + else + { + printf("The deleted element is %d\n", queue[front]); + if(front == rear) + front = rear = -1; + else if(front == max-1) + { + front = 0; + } + else + front++; + } +} +void peek() +{ + if((front == -1) && (rear == -1)) + printf("Queue is EMPTY\n"); + else + printf("The element at the top is %d\n", queue[front]); +} +void display() +{ + int i; + if((front == -1) && (rear == -1)) + printf("Queue is EMPTY\n"); + else if(front < rear) + { + for(i=front; i<=rear; i++) + printf("%d\t", queue[i]); + printf("\n"); + } + else + { + for(i=front; i<=(max-1); i++) + printf("%d\t", queue[i]); + for(i=0; i<=rear; i++) + printf("%d\t", queue[i]); + printf("\n"); + } +} +void main() +{ + createQueue(); + int ch; + do + { + printf("\nPlease enter the choice\n"); + printf("1: INSERT\n2: DELETE\n3: PEEK\n4: DISPALY\n5: QUIT\n"); + scanf("%d", &ch); + switch(ch) + { + case 1: + insert(); + break; + case 2: + DELETE(); + break; + case 3: + peek(); + break; + case 4: + display(); + break; + } + }while(ch != 5); +} From 6a9105ed830f3e4a0bd10c079a85f0beac587cc1 Mon Sep 17 00:00:00 2001 From: DeadilyVirus <56110392+DeadilyVirus@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:15:49 +0530 Subject: [PATCH 075/394] Linear Queue Implementation Linear Queue Implementation Using C --- qlinear.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 qlinear.c diff --git a/qlinear.c b/qlinear.c new file mode 100644 index 00000000..8233c064 --- /dev/null +++ b/qlinear.c @@ -0,0 +1,75 @@ +#include +#define max 10 +int queue[max]; +int front, rear; +void createQueue() +{ + front = rear = -1; +} +void insert() +{ + int num; + printf("Please enter the number to be inserted :\n"); + scanf("%d", &num); + if(rear == max-1) + printf("Queue is FULL\n"); + else if((front == -1) && (rear == -1)) + front = rear = 0; + else + rear++; + queue[rear] = num; +} +void DELETE() +{ + if((front == -1) || (front > rear)) + printf("Queue is EMPTY\n"); + else + { + printf("The deleted element is %d\n", queue[front]); + front++; + } +} +void peek() +{ + if((front == -1) || (front > rear)) + printf("Queue is EMPTY\n"); + else + printf("The element at the top is %d\n", queue[front]); +} +void display() +{ + if((front == -1)||(front > rear)) + printf("Queue is EMPTY\n"); + else + { + int i; + for(i=front; i<=rear; i++) + printf("%d\t", queue[i]); + } +} +void main() +{ + createQueue(); + int ch; + do + { + printf("\nPlease enter the choice\n"); + printf("1: INSERT\n2: DELETE\n3: PEEK\n4: DISPALY\n5: QUIT\n"); + scanf("%d", &ch); + switch(ch) + { + case 1: + insert(); + break; + case 2: + DELETE(); + break; + case 3: + peek(); + break; + case 4: + display(); + break; + } + }while(ch != 5); +} From 8b21816139b50ab794359cbcd1a0c76d6e465dbb Mon Sep 17 00:00:00 2001 From: DeadilyVirus <56110392+DeadilyVirus@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:17:17 +0530 Subject: [PATCH 076/394] Create quick_sort Quick Sort Program --- quick_sort | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 quick_sort diff --git a/quick_sort b/quick_sort new file mode 100644 index 00000000..a27ad809 --- /dev/null +++ b/quick_sort @@ -0,0 +1,65 @@ +#include +#define size 10 +int a[size]; + +int partition(int beg, int end) +{ + int left, right, temp, loc, flag; + loc = left = beg; + right = end; + flag = 0; + while(flag != 1) + { + while((a[loc] <= a[right]) && (loc != right)) + right--; + if(loc == right) + flag = 1; + else if(a[loc] > a[right]) + { + temp = a[loc]; + a[loc] = a[right]; + a[right] = temp; + loc = right; + } + if(flag != 1) + { + while((a[loc] >= a[left]) && (loc != left)) + left--; + if(loc == left) + flag = 1; + else if(a[loc] < a[left]) + { + temp = a[loc]; + a[loc] = a[left]; + a[left] = temp; + loc = left; + } + } + } + return loc; +} + +void quick_sort(int beg, int end) +{ + int loc; + if(beg < end) + { + loc = partition(beg, end); + quick_sort(beg, loc-1); + quick_sort(loc+1, end); + } +} + +void main() +{ + int i, n; + printf("Plesae enter the total number of elements :\n"); + scanf("%d",&n); + printf("Please enter the elements of the array : \n"); + for(i=0; i Date: Fri, 2 Oct 2020 01:19:02 +0530 Subject: [PATCH 077/394] Create Fibonacci Series in C --- Fibonacci Series in C | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacci Series in C diff --git a/Fibonacci Series in C b/Fibonacci Series in C new file mode 100644 index 00000000..a1b526a1 --- /dev/null +++ b/Fibonacci Series in C @@ -0,0 +1,16 @@ +#include +int main() +{ + int n1=0,n2=1,n3,i,number; + printf("Enter the number of elements:"); + scanf("%d",&number); + printf("\n%d %d",n1,n2);//printing 0 and 1 + for(i=2;i Date: Fri, 2 Oct 2020 01:22:54 +0530 Subject: [PATCH 078/394] this code finds armstrong numbers using recursion this code written in c ,to find armstrong numbers using recursion. --- to find armstrong numbers using recursion | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 to find armstrong numbers using recursion diff --git a/to find armstrong numbers using recursion b/to find armstrong numbers using recursion new file mode 100644 index 00000000..aacfc8a5 --- /dev/null +++ b/to find armstrong numbers using recursion @@ -0,0 +1,35 @@ +#include +#include + +int main() +{ + int Number, Temp, Reminder, Times =0, Sum = 0; + + printf("\nPlease Enter number to Check for Armstrong \n"); + scanf("%d", &Number); + + //Helps to prevent altering the original value + Temp = Number; + while (Temp != 0) + { + Times = Times + 1; + Temp = Temp / 10; + } + + Temp = Number; + while( Temp > 0) + { + Reminder = Temp %10; + Sum = Sum + pow(Reminder, Times); + Temp = Temp /10; + } + + printf("\n Sum of entered number is = %d\n", Sum); + + if ( Number == Sum ) + printf("\n %d is Armstrong Number.\n", Number); + else + printf("\n %d is not a Armstrong Number.\n", Number); + + return 0; +} From 8e308d57da39aed6c14954cbd4a8b0aa8300aea8 Mon Sep 17 00:00:00 2001 From: Musharraf Date: Fri, 2 Oct 2020 01:23:14 +0530 Subject: [PATCH 079/394] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be34dd87..8b137891 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1 +1 @@ -contribution + From caa82763b076d6450a16ba6a764ff72f597954a5 Mon Sep 17 00:00:00 2001 From: hsantanu836 <72227749+hsantanu836@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:26:53 +0530 Subject: [PATCH 080/394] reverse_a_string In this program we reverse a string. --- reverse_a_string | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 reverse_a_string diff --git a/reverse_a_string b/reverse_a_string new file mode 100644 index 00000000..cce9f939 --- /dev/null +++ b/reverse_a_string @@ -0,0 +1,15 @@ +#include +#include +int main() +{ + char s[100]; + + printf("Enter a string to reverse\n"); + gets(s); + + strrev(s); + + printf("Reverse of the string: %s\n", s); + + return 0; +} From 132ac0e6a31e7c8efc1ce694832651d4a44cb8cc Mon Sep 17 00:00:00 2001 From: bbisht22 <72227738+bbisht22@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:27:59 +0530 Subject: [PATCH 081/394] Liquidity Ratio Number Programs to find the greatest 5 numbers in c --- Liquidityno | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Liquidityno diff --git a/Liquidityno b/Liquidityno new file mode 100644 index 00000000..5065bb81 --- /dev/null +++ b/Liquidityno @@ -0,0 +1,21 @@ +#include + int main() { + int a[10]; + int i; + int greatest; + printf("Enter ten values:"); + //Store 10 numbers in an array + for (i = 0; i < 10; i++) { + scanf("%d", &a[i]); + } + //Assume that a[0] is greatest + greatest = a[0]; + for (i = 0; i < 10; i++) { +if (a[i] > greatest) { +greatest = a[i]; + } + } + printf(" + Greatest of ten numbers is %d", greatest); + return 0; + } From 00e40cbe9568d3535293aaa193ef3d51240d0ca8 Mon Sep 17 00:00:00 2001 From: sharmasarthak26 <60601125+sharmasarthak26@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:33:22 +0530 Subject: [PATCH 082/394] Leap Year Program to Check Leap Year --- Leap Year | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Leap Year diff --git a/Leap Year b/Leap Year new file mode 100644 index 00000000..aa973bb8 --- /dev/null +++ b/Leap Year @@ -0,0 +1,27 @@ +#include +void main() + { int year; + printf("Enter a year: "); + scanf("%d", &year); + + // leap year if perfectly visible by 400 + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + // not a leap year if visible by 100 + // but not divisible by 400 + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + // leap year if not divisible by 100 + // but divisible by 4 + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + // all other years are not leap year + else { + printf("%d is not a leap year.", year); + } + + getch(); + } From 00224f894bc09209ec64626a51421fa58141a755 Mon Sep 17 00:00:00 2001 From: KUMAR SHUBHAM <68353145+pothhead@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:45:47 +0530 Subject: [PATCH 083/394] formulaForQuadilateral --- quadilateral formula | 144 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 quadilateral formula diff --git a/quadilateral formula b/quadilateral formula new file mode 100644 index 00000000..27d84d29 --- /dev/null +++ b/quadilateral formula @@ -0,0 +1,144 @@ +// C++ implementation of above approach +#include +using namespace std; + +struct Point // points +{ + int x; + int y; +}; + +// determines the orientation of points +int orientation(Point p, Point q, Point r) +{ + int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y); + + if (val == 0) + return 0; + return (val > 0) ? 1 : 2; +} + +// check whether the distinct line segments intersect +bool doIntersect(Point p1, Point q1, Point p2, Point q2) +{ + int o1 = orientation(p1, q1, p2); + int o2 = orientation(p1, q1, q2); + int o3 = orientation(p2, q2, p1); + int o4 = orientation(p2, q2, q1); + + if (o1 != o2 && o3 != o4) + return true; + + return false; +} + +// check if points overlap(similar) +bool similar(Point p1, Point p2) +{ + + // it is same, we are returning false because + // quadrilateral is not possible in this case + if (p1.x == p2.x && p1.y == p2.y) + return false; + + // it is not same, So there is a + // possibility of a quadrilateral + return true; +} + +// check for collinearity +bool collinear(Point p1, Point p2, Point p3) +{ + int x1 = p1.x, y1 = p1.y; + int x2 = p2.x, y2 = p2.y; + int x3 = p3.x, y3 = p3.y; + + // it is collinear, we are returning false + // because quadrilateral is not possible in this case + if ((y3 - y2) * (x2 - x1) == (y2 - y1) * (x3 - x2)) + return false; + + // it is not collinear, So there + // is a possibility of a quadrilateral + else + return true; +} + +int no_of_quads(Point p1, Point p2, Point p3, Point p4) +{ + // ** Checking for cases where no quadrilateral = 0 ** + + // check if any of the points are same + bool same = true; + same = same & similar(p1, p2); + same = same & similar(p1, p3); + same = same & similar(p1, p4); + same = same & similar(p2, p3); + same = same & similar(p2, p4); + same = same & similar(p3, p4); + + // similar points exist + if (same == false) + return 0; + + // check for collinearity + bool coll = true; + coll = coll & collinear(p1, p2, p3); + coll = coll & collinear(p1, p2, p4); + coll = coll & collinear(p1, p3, p4); + coll = coll & collinear(p2, p3, p4); + + // points are collinear + if (coll == false) + return 0; + + //** Checking for cases where no of quadrilaterals= 1 or 3 ** + + int check = 0; + + if (doIntersect(p1, p2, p3, p4)) + check = 1; + if (doIntersect(p1, p3, p2, p4)) + check = 1; + if (doIntersect(p1, p2, p4, p3)) + check = 1; + + if (check == 0) + return 3; + return 1; +} + +// Driver code +int main() +{ + struct Point p1, p2, p3, p4; + // A =(0, 9), B = (-1, 0), C = (5, -1), D=(5, 9) + p1.x = 0, p1.y = 9; + p2.x = -1, p2.y = 0; + p3.x = 5, p3.y = -1; + p4.x = 5, p4.y = 9; + cout << no_of_quads(p1, p2, p3, p4) << endl; + + // A=(0, 9), B=(-1, 0), C=(5, -1), D=(0, 3) + p1.x = 0, p1.y = 9; + p2.x = -1, p2.y = 0; + p3.x = 5, p3.y = -1; + p4.x = 0, p4.y = 3; + cout << no_of_quads(p1, p2, p3, p4) << endl; + + // A=(0, 9), B=(0, 10), C=(0, 11), D=(0, 12) + p1.x = 0, p1.y = 9; + p2.x = 0, p2.y = 10; + p3.x = 0, p3.y = 11; + p4.x = 0, p4.y = 12; + cout << no_of_quads(p1, p2, p3, p4) << endl; + + // A=(0, 9), B=(0, 9), C=(5, -1), D=(0, 3) + p1.x = 0, p1.y = 9; + p2.x = 0, p2.y = 9; + p3.x = 5, p3.y = -1; + p4.x = 0, p4.y = 3; + cout << no_of_quads(p1, p2, p3, p4) << endl; + + return 0; +} From 4a998f0b3920ae56815b28823abe0e624634db25 Mon Sep 17 00:00:00 2001 From: Md Shahriyar Al Mustakim Mitul <57193846+mitul3737@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:20:34 +0600 Subject: [PATCH 084/394] Bubble sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. It will show the output like: Sorted array: 11 12 22 25 34 64 90 --- Bubble Sort | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Bubble Sort diff --git a/Bubble Sort b/Bubble Sort new file mode 100644 index 00000000..ef2663e2 --- /dev/null +++ b/Bubble Sort @@ -0,0 +1,41 @@ +#include +using namespace std; + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +// A function to implement bubble sort +void bubbleSort(int arr[], int n) +{ + int i, j; + for (i = 0; i < n-1; i++) + + // Last i elements are already in place + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +/* Function to print an array */ +void printArray(int arr[], int size) +{ + int i; + for (i = 0; i < size; i++) + cout << arr[i] << " "; + cout << endl; +} + +// Driver code +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + cout<<"Sorted array: \n"; + printArray(arr, n); + return 0; +} From cac24d10eca4fd260476ab970790a6ae07e3518e Mon Sep 17 00:00:00 2001 From: Sau1506mya <65443588+Sau1506mya@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:07:45 +0530 Subject: [PATCH 085/394] selectionsort Program to implement selection sort in c. --- selectionsort | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 selectionsort diff --git a/selectionsort b/selectionsort new file mode 100644 index 00000000..14193c04 --- /dev/null +++ b/selectionsort @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +int main() { + + int n,i,j,min,c=0; + scanf("%d",&n); + int a[n]; + + for(i=1;i<=n;i++) + scanf("%d",&a[i]); + + for(i=1;i<=n-1;i++) + { + min = i; + for(j=i+1;j<=n;j++) + { + c++; + if (a[j] < a[min]) + { + min = j; + } + } + if(min!=i) + { + int temp=a[i]; + a[i]=a[min]; + a[min]=temp; + } + } + + for(i=1;i<=n;i++) + printf("%d ",a[i]); + printf("\n%d\n%d",c,n-1); + + return 0; +} From c640cf336f399d6b84270c9b1052968141b24fa7 Mon Sep 17 00:00:00 2001 From: Sau1506mya <65443588+Sau1506mya@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:10:25 +0530 Subject: [PATCH 086/394] quicksort_c Program to implement quick sort in c --- quicksort_c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 quicksort_c diff --git a/quicksort_c b/quicksort_c new file mode 100644 index 00000000..3c8aea20 --- /dev/null +++ b/quicksort_c @@ -0,0 +1,53 @@ +#include +void swap(int* a, int* b) +{ + int t = *a; + *a = *b; + *b = t; +} +int partition (int arr[], int low, int high) +{ + int pivot = arr[high]; + int i = (low - 1); + + for (int j = low; j <= high- 1; j++) + { + if (arr[j] < pivot) + { + i++; + swap(&arr[i], &arr[j]); + } + } + swap(&arr[i + 1], &arr[high]); + return (i + 1); +} +void quickSort(int arr[], int low, int high) +{ + if (low < high) + { + int pi = partition(arr, low, high); + quickSort(arr, low, pi - 1); + quickSort(arr, pi + 1, high); + } +} +void printArray(int arr[], int size) +{ + int i; + for (i=0; i < size; i++) + printf("%d ", arr[i]); + printf("\n"); +} +int main() +{ + int n; + scanf("%d",&n); + int arr[n]; + for (int i=0;i Date: Fri, 2 Oct 2020 02:12:38 +0530 Subject: [PATCH 087/394] heapsort Program to implement heap sort in c. --- heapsort | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 heapsort diff --git a/heapsort b/heapsort new file mode 100644 index 00000000..83d3d96e --- /dev/null +++ b/heapsort @@ -0,0 +1,48 @@ +#include + + void swap(int *a, int *b) { + int temp = *a; + *a = *b; + *b = temp; + } + + void heapify(int arr[], int n, int i) { + int largest = i; + int left = 2 * i + 1; + int right = 2 * i + 2; + + if (left < n && arr[left] > arr[largest]) + largest = left; + + if (right < n && arr[right] > arr[largest]) + largest = right; + if (largest != i) { + swap(&arr[i], &arr[largest]); + heapify(arr, n, largest); + } + } + void heapSort(int arr[], int n) { + for (int i = n / 2 - 1; i >= 0; i--) + heapify(arr, n, i); + for (int i = n - 1; i >= 0; i--) { + swap(&arr[0], &arr[i]); + heapify(arr, i, 0); + } + } + void printArray(int arr[], int n) { + for (int i = 0; i < n; ++i) + printf("%d ", arr[i]); + printf("\n"); + } + int main() { + int n; + scanf("%d",&n); + int arr[n]; + for(int i=0;i=0;i--) + heapify(arr,n,i); + printArray(arr, n); + heapSort(arr, n); + printArray(arr, n); + } From 3c84265c1ddc07df86f111558c7aba8c342fd590 Mon Sep 17 00:00:00 2001 From: Nancy <47886063+nv77Nancy@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:15:00 +0530 Subject: [PATCH 088/394] Create Binary_to_decimal_conversion This is a C program that converts a binary number into its equivalent decimal form. --- Binary_to_decimal_conversion | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Binary_to_decimal_conversion diff --git a/Binary_to_decimal_conversion b/Binary_to_decimal_conversion new file mode 100644 index 00000000..b1eefffd --- /dev/null +++ b/Binary_to_decimal_conversion @@ -0,0 +1,20 @@ +#include +#include + +int main() +{ + int decimalnum = 0, temp = 0, remainder; + long binarynum; + printf("Enter a binary number: "); + scanf("%ld", &binarynum); + while (binarynum!=0) + { + remainder = binarynum % 10; + binarynum = binarynum / 10; + decimalnum = decimalnum + remainder*pow(2,temp); + temp++; + } + + printf("Equivalent decimal number is: %d", decimalnum); + return 0; +} From dc6c38c2e1b89b2ad5e438f09e629a2b83bbd955 Mon Sep 17 00:00:00 2001 From: Sau1506mya <65443588+Sau1506mya@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:15:02 +0530 Subject: [PATCH 089/394] countingsort Program to implement counting sort in c. --- countingsort | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 countingsort diff --git a/countingsort b/countingsort new file mode 100644 index 00000000..32d25c01 --- /dev/null +++ b/countingsort @@ -0,0 +1,58 @@ +#include +#include + +#define WORD_SIZE 10 +#define POSITIONS 100 + +struct word { + int position; + char term[WORD_SIZE + 1]; +}; + +void counting_sort(char *sorted[], struct word words[], size_t size) { + int buckets[POSITIONS]; + int i; + + + for (i = 0; i < POSITIONS; i++) { + buckets[i] = 0; + } + + + for (i = 0; i < size; i++) { + buckets[words[i].position]++; + } + + + for (i = 1; i < POSITIONS; i++) { + buckets[i] += buckets[i - 1]; + } + + + for (i = size - 1; i >= 0; i--) { + sorted[--buckets[words[i].position]] = words[i].term; + } +} + +int main() { + int n, i, max; + char garbage[WORD_SIZE + 1]; + + scanf("%d", &n); + struct word words[n]; + char *sorted[n]; + + max = n / 2; + for (i = 0; i < max; i++) { + scanf("%d %10s", &words[i].position, garbage); + strcpy(words[i].term, "-"); + } + for (; i < n; i++) { + scanf("%d %10s", &words[i].position, words[i].term); + } + counting_sort(sorted, words, n); + for (i = 0; i < n; i++) { + printf("%s ", sorted[i]); + } + return 0; +} From 2b137a65932ebda803623ce8968bf8a491fe018b Mon Sep 17 00:00:00 2001 From: Pranav Garg <72160417+cheekudeveloper@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:22:02 +0530 Subject: [PATCH 090/394] sumno --- sumno | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sumno diff --git a/sumno b/sumno new file mode 100644 index 00000000..05f60192 --- /dev/null +++ b/sumno @@ -0,0 +1,14 @@ +#include + +int main() +{ + int a = 4; + float b = 8.5; + int c = 6; + + printf("the value of a is %d \n", a); + printf("the value of b is %f \n", b); + printf("sum of a and b is %f" , a + b); + + return 0; +} From e3702670c8e074cd446bb2729b2d227f0250835c Mon Sep 17 00:00:00 2001 From: shobhitdwivedi31 <72229114+shobhitdwivedi31@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:35:58 +0530 Subject: [PATCH 091/394] Electric Bill C Program to Calculate Electricity Bill --- Electric Bill | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Electric Bill diff --git a/Electric Bill b/Electric Bill new file mode 100644 index 00000000..772a5d9b --- /dev/null +++ b/Electric Bill @@ -0,0 +1,81 @@ +#include + +int main() +{ + int Units; + float Amount, Sur_Charge, Total_Amount; + + printf("\n Please Enter the Units that you Consumed : "); + scanf("%d", &Units); + + if (Units < 50) + { + Amount = Units * 2.60; + Sur_Charge = 25; + } + else if (Units <= 100) + { + // First Fifty Units charge is 130 (50 * 2.60) + // Next, we are removing those 50 units from total units + Amount = 130 + ((Units - 50 ) * 3.25); + Sur_Charge = 35; + } + else if (Units <= 200) + { + // First Fifty Units charge is 130, and 50 - 100 is 162.50 (50 * 3.25) + // Next, we are removing those 100 units from total units + Amount = 130 + 162.50 + ((Units - 100 ) * 5.26); + Sur_Charge = 45; + } + else + { + // First Fifty Units 130, 50 - 100 is 162.50, and 100 - 200 is 526 (100 * 5.65) + // Next, we are removing those 200 units from total units + Amount = 130 + 162.50 + 526 + ((Units - 200 ) * 7.75); + Sur_Charge = 55; + } + + Total_Amount = Amount + Sur_Charge; + printf("\n Electricity Bill = %.2f", Total_Amount); + + return 0; +} +{ + int Units; + float Amount, Sur_Charge, Total_Amount; + + printf("\n Please Enter the Units that you Consumed : "); + scanf("%d", &Units); + + if (Units < 50) + { + Amount = Units * 2.60; + Sur_Charge = 25; + } + else if (Units <= 100) + { + // First Fifty Units charge is 130 (50 * 2.60) + // Next, we are removing those 50 units from total units + Amount = 130 + ((Units - 50 ) * 3.25); + Sur_Charge = 35; + } + else if (Units <= 200) + { + // First Fifty Units charge is 130, and 50 - 100 is 162.50 (50 * 3.25) + // Next, we are removing those 100 units from total units + Amount = 130 + 162.50 + ((Units - 100 ) * 5.26); + Sur_Charge = 45; + } + else + { + // First Fifty Units 130, 50 - 100 is 162.50, and 100 - 200 is 526 (100 * 5.65) + // Next, we are removing those 200 units from total units + Amount = 130 + 162.50 + 526 + ((Units - 200 ) * 7.75); + Sur_Charge = 55; + } + + Total_Amount = Amount + Sur_Charge; + printf("\n Electricity Bill = %.2f", Total_Amount); + + return 0; +} From 83d2f3731b3da02ea0dcf15657b1a66804af457d Mon Sep 17 00:00:00 2001 From: technocrat1506 <72153157+technocrat1506@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:37:01 +0530 Subject: [PATCH 092/394] Funnystring Program to demonstrate the funny string problem in c. --- Funnystring | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Funnystring diff --git a/Funnystring b/Funnystring new file mode 100644 index 00000000..d50b20aa --- /dev/null +++ b/Funnystring @@ -0,0 +1,35 @@ +#include +#include +#include + +int main() +{ + int q,i,len; + char str[10000],r[10000]; + scanf("%d",&q); + while(q!=0) + { + scanf("%s",str); + len=strlen(str); + for (i = 0; i < len; i++) + { + r[i] = str[strlen(str) - i - 1]; + } + int flag=1; + for (i = 1; i < len; i++) + { + if (abs(r[i] - r[i-1]) != abs(str[i] - str[i-1])) + { + printf("Not Funny\n"); + flag=0; + break; + } + } + + if (flag==1) + printf("Funny\n"); + q--; + } + + return 0; +} From 6547661a94c656936d9900474673d0a2e5c2b7c8 Mon Sep 17 00:00:00 2001 From: Saumya2600 <72230641+Saumya2600@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:38:13 +0530 Subject: [PATCH 093/394] Create Fibonacci Sequence --- Fibonacci Sequence | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacci Sequence diff --git a/Fibonacci Sequence b/Fibonacci Sequence new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/Fibonacci Sequence @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From e66ea6c7e69cef561569d9584a09af8c18a4f1bf Mon Sep 17 00:00:00 2001 From: shobhitdwivedi31 <72229114+shobhitdwivedi31@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:40:13 +0530 Subject: [PATCH 094/394] LCM C Program to find LCM of Two Number --- LCM | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 LCM diff --git a/LCM b/LCM new file mode 100644 index 00000000..ccc2faf1 --- /dev/null +++ b/LCM @@ -0,0 +1,22 @@ +#include + +int main() +{ + int Num1, Num2, max_Value; + + printf("Please Enter two integer Values \n"); + scanf("%d %d", &Num1, &Num2); + + max_Value = (Num1 > Num2)? Num1 : Num2; + + while(1) //Alway True + { + if(max_Value % Num1 == 0 && max_Value % Num2 == 0) + { + printf("LCM of %d and %d = %d", Num1, Num2, max_Value); + break; + } + ++max_Value; + } + return 0; +} From 1a2df12b95e92ff094697dd49f0817c68c780b57 Mon Sep 17 00:00:00 2001 From: Mudrika09 <48450992+Mudrika09@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:42:27 +0530 Subject: [PATCH 095/394] Linked List implementation of Queue Menu-Driven Program implementing all the operations on Linked Queue --- Linked List implementation of Queue | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Linked List implementation of Queue diff --git a/Linked List implementation of Queue b/Linked List implementation of Queue new file mode 100644 index 00000000..b3622145 --- /dev/null +++ b/Linked List implementation of Queue @@ -0,0 +1,104 @@ +#include +#include +struct node +{ + int data; + struct node *next; +}; +struct node *front; +struct node *rear; +void insert(); +void delete(); +void display(); +void main () +{ + int choice; + while(choice != 4) + { + printf("\n*************************Main Menu*****************************\n"); + printf("\n=================================================================\n"); + printf("\n1.insert an element\n2.Delete an element\n3.Display the queue\n4.Exit\n"); + printf("\nEnter your choice ?"); + scanf("%d",& choice); + switch(choice) + { + case 1: + insert(); + break; + case 2: + delete(); + break; + case 3: + display(); + break; + case 4: + exit(0); + break; + default: + printf("\nEnter valid choice??\n"); + } + } +} +void insert() +{ + struct node *ptr; + int item; + + ptr = (struct node *) malloc (sizeof(struct node)); + if(ptr == NULL) + { + printf("\nOVERFLOW\n"); + return; + } + else + { + printf("\nEnter value?\n"); + scanf("%d",&item); + ptr -> data = item; + if(front == NULL) + { + front = ptr; + rear = ptr; + front -> next = NULL; + rear -> next = NULL; + } + else + { + rear -> next = ptr; + rear = ptr; + rear->next = NULL; + } + } +} +void delete () +{ + struct node *ptr; + if(front == NULL) + { + printf("\nUNDERFLOW\n"); + return; + } + else + { + ptr = front; + front = front -> next; + free(ptr); + } +} +void display() +{ + struct node *ptr; + ptr = front; + if(front == NULL) + { + printf("\nEmpty queue\n"); + } + else + { printf("\nprinting values .....\n"); + while(ptr != NULL) + { + printf("\n%d\n",ptr -> data); + ptr = ptr -> next; + } + } +} From 0b719eda1a7f01118ab214484d547d9d2d33ebc3 Mon Sep 17 00:00:00 2001 From: Prabhakar Kumar <72229192+PRABHAKAR159@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:43:40 +0530 Subject: [PATCH 096/394] Create Library management system using structures in C --- ...ry management system using structures in C | 291 ++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 Library management system using structures in C diff --git a/Library management system using structures in C b/Library management system using structures in C new file mode 100644 index 00000000..4a8a07b8 --- /dev/null +++ b/Library management system using structures in C @@ -0,0 +1,291 @@ +#include +#include +struct Book{ + int bookId; + char bookName[50]; + char author[50]; + int bookPrice; + int quantityInLibrary; + int quantityIssued ; +}; + +struct Member{ + int memberId; + char memberName[50]; + int memberFine; + int noOfBooksIssued; + int isMember; +}; + + +void displayDetailsOfAllMembers(struct Member members[] ,int noOfMembers) +{ + for(int i=0;i Date: Fri, 2 Oct 2020 02:56:37 +0530 Subject: [PATCH 097/394] Create Sort in Descending order lists the numbers in descending order --- Sort in Descending order | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sort in Descending order diff --git a/Sort in Descending order b/Sort in Descending order new file mode 100644 index 00000000..86796efb --- /dev/null +++ b/Sort in Descending order @@ -0,0 +1,34 @@ + #include + void main () + { + int number[30]; + + int i, j, a, n; + printf("Enter the value of N\n"); + scanf("%d", &n); + + printf("Enter the numbers \n"); + for (i = 0; i < n; ++i) + scanf("%d", &number[i]); + + for (i = 0; i < n; ++i) + { + for (j = i + 1; j < n; ++j) + { + if (number[i] < number[j]) + { + a = number[i]; + number[i] = number[j]; + number[j] = a; + } + } + } + + printf("The numbers arranged in descending order are given below\n"); + + for (i = 0; i < n; ++i) + { + printf("%d\n", number[i]); + } + + } From b6e364df984e31fac050127437fa43dacc8b4275 Mon Sep 17 00:00:00 2001 From: CR Poudyal Date: Fri, 2 Oct 2020 06:34:01 +0545 Subject: [PATCH 098/394] Stack Implementation Using C --- stack.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 stack.c diff --git a/stack.c b/stack.c new file mode 100644 index 00000000..300c9362 --- /dev/null +++ b/stack.c @@ -0,0 +1,71 @@ +#include + +int MAXSIZE = 8; +int stack[8]; +int top = -1; + +int isempty() { + + if(top == -1) + return 1; + else + return 0; +} + +int isfull() { + + if(top == MAXSIZE) + return 1; + else + return 0; +} + +int peek() { + return stack[top]; +} + +int pop() { + int data; + + if(!isempty()) { + data = stack[top]; + top = top - 1; + return data; + } else { + printf("Could not retrieve data, Stack is empty.\n"); + } +} + +int push(int data) { + + if(!isfull()) { + top = top + 1; + stack[top] = data; + } else { + printf("Could not insert data, Stack is full.\n"); + } +} + +int main() { + // push items on to the stack + push(5); + push(90); + push(12); + push(3); + push(1); + push(0); + + printf("Element at top of the stack: %d\n" ,peek()); + printf("Elements: \n"); + + // print stack data + while(!isempty()) { + int data = pop(); + printf("%d\n",data); + } + + printf("Stack full: %s\n" , isfull()?"true":"false"); //checking stack is full or not + printf("Stack empty: %s\n" , isempty()?"true":"false"); //checking stack is empty or not + + return 0; +} From b0faacd75ef91ffc4e28261e61bcae3479cff129 Mon Sep 17 00:00:00 2001 From: Sagarmatsagar321 <72236827+Sagarmatsagar321@users.noreply.github.com> Date: Fri, 2 Oct 2020 06:50:41 +0530 Subject: [PATCH 099/394] Create Find odd or even no Program to find odd or even no --- Find odd or even no | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Find odd or even no diff --git a/Find odd or even no b/Find odd or even no new file mode 100644 index 00000000..8a29813a --- /dev/null +++ b/Find odd or even no @@ -0,0 +1,20 @@ +/* Program to check whether the input integer number + * is even or odd using the modulus operator (%) + */ +#include +int main() +{ + // This variable is to store the input number + int num; + + printf("Enter an integer: "); + scanf("%d",&num); + + // Modulus (%) returns remainder + if ( num%2 == 0 ) + printf("%d is an even number", num); + else + printf("%d is an odd number", num); + + return 0; +} From ba852ab43f8970413bbe9f2e08863a8f81624fdf Mon Sep 17 00:00:00 2001 From: kanaujiavikash12 <72237397+kanaujiavikash12@users.noreply.github.com> Date: Fri, 2 Oct 2020 07:23:50 +0530 Subject: [PATCH 100/394] smallest number how to find smallest number in array c++ --- creatervikas | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 creatervikas diff --git a/creatervikas b/creatervikas new file mode 100644 index 00000000..8f466115 --- /dev/null +++ b/creatervikas @@ -0,0 +1,31 @@ +#include +using namespace std; +int findSmallestElement(int arr[], int n){ + /* We are assigning the first array element to + * the temp variable and then we are comparing + * all the array elements with the temp inside + * loop and if the element is smaller than temp + * then the temp value is replaced by that. This + * way we always have the smallest value in temp. + * Finally we are returning temp. + */ + int temp = arr[0]; + for(int i=0; iarr[i]) { + temp=arr[i]; + } + } + return temp; +} +int main() { + int n; + cout<<"Enter the size of array: "; + cin>>n; int arr[n-1]; + cout<<"Enter array elements: "; + for(int i=0; i>arr[i]; + } + int smallest = findSmallestElement(arr, n); + cout<<"Smallest Element is: "< Date: Fri, 2 Oct 2020 07:37:18 +0530 Subject: [PATCH 101/394] Create Tic tac toe --- Tic tac toe | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 Tic tac toe diff --git a/Tic tac toe b/Tic tac toe new file mode 100644 index 00000000..a2bbd5ab --- /dev/null +++ b/Tic tac toe @@ -0,0 +1,284 @@ +#include +#include +#include +#include + +int b[10] = {2,2,2,2,2,2,2,2,2,2}; +int t = 1,f = 0; +int p,c; + +void menu(); +void go(int n); +void start_game(); +void check_draw(); +void draw_board(); +void player_first(); +void put_X_O(char ch,int pos); +COORD coord= {0,0}; // this is global variable +//center of axis is set to the top left cornor of the screen +void gotoxy(int x,int y) +{ +coord.X=x; +coord.Y=y; +SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); +} + +void main() +{ +system("cls"); +menu(); +getch(); + +} + +void menu() +{ +int choice; +system("cls"); +printf("\n--------MENU--------"); +printf("\n1 : Play with X"); +printf("\n2 : Play with O"); +printf("\n3 : Exit"); +printf("\nEnter your choice:>"); +scanf("%d",&choice); +t = 1; +switch (choice) +{ +case 1: +p = 1; +c = 0; +player_first(); +break; +case 2: +p = 0; +c = 1; +start_game(); +break; +case 3: +exit(1); +default: +menu(); +} +} + +int make2() +{ +if(b[5] == 2) +return 5; +if(b[2] == 2) +return 2; +if(b[4] == 2) +return 4; +if(b[6] == 2) +return 6; +if(b[8] == 2) +return 8; +return 0; +} + +int make4() +{ +if(b[1] == 2) +return 1; +if(b[3] == 2) +return 3; +if(b[7] == 2) +return 7; +if(b[9] == 2) +return 9; +return 0; +} + +int posswin(int p) +{ +// p==1 then X p==0 then O +int i; +int check_val,pos; + +if(p == 1) + check_val = 18; +else + check_val = 50; + +i = 1; +while(i<=9)//row check +{ + if(b[i] * b[i+1] * b[i+2] == check_val) + { + if(b[i] == 2) + return i; + if(b[i+1] == 2) + return i+1; + if(b[i+2] == 2) + return i+2; + } + i+=3; +} + +i = 1; +while(i<=3)//column check +{ + if(b[i] * b[i+3] * b[i+6] == check_val) + { + if(b[i] == 2) + return i; + if(b[i+3] == 2) + return i+3; + if(b[i+6] == 2) + return i+6; + } + i++; +} + +if(b[1] * b[5] * b[9] == check_val) +{ + if(b[1] == 2) + return 1; + if(b[5] == 2) + return 5; + if(b[9] == 2) + return 9; +} + +if(b[3] * b[5] * b[7] == check_val) +{ + if(b[3] == 2) + return 3; + if(b[5] == 2) + return 5; + if(b[7] == 2) + return 7; +} +return 0; +} + +void go(int n) +{ +if(t % 2) +b[n] = 3; +else +b[n] = 5; +turn++; +} + +void player_first() +{ +int pos; + +check_draw(); +draw_board(); +gotoxy(30,18); +printf("Your Turn :> "); +scanf("%d",&pos); + +if(b[pos] != 2) + player_first(); + +if(pos == posswin(player)) +{ + go(pos); + draw_board(); + gotoxy(30,20); + //textcolor(128+RED); + printf("Player Wins"); + getch(); + exit(0); +} + +go(pos); +draw_board(); +start_game(); +} + +void start_game() +{ +// p==1 then X p==0 then O +if(posswin(c)) +{ +go(posswin(c)); +f = 1; +} +else if(posswin(p)) +go(posswin(p)); +else if(make2()) +go(make2()); +else +go(make4()); +draw_board(); + +if(f) +{ + gotoxy(30,20); + //textcolor(128+RED); + printf("Computer wins"); + getch(); +} +else + player_first(); +} + +void check_draw() +{ +if(turn > 9) +{ +gotoxy(30,20); +//textcolor(128+RED); +printf("Game Draw"); +getch(); +exit(0); +} +} + +void draw_board() +{ +int j; + +for(j=9; j<17; j++) +{ + gotoxy(35,j); + printf("| |"); +} +gotoxy(28,11); +printf("-----------------------"); +gotoxy(28,14); +printf("-----------------------"); + +for(j=1; j<10; j++) +{ + if(b[j] == 3) + put_X_O('X',j); + else if(b[j] == 5) + put_X_O('O',j); +} +} + +void put_X_O(char ch,int pos) +{ +int m; +int x = 31, y = 10; + +m = pos; + +if(m > 3) +{ + while(m > 3) + { + y += 3; + m -= 3; + } +} +if(pos % 3 == 0) + x += 16; +else +{ + pos %= 3; + pos--; + while(pos) + { + x+=8; + pos--; + } +} +gotoxy(x,y); +printf("%c",ch); +} From e9cf96d79ad617020a0362828ec9ca442ea231b6 Mon Sep 17 00:00:00 2001 From: Gautam-Jain123 <56504041+Gautam-Jain123@users.noreply.github.com> Date: Fri, 2 Oct 2020 07:40:30 +0530 Subject: [PATCH 102/394] Create Game --- Game | 530 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 530 insertions(+) create mode 100644 Game diff --git a/Game b/Game new file mode 100644 index 00000000..99940517 --- /dev/null +++ b/Game @@ -0,0 +1,530 @@ +#include +#include +#include +#include +#include +void show_record(); +void reset_score(); +void help(); +void edit_score(float , char []); +int main() +{ +int countr,r,r1,count,i,n; +float score; +char choice; +char playername[20]; +mainhome: +system("cls"); +printf("\t\t\tC PROGRAM QUIZ GAME\n"); +printf("\n\t\t________________________________________"); + + printf("\n\t\t\t WELCOME "); + printf("\n\t\t\t to "); + printf("\n\t\t\t THE GAME "); + printf("\n\t\t________________________________________"); + printf("\n\t\t________________________________________"); + printf("\n\t\t BECOME A MILLIONAIRE!!!!!!!!!!! ") ; + printf("\n\t\t________________________________________"); + printf("\n\t\t________________________________________"); + printf("\n\t\t > Press S to start the game"); + printf("\n\t\t > Press V to view the highest score "); + printf("\n\t\t > Press R to reset score"); + printf("\n\t\t > press H for help "); + printf("\n\t\t > press Q to quit "); + printf("\n\t\t________________________________________\n\n"); + choice=toupper(getch()); + if (choice=='V') +{ +show_record(); +goto mainhome; +} + else if (choice=='H') +{ +help();getch(); +goto mainhome; +} +else if (choice=='R') +{reset_score(); +getch(); +goto mainhome;} +else if (choice=='Q') +exit(1); +else if(choice=='S') +{ + system("cls"); + +printf("\n\n\n\n\n\n\n\n\n\n\t\t\tResister your name:"); + gets(playername); + +system("cls"); +printf("\n ------------------ Welcome %s to C Program Quiz Game --------------------------",playername); +printf("\n\n Here are some tips you might wanna know before playing:"); +printf("\n -------------------------------------------------------------------------"); +printf("\n >> There are 2 rounds in this Quiz Game,WARMUP ROUND & CHALLANGE ROUND"); +printf("\n >> In warmup round you will be asked a total of 3 questions to test your"); +printf("\n general knowledge. You are eligible to play the game if you give atleast 2"); +printf("\n right answers, otherwise you can't proceed further to the Challenge Round."); +printf("\n >> Your game starts with CHALLANGE ROUND. In this round you will be asked a"); +printf("\n total of 10 questions. Each right answer will be awarded $100,000!"); +printf("\n By this way you can win upto ONE MILLION cash prize!!!!!.........."); +printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the"); +printf("\n right option."); +printf("\n >> You will be asked questions continuously, till right answers are given"); +printf("\n >> No negative marking for wrong answers!"); +printf("\n\n\t!!!!!!!!!!!!! ALL THE BEST !!!!!!!!!!!!!"); +printf("\n\n\n Press Y to start the game!\n"); +printf("\n Press any other key to return to the main menu!"); +if (toupper(getch())=='Y') + { + goto home; + } +else + { + goto mainhome; + system("cls"); + } + + home: + system("cls"); + count=0; + for(i=1;i<=3;i++) + { +system("cls"); + r1=i; + + + switch(r1) + { + case 1: + printf("\n\nWhich of the following is a Palindrome number?"); + printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234"); + if (toupper(getch())=='C') + { + printf("\n\nCorrect!!!");count++; + getch(); + break; +} +else +{ +printf("\n\nWrong!!! The correct answer is C.23232"); +getch(); +break; +} + + case 2: + printf("\n\n\nThe country with the highest environmental performance index is..."); + printf("\n\nA.France\t\tB.Denmark\n\nC.Switzerland\t\tD.Finland"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");count++; + getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is C.Switzerland"); + getch(); + break;} + + case 3: + printf("\n\n\nWhich animal laughs like human being?"); + printf("\n\nA.Polar Bear\t\tB.Hyena\n\nC.Donkey\t\tD.Chimpanzee"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");count++; + getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.Hyena"); + getch(); + break;} + + case 4: + printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?"); + printf("\n\nA.Wayne Rooney\t\tB.Lucas Podolski\n\nC.Lionel Messi\t\tD.Christiano Ronaldo"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");count++; + getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski"); + getch(); + break;} + + case 5: + printf("\n\n\nWhich is the third highest mountain in the world?"); + printf("\n\nA.Mt. K2\t\tB.Mt. Kanchanjungha\n\nC.Mt. Makalu\t\tD.Mt. Kilimanjaro"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");count++; + getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.Mt. Kanchanjungha"); + getch(); + break;} + + case 6: + printf("\n\n\nWhat is the group of frogs known as?"); + printf("\n\nA.A traffic\t\tB.A toddler\n\nC.A police\t\tD.An Army"); + if (toupper(getch())=='D' ) + {printf("\n\nCorrect!!!");count++; + getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D.An Army"); + getch(); + break;}} + } + +if(count>=2) +{goto test;} +else +{ +system("cls"); +printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME"); +getch(); +goto mainhome; +} + test: + system("cls"); + printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername); + printf("\n\n\n\n\t!Press any key to Start the Game!"); + if(toupper(getch())=='p') + {goto game;} +game: +countr=0; +for(i=1;i<=10;i++) +{system("cls"); +r=i; + + switch(r) + { + case 1: + printf("\n\nWhat is the National Game of England?"); + printf("\n\nA.Football\t\tB.Basketball\n\nC.Cricket\t\tD.Baseball"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");countr++;getch(); + break;getch();} + else + {printf("\n\nWrong!!! The correct answer is C.Cricket");getch(); + goto score; + break;} + + case 2: + printf("\n\n\nStudy of Earthquake is called............,"); + printf("\n\nA.Seismology\t\tB.Cosmology\n\nC.Orology\t\tD.Etimology"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is A.Seismology");getch(); + goto score; + break; + } + + case 3: + printf("\n\n\nAmong the top 10 highest peaks in the world, how many lie in Nepal? "); + printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.9"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is C.8");getch(); + goto score; + break;} + + case 4: + printf("\n\n\nThe Laws of Electromagnetic Induction were given by?"); + printf("\n\nA.Faraday\t\tB.Tesla\n\nC.Maxwell\t\tD.Coulomb"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + { + printf("\n\nWrong!!! The correct answer is A.Faraday");getch(); + goto score; + break; + } + + case 5: + printf("\n\n\nIn what unit is electric power measured?"); + printf("\n\nA.Coulomb\t\tB.Watt\n\nC.Power\t\tD.Units"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");countr++;getch(); break;} + else + { + printf("\n\nWrong!!! The correct answer is B.Power"); + getch(); + goto score; + break; + } + + case 6: + printf("\n\n\nWhich element is found in Vitamin B12?"); + printf("\n\nA.Zinc\t\tB.Cobalt\n\nC.Calcium\t\tD.Iron"); + if (toupper(getch())=='B' ) + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.Cobalt");goto score; + getch(); + break;} + + case 7: + printf("\n\n\nWhat is the National Name of Japan?"); + printf("\n\nA.Polska\t\tB.Hellas\n\nC.Drukyul\t\tD.Nippon"); + if (toupper(getch())=='D') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D.Nippon");getch(); + goto score; + break;} + + case 8: + printf("\n\n\nHow many times a piece of paper can be folded at the most?"); + printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.Depends on the size of paper"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");countr++;getch(); break;} + else + {printf("\n\nWrong!!! The correct answer is B.7");getch(); + goto score; + break;} + + case 9: + printf("\n\n\nWhat is the capital of Denmark?"); + printf("\n\nA.Copenhagen\t\tB.Helsinki\n\nC.Ajax\t\tD.Galatasaray"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is A.Copenhagen");getch(); + goto score; + break;} + + case 10: + printf("\n\n\nWhich is the longest River in the world?"); + printf("\n\nA.Nile\t\tB.Koshi\n\nC.Ganga\t\tD.Amazon"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++;getch(); break;} + else + {printf("\n\nWrong!!! The correct answer is A.Nile");getch();break;goto score;} + + case 11: + printf("\n\n\nWhat is the color of the Black Box in aeroplanes?"); + printf("\n\nA.White\t\tB.Black\n\nC.Orange\t\tD.Red"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is C.Orange");getch(); + break;goto score;} + + case 12: + printf("\n\n\nWhich city is known at 'The City of Seven Hills'?"); + printf("\n\nA.Rome\t\tB.Vactican City\n\nC.Madrid\t\tD.Berlin"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is A.Rome");getch(); + break;goto score;} + + case 13: + printf("\n\n\nName the country where there no mosquitoes are found?"); + printf("\n\nA.Japan\t\tB.Italy\n\nC.Argentina\t\tD.France"); + if (toupper(getch())=='D') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D.France");getch(); + break;goto score;} + + case 14: + printf("\n\n\nWho is the author of 'Pulpasa Cafe'?"); + printf("\n\nA.Narayan Wagle\t\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\t\tD.Khagendra Sangraula"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");getch(); + break;goto score;} + + case 15: + printf("\n\n\nWhich Blood Group is known as the Universal Recipient?"); + printf("\n\nA.A\t\tB.AB\n\nC.B\t\tD.O"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");countr++;getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.AB");getch(); + goto score; + break;} + + case 16: + printf("\n\n\nWhat is the unit of measurement of distance between Stars?"); + printf("\n\nA.Light Year\t\tB.Coulomb\n\nC.Nautical Mile\t\tD.Kilometer"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++; getch(); + break; + } + else + {printf("\n\nWrong!!! The correct answer is A.Light Year");getch(); + goto score; + break;} + + + case 17: + printf("\n\n\nThe country famous for Samba Dance is........"); + printf("\n\nA.Brazil\t\tB.Venezuela\n\nC.Nigeria\t\tD.Bolivia"); + if (toupper(getch())=='A') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is A.Brazil");getch();goto score; + break;} + + case 18: + printf("\n\n\nWind speed is measure by__________?"); + printf("\n\nA.Lysimeter\t\tB.Air vane\n\nC.Hydrometer\t\tD.Anemometer\n\n"); + if (toupper(getch())=='D') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D.Anemometer");getch();goto score; + break;} + + case 19: + printf("\n\n\nWhich city in the world is popularly known as The City of Temple?"); + printf("\n\nA.Delhi\tB.Bhaktapur\n\nC.Kathmandu\tD.Agra\n\n"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is C.Kathmandu");getch();goto score; + break;} + + case 20: + printf("\n\n\nWhich hardware was used in the First Generation Computer?"); + printf("\n\nA.Transistor\t\tB.Valves\n\nC.I.C\t\tD.S.S.I"); + if (toupper(getch())=='B') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is B.Valves");getch();goto score; + break;} + + case 21: + printf("\n\n\nOzone plate is being destroyed regularly because of____ ?"); + printf("\n\nA.L.P.G\t\tB.Nitrogen\n\nC.Methane\t\tD. C.F.C"); + if (toupper(getch())=='D') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D. C.F.C");getch();goto score; + break;} + + case 22: + printf("\n\n\nWho won the Women's Australian Open Tennis in 2007?"); + printf("\n\nA.Martina Hingis\t\tB.Maria Sarapova\n\nC.Kim Clijster\t\tD.Serena Williams"); + if (toupper(getch())=='D') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is D.Serena Williams");getch();goto score; + break;} + + case 23: + printf("\n\n\nWhich film was awarded the Best Motion Picture at Oscar in 2010?"); + printf("\n\nA.The Secret in their Eyes\t\tB.Shutter Island\n\nC.The King's Speech\t\tD.The Reader"); + if (toupper(getch())=='C') + {printf("\n\nCorrect!!!");countr++; getch(); + break;} + else + {printf("\n\nWrong!!! The correct answer is C.The King's Speech");getch();goto score; + break;}}} +score: +system("cls"); +score=(float)countr*100000; +if(score>0.00 && score<1000000) +{ + printf("\n\n\t\t**************** CONGRATULATION *****************"); + printf("\n\t You won $%.2f",score);goto go;} + + else if(score==1000000.00) +{ + printf("\n\n\n \t\t**************** CONGRATULATION ****************"); + printf("\n\t\t\t\t YOU ARE A MILLIONAIRE!!!!!!!!!"); + printf("\n\t\t You won $%.2f",score); + printf("\t\t Thank You!!"); +} + else +{ +printf("\n\n\t******** SORRY YOU DIDN'T WIN ANY CASH ********"); +printf("\n\t\t Thanks for your participation"); +printf("\n\t\t TRY AGAIN");goto go;} + +go: +puts("\n\n Press Y if you want to play next game"); +puts(" Press any key if you want to go main menu"); +if (toupper(getch())=='Y') + goto home; +else + { + edit_score(score,playername); + goto mainhome;}}} +void show_record() +{system("cls"); +char name[20]; +float scr; +FILE f; +f=fopen("score.txt","r"); +fscanf(f,"%s%f",&name,&scr); +printf("\n\n\t\t************************************************************"); +printf("\n\n\t\t %s has secured the Highest Score %0.2f",name,scr); +printf("\n\n\t\t*************************************************************"); +fclose(f); +getch();} + +void reset_score() +{system("cls"); +float sc; +char nm[20]; +FILE *f; +f=fopen("score.txt","r+"); +fscanf(f,"%s%f",&nm,&sc); +sc=0; +fprintf(f,"%s,%.2f",nm,sc); +fclose(f);} + +void help() +{system("cls"); +printf("\n\n HELP"); +printf("\n -------------------------------------------------------------------------"); +printf("\n ......................... C program Quiz Game..........."); +printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLANGE ROUND"); +printf("\n >> In warmup round you will be asked a total of 3 questions to test your general"); +printf("\n knowledge. You will be eligible to play the game if you can give atleast 2"); +printf("\n right answers otherwise you can't play the Game..........."); +printf("\n >> Your game starts with the CHALLANGE ROUND. In this round you will be asked"); +printf("\n total 10 questions each right answer will be awarded $100,000."); +printf("\n By this way you can win upto ONE MILLION cash prize in USD..............."); +printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the"); +printf("\n right option"); +printf("\n >> You will be asked questions continuously if you keep giving the right answers."); +printf("\n >> No negative marking for wrong answers"); + +printf("\n\n\t*********************BEST OF LUCK*********************************"); +printf("\n\n\t*****C PROGRAM QUIZ GAME is developed by CODE WITH C TEAM********");} +void edit_score(float score, char plnm[20]) +{system("cls"); +float sc; +char nm[20]; +FILE *f; +f=fopen("score.txt","r"); +fscanf(f,"%s%f",&nm,&sc); +if (score>=sc) +{ sc=score; +fclose(f); +f=fopen("score.txt","w"); +fprintf(f,"%s\n%.2f",plnm,sc); +fclose(f);}} + + + From 4d01e0ebe09f3c391ca97a5827caa7d23eac57bf Mon Sep 17 00:00:00 2001 From: Gautam-Jain123 <56504041+Gautam-Jain123@users.noreply.github.com> Date: Fri, 2 Oct 2020 07:42:12 +0530 Subject: [PATCH 103/394] Create Calendar --- Calendar | 420 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 420 insertions(+) create mode 100644 Calendar diff --git a/Calendar b/Calendar new file mode 100644 index 00000000..68092c3b --- /dev/null +++ b/Calendar @@ -0,0 +1,420 @@ +#include +#include +#include +struct Date{ +int dd; +int mm; +int yy; +}; +struct Date date; + +struct Remainder{ +int dd; +int mm; +char note[50]; +}; +struct Remainder R; + +COORD xy = {0, 0}; + +void gotoxy (int x, int y) +{ +xy.X = x; xy.Y = y; // X and Y coordinates +SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy); +} + +//This will set the forground color for printing in a console window. +void SetColor(int ForgC) +{ +WORD wColor; +//We will need this handle to get the current background attribute +HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); +CONSOLE_SCREEN_BUFFER_INFO csbi; + + //We use csbi for the wAttributes word. + if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) + { + //Mask out all but the background attribute, and add in the forgournd color + wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); + SetConsoleTextAttribute(hStdOut, wColor); + } + return; +} + +void ClearColor(){ +SetColor(15); +} + +void ClearConsoleToColors(int ForgC, int BackC) +{ +WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F); +//Get the handle to the current output buffer... +HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); +//This is used to reset the carat/cursor to the top left. +COORD coord = {0, 0}; +//A return value... indicating how many chars were written +// not used but we need to capture this since it will be +// written anyway (passing NULL causes an access violation). +DWORD count; + + //This is a structure containing all of the console info + // it is used here to find the size of the console. + CONSOLE_SCREEN_BUFFER_INFO csbi; + //Here we will set the current color + SetConsoleTextAttribute(hStdOut, wColor); + if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) + { + //This fills the buffer with a given character (in this case 32=space). + FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count); + + FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count ); + //This will set our cursor position for the next print statement. + SetConsoleCursorPosition(hStdOut, coord); + } + return; +} + +void SetColorAndBackground(int ForgC, int BackC) +{ +WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);; +SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor); +return; +} + +int check_leapYear(int year){ //checks whether the year passed is leap year or not +if(year % 400 == 0 || (year % 100!=0 && year % 4 ==0)) +return 1; +return 0; +} + +void increase_month(int *mm, int *yy){ //increase the month by one +++*mm; +if(*mm > 12){ +++*yy; +*mm = *mm - 12; +} +} + +void decrease_month(int *mm, int *yy){ //decrease the month by one +--*mm; +if(*mm < 1){ +--*yy; +if(*yy<1600){ +printf("No record available"); +return; +} +*mm = *mm + 12; +} +} + +int getNumberOfDays(int month,int year){ //returns the number of days in given month +switch(month){ //and year +case 1 : return(31); +case 2 : if(check_leapYear(year)==1) +return(29); +else +return(28); +case 3 : return(31); +case 4 : return(30); +case 5 : return(31); +case 6 : return(30); +case 7 : return(31); +case 8 : return(31); +case 9 : return(30); +case 10: return(31); +case 11: return(30); +case 12: return(31); +default: return(-1); +} +} + +char *getName(int day){ //returns the name of the day +switch(day){ +case 0 :return("Sunday"); +case 1 :return("Monday"); +case 2 :return("Tuesday"); +case 3 :return("Wednesday"); +case 4 :return("Thursday"); +case 5 :return("Friday"); +case 6 :return("Saturday"); +default:return("Error in getName() module.Invalid argument passed"); +} +} + +void print_date(int mm, int yy){ //prints the name of month and year +printf("---------------------------\n"); +gotoxy(25,6); +switch(mm){ +case 1: printf("January"); break; +case 2: printf("February"); break; +case 3: printf("March"); break; +case 4: printf("April"); break; +case 5: printf("May"); break; +case 6: printf("June"); break; +case 7: printf("July"); break; +case 8: printf("August"); break; +case 9: printf("September"); break; +case 10: printf("October"); break; +case 11: printf("November"); break; +case 12: printf("December"); break; +} +printf(" , %d", yy); +gotoxy(20,7); +printf("---------------------------"); +} +int getDayNumber(int day,int mon,int year){ //retuns the day number +int res = 0, t1, t2, y = year; +year = year - 1600; +while(year >= 100){ +res = res + 5; +year = year - 100; +} +res = (res % 7); +t1 = ((year - 1) / 4); +t2 = (year-1)-t1; +t1 = (t1*2)+t2; +t1 = (t1%7); +res = res + t1; +res = res%7; +t2 = 0; +for(t1 = 1;t1 < mon; t1++){ +t2 += getNumberOfDays(t1,y); +} +t2 = t2 + day; +t2 = t2 % 7; +res = res + t2; +res = res % 7; +if(y > 2000) +res = res + 1; +res = res % 7; +return res; +} + +char *getDay(int dd,int mm,int yy){ +int day; +if(!(mm>=1 && mm<=12)){ +return("Invalid month value"); +} +if(!(dd>=1 && dd<=getNumberOfDays(mm,yy))){ +return("Invalid date"); +} +if(yy>=1600){ +day = getDayNumber(dd,mm,yy); +day = day%7; +return(getName(day)); +}else{ +return("Please give year more than 1600"); +} +} + +int checkNote(int dd, int mm){ +FILE *fp; +fp = fopen("note.dat","rb"); +if(fp == NULL){ +printf("Error in Opening the file"); +} +while(fread(&R,sizeof(R),1,fp) == 1){ +if(R.dd == dd && R.mm == mm){ +fclose(fp); +return 1; +} +} +fclose(fp); +return 0; +} + +void printMonth(int mon,int year,int x,int y){ //prints the month with all days +int nod, day, cnt, d = 1, x1 = x, y1 = y, isNote = 0; +if(!(mon>=1 && mon<=12)){ +printf("INVALID MONTH"); +getch(); +return; +} +if(!(year>=1600)){ +printf("INVALID YEAR"); +getch(); +return; +} +gotoxy(20,y); +print_date(mon,year); +y += 3; +gotoxy(x,y); +printf("S M T W T F S "); +y++; +nod = getNumberOfDays(mon,year); +day = getDayNumber(d,mon,year); +switch(day){ //locates the starting day in calender +case 0 : +x=x; +cnt=1; +break; +case 1 : +x=x+4; +cnt=2; +break; +case 2 : +x=x+8; +cnt=3; +break; +case 3 : +x=x+12; +cnt=4; +break; +case 4 : +x=x+16; +cnt=5; +break; +case 5 : +x=x+20; +cnt=6; +break; +case 6 : +x=x+24; +cnt=7; +break; +default : +printf("INVALID DATA FROM THE getOddNumber()MODULE"); +return; +} +gotoxy(x,y); +if(cnt == 1){ +SetColor(12); +} +if(checkNote(d,mon)==1){ +SetColorAndBackground(15,12); +} +printf("%02d",d); +SetColorAndBackground(15,1); +for(d=2;d<=nod;d++){ +if(cnt%7==0){ +y++; +cnt=0; +x=x1-4; +} +x = x+4; +cnt++; +gotoxy(x,y); +if(cnt==1){ +SetColor(12); +}else{ +ClearColor(); +} +if(checkNote(d,mon)==1){ +SetColorAndBackground(15,12); +} +printf("%02d",d); +SetColorAndBackground(15,1); +} +gotoxy(8, y+2); +SetColor(14); +printf("Press 'n' to Next, Press 'p' to Previous and 'q' to Quit"); +gotoxy(8,y+3); +printf("Red Background indicates the NOTE, Press 's' to see note: "); +ClearColor(); +} + +void AddNote(){ +FILE *fp; +fp = fopen("note.dat","ab+"); +system("cls"); +gotoxy(5,7); +printf("Enter the date(DD/MM): "); +scanf("%d%d",&R.dd, &R.mm); +gotoxy(5,8); +printf("Enter the Note(50 character max): "); +fflush(stdin); +scanf("%[^\n]",R.note); +if(fwrite(&R,sizeof(R),1,fp)){ +gotoxy(5,12); +puts("Note is saved sucessfully"); +fclose(fp); +}else{ +gotoxy(5,12); +SetColor(12); +puts("\aFail to save!!\a"); +ClearColor(); +} +gotoxy(5,15); +printf("Press any key............"); +getch(); +fclose(fp); +} + +void showNote(int mm){ +FILE *fp; +int i = 0, isFound = 0; +system("cls"); +fp = fopen("note.dat","rb"); +if(fp == NULL){ +printf("Error in opening the file"); +} +while(fread(&R,sizeof(R),1,fp) == 1){ +if(R.mm == mm){ +gotoxy(10,5+i); +printf("Note %d Day = %d: %s", i+1, R.dd, R.note); +isFound = 1; +i++; +} +} +if(isFound == 0){ +gotoxy(10,5); +printf("This Month contains no note"); +} +gotoxy(10,7+i); +printf("Press any key to back......."); +getch(); + +} + +int main(){ +ClearConsoleToColors(15, 1); +SetConsoleTitle("Calender Project - Programming-technique.blogspot.com"); +int choice; +char ch = 'a'; +while(1){ +system("cls"); +printf("1. Find Out the Day\n"); +printf("2. Print all the day of month\n"); +printf("3. Add Note\n"); +printf("4. EXIT\n"); +printf("ENTER YOUR CHOICE : "); +scanf("%d",&choice); +system("cls"); +switch(choice){ +case 1: +printf("Enter date (DD MM YYYY) : "); +scanf("%d %d %d",&date.dd,&date.mm,&date.yy); +printf("Day is : %s",getDay(date.dd,date.mm,date.yy)); +printf("\nPress any key to continue......"); +getch(); +break; +case 2 : +printf("Enter month and year (MM YYYY) : "); +scanf("%d %d",&date.mm,&date.yy); +system("cls"); +while(ch!='q'){ +printMonth(date.mm,date.yy,20,5); +ch = getch(); +if(ch == 'n'){ +increase_month(&date.mm,&date.yy); +system("cls"); +printMonth(date.mm,date.yy,20,5); +}else if(ch == 'p'){ +decrease_month(&date.mm,&date.yy); +system("cls"); +printMonth(date.mm,date.yy,20,5); +}else if(ch == 's'){ +showNote(date.mm); +system("cls"); +} +} +break; +case 3: +AddNote(); +break; +case 4 : +exit(0); +} +} +return 0; +} From 52520b8a0793120fecb5a6c85057876202fe2b0c Mon Sep 17 00:00:00 2001 From: Akshith Vasa <55576223+akshith2426@users.noreply.github.com> Date: Fri, 2 Oct 2020 07:45:42 +0530 Subject: [PATCH 104/394] Create hash_on_eightbitnumber.c Simple Hash function implementation on 8 bits using XOR operation. --- hash_on_eightbitnumber.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 hash_on_eightbitnumber.c diff --git a/hash_on_eightbitnumber.c b/hash_on_eightbitnumber.c new file mode 100644 index 00000000..75af83b1 --- /dev/null +++ b/hash_on_eightbitnumber.c @@ -0,0 +1,20 @@ +#include +int main() +{ + char ch, input[9], s[9]; + int i, len=0; + + printf("Enter your input bits:"); + scanf("%s",input); + + printf("Enter your key S (8 bits):"); + scanf("%s",s); + + printf("Your hash code is:"); + for(i=0; i<8; i++) + { + ch=input[i]^s[i]; + printf("%d",ch); + } + return 0; +} From f4448be57f580a4fe1be1f14a95616e20561d788 Mon Sep 17 00:00:00 2001 From: chaitanyatekane <71593995+chaitanyatekane@users.noreply.github.com> Date: Fri, 2 Oct 2020 07:51:02 +0530 Subject: [PATCH 105/394] factorial using recursive function here we are finding factorial of any integer number using recursive function in c --- ...orial of a number using recursive function | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 c program to find factorial of a number using recursive function diff --git a/c program to find factorial of a number using recursive function b/c program to find factorial of a number using recursive function new file mode 100644 index 00000000..d1ef5265 --- /dev/null +++ b/c program to find factorial of a number using recursive function @@ -0,0 +1,20 @@ +#include +#include +void main() +{ + int no,factorial; + int fact(int no); + clrscr(); + printf("Enter a number: "); + scanf("%d",&no); + factorial=fact(no); + printf("Factorial=%d",factorial); + getch(); +} +int fact(int no) +{ + if(no==1) + return 1; + else + return(no*fact(no-1)); +} From 7749c9cc3ae2c4e01668451987b4e0259884fb80 Mon Sep 17 00:00:00 2001 From: keerthan1555 <71212313+keerthan1555@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:08:11 +0530 Subject: [PATCH 106/394] even or odd c program to find even or odd number --- odd or enen | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 odd or enen diff --git a/odd or enen b/odd or enen new file mode 100644 index 00000000..dbbc9a12 --- /dev/null +++ b/odd or enen @@ -0,0 +1,16 @@ +#include +int main () +{ +int n; +printf("enter the value of n\n"); +scanf("%d",&n); +if (n%d==0): +{ +printf("%d is enen ,n); +} + else + { + printf("%d is odd ,n); +} + return 0; + } From 2ff2ed2c09109dd16ede02f4b92f554acdc7bac5 Mon Sep 17 00:00:00 2001 From: Dhrupesh Pokiya <49096353+dapokiya@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:10:22 +0530 Subject: [PATCH 107/394] Celsius_To_Fahrenheit Program to convert temperature from Celsius to Fahrenheit --- celsius to fahrenheit | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 celsius to fahrenheit diff --git a/celsius to fahrenheit b/celsius to fahrenheit new file mode 100644 index 00000000..729795b7 --- /dev/null +++ b/celsius to fahrenheit @@ -0,0 +1,19 @@ +#include + +int main() +{ + float celsius, fahrenheit; + + /* Input temperature in celsius */ + printf("Enter temperature in Celsius: "); + scanf("%f", &celsius); + + /* celsius to fahrenheit conversion formula */ + fahrenheit = (celsius * 9 / 5) + 32; + + printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit); + + return + +0; +} From 29a8c5eb2b8b2f825f02942f54f52439c28eca9f Mon Sep 17 00:00:00 2001 From: param-dev <65339658+param-dev@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:18:42 +0530 Subject: [PATCH 108/394] Create concatenate str Concatenate Two Strings Without Using strcat() --- concatenate str | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 concatenate str diff --git a/concatenate str b/concatenate str new file mode 100644 index 00000000..f913a334 --- /dev/null +++ b/concatenate str @@ -0,0 +1,24 @@ +#include +int main() { + char s1[100] = "programming ", s2[] = "is awesome"; + int length, j; + + // store length of s1 in the length variable + length = 0; + while (s1[length] != '\0') { + ++length; + } + + // concatenate s2 to s1 + for (j = 0; s2[j] != '\0'; ++j, ++length) { + s1[length] = s2[j]; + } + + // terminating the s1 string + s1[length] = '\0'; + + printf("After concatenation: "); + puts(s1); + + return 0; +} From de6de0f4b943dd3622c118569264347c103f989d Mon Sep 17 00:00:00 2001 From: mathurapg <72239347+mathurapg@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:21:00 +0530 Subject: [PATCH 109/394] Create polynomial_equation_solver --- polynomial_equation_solver | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 polynomial_equation_solver diff --git a/polynomial_equation_solver b/polynomial_equation_solver new file mode 100644 index 00000000..67739849 --- /dev/null +++ b/polynomial_equation_solver @@ -0,0 +1,44 @@ +#include +#include + +float poly(float a[], int, float); + +int main() +{ + float x, a[10], y1; + int deg, i; + + printf("Enter the degree of polynomial equation: "); + scanf("%d", °); + + printf("Ehter the value of x for which the equation is to be evaluated: "); + scanf("%f", &x); + + for(i=0; i<=deg; i++) + { + printf("Enter the coefficient of x to the power %d: ",i); + scanf("%f",&a[i]); + } + + y1 = poly(a, deg, x); + + printf("The value of polynomial equation for the value of x = %.2f is: %.2f",x,y1); + + return 0; +} + +/* function for finding the value of polynomial at some value of x */ +float poly(float a[], int deg, float x) +{ + float p; + int i; + + p = a[deg]; + + for(i=deg;i>=1;i--) + { + p = (a[i-1] + x*p); + } + + return p; +} From c0f6ca373433f406105c8f9895618656fcbe3317 Mon Sep 17 00:00:00 2001 From: Coderash1998 <47770728+Coderash1998@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:22:12 +0530 Subject: [PATCH 110/394] Create sorting of arrays created this program --- sorting of arrays | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 sorting of arrays diff --git a/sorting of arrays b/sorting of arrays new file mode 100644 index 00000000..c9b39e85 --- /dev/null +++ b/sorting of arrays @@ -0,0 +1,52 @@ +#include + +void swap(int* xp, int* yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +// Function to perform Selection Sort +void selectionSort(int arr[], int n) +{ + int i, j, min_idx; + + // One by one move boundary of unsorted subarray + for (i = 0; i < n - 1; i++) { + + // Find the minimum element in unsorted array + min_idx = i; + for (j = i + 1; j < n; j++) + if (arr[j] < arr[min_idx]) + min_idx = j; + + // Swap the found minimum element + // with the first element + swap(&arr[min_idx], &arr[i]); + } +} + +// Function to print an array +void printArray(int arr[], int size) +{ + int i; + for (i = 0; i < size; i++) + printf("%d ", arr[i]); + printf("\n"); +} + +// Driver code +int main() +{ + int arr[] = { 0, 23, 14, 12, 9 }; + int n = sizeof(arr) / sizeof(arr[0]); + printf("Original array: \n"); + printArray(arr, n); + + selectionSort(arr, n); + printf("\nSorted array in Ascending order: \n"); + printArray(arr, n); + + return 0; +} From c4b512b3628b542ba69c3e3f8c21a5a8e8dc2a98 Mon Sep 17 00:00:00 2001 From: mathurapg <72239347+mathurapg@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:22:34 +0530 Subject: [PATCH 111/394] Create digital-clock --- digital-clock | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 digital-clock diff --git a/digital-clock b/digital-clock new file mode 100644 index 00000000..2f2b4b76 --- /dev/null +++ b/digital-clock @@ -0,0 +1,47 @@ +/*C program to design a digital clock.*/ + +#include +#include //for sleep() function +#include +#include + +int main() +{ + int hour, minute, second; + + hour=minute=second=0; + + while(1) + { + //clear output screen + system("clear"); + + //print time in HH : MM : SS format + printf("%02d : %02d : %02d ",hour,minute,second); + + //clear output buffer in gcc + fflush(stdout); + + //increase second + second++; + + //update hour, minute and second + if(second==60){ + minute+=1; + second=0; + } + if(minute==60){ + hour+=1; + minute=0; + } + if(hour==24){ + hour=0; + minute=0; + second=0; + } + + sleep(1); //wait till 1 second + } + + return 0; +} From c4395a8bcc8bbcd2fc2b24348482fbcf94c5d652 Mon Sep 17 00:00:00 2001 From: mathurapg <72239347+mathurapg@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:24:18 +0530 Subject: [PATCH 112/394] Create ipcheck_in_linux --- ipcheck_in_linux | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ipcheck_in_linux diff --git a/ipcheck_in_linux b/ipcheck_in_linux new file mode 100644 index 00000000..7e0dcd94 --- /dev/null +++ b/ipcheck_in_linux @@ -0,0 +1,42 @@ + +#include +#include +#include + +#include +#include +#include +#include +#include + +int main() +{ + unsigned char ip_address[15]; + int fd; + struct ifreq ifr; + + /*AF_INET - to define network interface IPv4*/ + /*Creating soket for it.*/ + fd = socket(AF_INET, SOCK_DGRAM, 0); + + /*AF_INET - to define IPv4 Address type.*/ + ifr.ifr_addr.sa_family = AF_INET; + + /*eth0 - define the ifr_name - port name + where network attached.*/ + memcpy(ifr.ifr_name, "eth0", IFNAMSIZ-1); + + /*Accessing network interface information by + passing address using ioctl.*/ + ioctl(fd, SIOCGIFADDR, &ifr); + /*closing fd*/ + close(fd); + + /*Extract IP Address*/ + strcpy(ip_address,inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + + printf("System IP Address is: %s\n",ip_address); + + return 0; +} +
From 4ccac2442e4388d99f2a224a081412abbd0349ac Mon Sep 17 00:00:00 2001 From: mathurapg <72239347+mathurapg@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:25:18 +0530 Subject: [PATCH 113/394] Create flying_character --- flying_character | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 flying_character diff --git a/flying_character b/flying_character new file mode 100644 index 00000000..db8b37f1 --- /dev/null +++ b/flying_character @@ -0,0 +1,75 @@ + +#include +#include +#include +#include + +/*will return character based on passed number*/ +char getCHAR(int n) +{ + char ok[]="~!@#$%^&*:;'\",{}|<>="; + return ok[n]; +} + +/*function to identify that any key hit by the keyboard*/ +int kbhit(void) +{ + struct termios oldt, newt; + int ch; + int oldf; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + if(ch != EOF) + { + ungetc(ch, stdin); + return 1; + } + + return 0; +} + +/*move cursor on specified position on screen*/ +void gotoxy(int x,int y) +{ +printf("%c[%d;%df",0x1B,y,x); +} + +int main(void) { + int x,y; + long int i,j; + i=j=0; + + x=1; y=20; + system("clear"); + + /*program will run until any key hit*/ + while(!kbhit()) + { + x=rand()%((150-1+1)+1); + y=rand()%((50-1+1)+1); + gotoxy(x,y); + printf("%c", getCHAR(rand()%((20-1+1)+1))); fflush(stdout); + ++i; + if(i==10000) {++j; i=0;} + if(j==100000){ i=0;} + if(j<=100) + usleep(30000); + if(j<=1000) + usleep(3000); + if(j<=10000) + usleep(300); + } + return 0; +} +
From a40e0fb7b3df22bf4df42bc2c101baa86f8c1e30 Mon Sep 17 00:00:00 2001 From: mathurapg <72239347+mathurapg@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:27:04 +0530 Subject: [PATCH 114/394] Create EMI_calculator --- EMI_calculator | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 EMI_calculator diff --git a/EMI_calculator b/EMI_calculator new file mode 100644 index 00000000..ba0d2e3b --- /dev/null +++ b/EMI_calculator @@ -0,0 +1,26 @@ +#include +#include + +int main() +{ + float principal, rate, time, emi; + + printf("Enter principal: "); + scanf("%f",&principal); + + printf("Enter rate: "); + scanf("%f",&rate); + + printf("Enter time in year: "); + scanf("%f",&time); + + rate=rate/(12*100); /*one month interest*/ + time=time*12; /*one month period*/ + + + emi= (principal*rate*pow(1+rate,time))/(pow(1+rate,time)-1); + + printf("Monthly EMI is= %f\n",emi); + + return 0; +} From 834c578e68ce719085502da2964e4d19001b340e Mon Sep 17 00:00:00 2001 From: param-dev <65339658+param-dev@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:29:49 +0530 Subject: [PATCH 115/394] Create sentence to a file C Program to Write a Sentence to a File --- sentence to a file | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 sentence to a file diff --git a/sentence to a file b/sentence to a file new file mode 100644 index 00000000..76be8c17 --- /dev/null +++ b/sentence to a file @@ -0,0 +1,23 @@ +#include +#include + +int main() { + char sentence[1000]; + + // creating file pointer to work with files + FILE *fptr; + + // opening file in writing mode + fptr = fopen("program.txt", "w"); + + // exiting program + if (fptr == NULL) { + printf("Error!"); + exit(1); + } + printf("Enter a sentence:\n"); + fgets(sentence, sizeof(sentence), stdin); + fprintf(fptr, "%s", sentence); + fclose(fptr); + return 0; +} From 71444cf583336dd7c4692e524f1d0dc6d8a5a2d5 Mon Sep 17 00:00:00 2001 From: Harsh Mendapara <35166367+harshh351998@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:36:39 +0530 Subject: [PATCH 116/394] Insertion sort c program Following C program asks from user to enter array size and array elements to sort that array using insertion sort technique. And finally display the sorted array on the screen. --- Insertion sort | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Insertion sort diff --git a/Insertion sort b/Insertion sort new file mode 100644 index 00000000..e8a6dbb0 --- /dev/null +++ b/Insertion sort @@ -0,0 +1,40 @@ +// Write a program in C that sorts any given array in Ascending order + + + +#include +#include +int main() +{ + int arr[50], size, i, j, k, element, index; + printf("Enter Array Size: "); + scanf("%d", &size); + printf("Enter %d Array Elements: ", size); + for(i=0; ij; k--) + arr[k] = arr[k-1]; + break; + } + } + } + else + continue; + arr[index] = element; + } + printf("\nSorted Array:\n"); + for(i=0; i Date: Fri, 2 Oct 2020 08:37:23 +0530 Subject: [PATCH 117/394] Biggest of three number C program to find the biggest of three numbers --- Biggest of three number | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Biggest of three number diff --git a/Biggest of three number b/Biggest of three number new file mode 100644 index 00000000..7b9bc949 --- /dev/null +++ b/Biggest of three number @@ -0,0 +1,25 @@ +#include + +void main() +{ + int num1, num2, num3; + + printf("Enter the values of num1, num2 and num3\n"); + scanf("%d %d %d", &num1, &num2, &num3); + printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3); + if (num1 > num2) + { + if (num1 > num3) + { + printf("num1 is the greatest among three \n"); + } + else + { + printf("num3 is the greatest among three \n"); + } + } + else if (num2 > num3) + printf("num2 is the greatest among three \n"); + else + printf("num3 is the greatest among three \n"); +} From 3d13897203be679a9860c1a4446f5da52757b2b0 Mon Sep 17 00:00:00 2001 From: Scarlett618 <70334720+Scarlett618@users.noreply.github.com> Date: Fri, 2 Oct 2020 08:53:41 +0530 Subject: [PATCH 118/394] Addfunction Program to add two numbers through a function. --- Addfunction | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Addfunction diff --git a/Addfunction b/Addfunction new file mode 100644 index 00000000..0fbdfec3 --- /dev/null +++ b/Addfunction @@ -0,0 +1,13 @@ +void add(int,int); +#include +int main(){ +int a,b; +printf("Enter two integers\n"); +scanf("%d %d",&a,&b); +add(a,b); +return 0; +} +void add(int x,int y){ +int sum=x+y; +printf("Sum of two numbers is %d",sum); +} From 055947cc4ae3b6bf46f8819e3ad2d42155a8fe06 Mon Sep 17 00:00:00 2001 From: Mohd Yasir Hussain Date: Fri, 2 Oct 2020 08:57:56 +0530 Subject: [PATCH 119/394] Check whether a Number is Palindrome Number or Not A program written in C --- Palindrome Number | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Palindrome Number diff --git a/Palindrome Number b/Palindrome Number new file mode 100644 index 00000000..615dc04f --- /dev/null +++ b/Palindrome Number @@ -0,0 +1,22 @@ +#include +int main() { + int n, reversedN = 0, remainder, originalN; + printf("Enter an integer: "); + scanf("%d", &n); + originalN = n; + + // reversed integer is stored in reversedN + while (n != 0) { + remainder = n % 10; + reversedN = reversedN * 10 + remainder; + n /= 10; + } + + // palindrome if orignalN and reversedN are equal + if (originalN == reversedN) + printf("%d is a palindrome.", originalN); + else + printf("%d is not a palindrome.", originalN); + + return 0; +} From 31f48ccbe719cc2e4d6e40523fe303f2c3ece821 Mon Sep 17 00:00:00 2001 From: royaashish <68891693+royaashish@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:01:19 +0530 Subject: [PATCH 120/394] Table You can find table of any number using this program. --- Table | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Table diff --git a/Table b/Table new file mode 100644 index 00000000..e48de691 --- /dev/null +++ b/Table @@ -0,0 +1,17 @@ +#include +#include +main() +{ + int n,end,i,mul; + printf("enter the number for which you want table:\n"); + scanf("%d",&n); + printf("enter the number till where \nyou want multiplication with %d :\n",n); + scanf("%d",&end); + printf("table of %d\n",n); + for(i=1;i<=end;i++) + { + mul=n*i; + printf("%d X %d = %d\n",n,i,mul); + } + getch(); +} From 493905bec9f8c06762bd8c60fc21816a565726ce Mon Sep 17 00:00:00 2001 From: dashingsaikat <48173982+dashingsaikat@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:11:44 +0530 Subject: [PATCH 121/394] graphicscarmove Program to move a car on a console of graphics by c programming with the cleardevice() method. --- graphicscarmove | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 graphicscarmove diff --git a/graphicscarmove b/graphicscarmove new file mode 100644 index 00000000..a139a2a9 --- /dev/null +++ b/graphicscarmove @@ -0,0 +1,58 @@ +#include +#include + +// Function to draw moving car +void draw_moving_car(void) { + + int i, j = 0, gd = DETECT, gm; + + initgraph(&gd, &gm, ""); + + for (i = 0; i <= 420; i = i + 10) { + + // Set color of car as red + setcolor(RED); + + line(0 + i, 300, 210 + i, 300); + line(50 + i, 300, 75 + i, 270); + line(75 + i, 270, 150 + i, 270); + line(150 + i, 270, 165 + i, 300); + line(0 + i, 300, 0 + i, 330); + line(210 + i, 300, 210 + i, 330); + + // For left wheel of car + circle(65 + i, 330, 15); + circle(65 + i, 330, 2); + + // For right wheel of car + circle(145 + i, 330, 15); + circle(145 + i, 330, 2); + + // Line left of left wheel + line(0 + i, 330, 50 + i, 330); + + // Line middle of both wheel + line(80 + i, 330, 130 + i, 330); + + // Line right of right wheel + line(210 + i, 330, 160 + i, 330); + + delay(100); + + // To erase previous drawn car + // use cleardevice() function + cleardevice(); + } + + getch(); + + closegraph(); +} + +// Driver code +int main() +{ + draw_moving_car(); + + return 0; +} From 2ff9278ebd4454f771a00d750de33a8a1a01de6f Mon Sep 17 00:00:00 2001 From: shivam9661 <49068772+shivam9661@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:25:24 +0530 Subject: [PATCH 122/394] Create Swapping of two number Swapping of two numbers --- Swapping of two number | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Swapping of two number diff --git a/Swapping of two number b/Swapping of two number new file mode 100644 index 00000000..5c7f9e45 --- /dev/null +++ b/Swapping of two number @@ -0,0 +1,21 @@ +#include +int main() { + double first, second, temp; + printf("Enter first number: "); + scanf("%lf", &first); + printf("Enter second number: "); + scanf("%lf", &second); + + // Value of first is assigned to temp + temp = first; + + // Value of second is assigned to first + first = second; + + // Value of temp (initial value of first) is assigned to second + second = temp; + + printf("\nAfter swapping, firstNumber = %.2lf\n", first); + printf("After swapping, secondNumber = %.2lf", second); + return 0; +} From 4a1dfe7a736905573ce0e76dbb5fab3a9e69ba26 Mon Sep 17 00:00:00 2001 From: Yashwantbisht <72188791+Yashwantbisht@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:30:12 +0530 Subject: [PATCH 123/394] Creat a calculator A calculator for adding , subtracting , multiplication and division --- Creat A Simple Calculator | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Creat A Simple Calculator diff --git a/Creat A Simple Calculator b/Creat A Simple Calculator new file mode 100644 index 00000000..080bede2 --- /dev/null +++ b/Creat A Simple Calculator @@ -0,0 +1,37 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} + + +OUTPUT + +Enter an operator (+, -, *,): * +Enter two operands: 1.5 +4.5 +1.5 * 4.5 = 6.8 From 05981c3104216361ce55317a2a0c3b43b1d185c5 Mon Sep 17 00:00:00 2001 From: souparnapal <72145624+souparnapal@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:55:29 +0530 Subject: [PATCH 124/394] Positive or Negative Program to find Positive or Negative Number using Nested If Condition in C --- Positive or Negative | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Positive or Negative diff --git a/Positive or Negative b/Positive or Negative new file mode 100644 index 00000000..23e4e614 --- /dev/null +++ b/Positive or Negative @@ -0,0 +1,21 @@ +#include + +int main() +{ + int number; + + printf("Enter any number:\n"); + scanf("%d",&number); + + if (number >= 0) + { + if (number > 0) + printf("%d is Positive Number", number); + else + printf("You have entered Value zero."); + } + else + printf("%d is Negative Number", number); + + return 0; +} From 619414de68d913e097b18e1f363271ef8777b545 Mon Sep 17 00:00:00 2001 From: Ankit-07-17 <72241661+Ankit-07-17@users.noreply.github.com> Date: Fri, 2 Oct 2020 09:59:02 +0530 Subject: [PATCH 125/394] Factorial_of_a_number This is the a c program to find factorial of a number --- Factorial_of_a_number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial_of_a_number diff --git a/Factorial_of_a_number b/Factorial_of_a_number new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/Factorial_of_a_number @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From 6dd3cfdf12a62d7bcfa4ff9e0376f4422a82eb02 Mon Sep 17 00:00:00 2001 From: Devendra Kumar Soni <69776043+soni-111@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:05:20 +0530 Subject: [PATCH 126/394] Create greatest number 1 program to find the greatest of two numbers in c --- greatest number 1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 greatest number 1 diff --git a/greatest number 1 b/greatest number 1 new file mode 100644 index 00000000..5e4e2dd8 --- /dev/null +++ b/greatest number 1 @@ -0,0 +1,27 @@ + #include + #include + void main() + { + + int n1,n2,sum; + clrscr(); + + printf("\nEnter 1st number : "); + scanf("%d",&n1); + + printf("\nEnter 2nd number : "); + scanf("%d",&n2); + + if(n1 > n2) + printf("\n1st number is greatest."); + else + printf("\n2nd number is greatest."); + + getch(); + } + + Output : + + Enter 1st number : 115 + Enter 2nd number : 228 + 2nd number is greatest. From 6e18ba96e6cf0555f851e55b4fec307c6bf8105e Mon Sep 17 00:00:00 2001 From: iamsky19 <72224423+iamsky19@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:17:15 +0530 Subject: [PATCH 127/394] Smaller Number --- Smaller Number | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Smaller Number diff --git a/Smaller Number b/Smaller Number new file mode 100644 index 00000000..441e2ce4 --- /dev/null +++ b/Smaller Number @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); +} From b2ea9c5a83336d73f620aa4037a620781733201e Mon Sep 17 00:00:00 2001 From: Ankesh Singh <65422972+Ankesh-26@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:18:22 +0530 Subject: [PATCH 128/394] Prime number Program to check whether the number is prime or not --- Prime number | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Prime number diff --git a/Prime number b/Prime number new file mode 100644 index 00000000..4fba8ae0 --- /dev/null +++ b/Prime number @@ -0,0 +1,27 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From 69f6af1be9aaec90b9af667fd2e82d1091f6e659 Mon Sep 17 00:00:00 2001 From: Sahil kumar <900213327sahil@gmail.com> Date: Fri, 2 Oct 2020 10:22:58 +0530 Subject: [PATCH 129/394] print an integer with C Basically added a C file to print an integer --- print an integer | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 print an integer diff --git a/print an integer b/print an integer new file mode 100644 index 00000000..907a4197 --- /dev/null +++ b/print an integer @@ -0,0 +1,14 @@ +#include +int main() { + int number; + + printf("Enter an integer: "); + + // reads and stores input + scanf("%d", &number); + + // displays output + printf("You entered: %d", number); + + return 0; +} From 516a83679af3324b50c9023289f922f6cd2f5a28 Mon Sep 17 00:00:00 2001 From: DIKSHA375 <72242795+DIKSHA375@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:28:45 +0530 Subject: [PATCH 130/394] countvowels c program to count vowels in a string --- countvowels | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 countvowels diff --git a/countvowels b/countvowels new file mode 100644 index 00000000..5e660fc1 --- /dev/null +++ b/countvowels @@ -0,0 +1,30 @@ +//PROGRAM TO COUNT VOWELS IN A STRING.. +#include +#include +#include +void main() +{ + char s1[30]; + int count=0,i; + clrscr(); + printf("Enter the sentence:"); + gets(s1); + for(i=0;i Date: Fri, 2 Oct 2020 10:43:04 +0530 Subject: [PATCH 131/394] Create CodeForces_Solution --- CodeForces_Solution | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CodeForces_Solution diff --git a/CodeForces_Solution b/CodeForces_Solution new file mode 100644 index 00000000..a969cced --- /dev/null +++ b/CodeForces_Solution @@ -0,0 +1,34 @@ +#include +using namespace std; +#define int long long +#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) +#define endl '\n' +#define mod 1000000007 +int min(int a, int b) { + if (a < b) + return a; + else + return b; +} +bool compare(int a, int b) { + return a > b; +} +int32_t main() { + fio; + int t; + cin >> t; + while (t--) { + int n; + cin >> n; + vectorv; + v.push_back(0); + for (int i = 3; i <= n; i += 2) { + v.push_back(2 * i + (i - 2) * 2); + } + int cnt = 0; + for (int i = 0; i < v.size(); i++) { + cnt += v[i] * i; + } + cout << cnt << endl; + } +} From 5b6897ddfc0cef7576e7a34d4092c6c8d3634727 Mon Sep 17 00:00:00 2001 From: Pragati Kalra <43950367+Pragati-Kalra@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:44:26 +0530 Subject: [PATCH 132/394] Binary Search C Program to implement binary search --- Binary Search | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Binary Search diff --git a/Binary Search b/Binary Search new file mode 100644 index 00000000..9d247c34 --- /dev/null +++ b/Binary Search @@ -0,0 +1,38 @@ + + + +#include + + +int binarySearch(int arr[], int l, int r, int x) +{ + if (r >= l) { + int mid = l + (r - l) / 2; + + + if (arr[mid] == x) + return mid; + + + if (arr[mid] > x) + return binarySearch(arr, l, mid - 1, x); + + + return binarySearch(arr, mid + 1, r, x); + } + + + return -1; +} + +int main(void) +{ + int arr[] = { 2, 3, 4, 10, 40 }; + int n = sizeof(arr) / sizeof(arr[0]); + int x = 10; + int result = binarySearch(arr, 0, n - 1, x); + (result == -1) ? printf("Element is not present in array") + : printf("Element is present at index %d", + result); + return 0; +} From 9ded9f972295781f1dfeb87f44bfbf61a761ecf5 Mon Sep 17 00:00:00 2001 From: mayank1140 <72243405+mayank1140@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:52:32 +0530 Subject: [PATCH 133/394] mayank find two number of c --- greater number c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 greater number c diff --git a/greater number c b/greater number c new file mode 100644 index 00000000..fa2d2b05 --- /dev/null +++ b/greater number c @@ -0,0 +1,22 @@ +#include +int main() +{ + int no1, no2; + printf("Insert two numbers:"); + scanf("%d %d",&no1, &no2); + + //Condition to check which of the two number is greater + //it will compare of number where number 1 is greater + if(no1 > no2) + printf("%d is greatest",no1); + + //where number 2 is greater + else if(no2 > no1) + printf("%d is greatest",no2); + + //for both are equal + else + printf("%d and %d are equal", no1, no2); + + return 0; +} From 086c12827b1a0c654515c83e76503bc4da94b34c Mon Sep 17 00:00:00 2001 From: Isha-nagpal <69720721+Isha-nagpal@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:54:31 +0530 Subject: [PATCH 134/394] fabonaccisequence Program to display Fabonacci sequence upto n terms in C. --- fabonaccisequence | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 fabonaccisequence diff --git a/fabonaccisequence b/fabonaccisequence new file mode 100644 index 00000000..9b6f1264 --- /dev/null +++ b/fabonaccisequence @@ -0,0 +1,17 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) + { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 1181e5f492994a53d40d0074afe88b1cdd1ad099 Mon Sep 17 00:00:00 2001 From: Meraj16 <72215899+Meraj16@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:55:13 +0530 Subject: [PATCH 135/394] Tower of Hanoi C recursive function to solve tower of hanoi puzzle --- TowerOfHanoi | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 TowerOfHanoi diff --git a/TowerOfHanoi b/TowerOfHanoi new file mode 100644 index 00000000..dbc4f920 --- /dev/null +++ b/TowerOfHanoi @@ -0,0 +1,34 @@ +#include + + +void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) +{ + + if (n == 1) + + { + + printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod); + + return; + + } + + towerOfHanoi(n-1, from_rod, aux_rod, to_rod); + + printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod); + + towerOfHanoi(n-1, aux_rod, to_rod, from_rod); +} + + + +int main() +{ + + int n = 4; // Number of disks + + towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods + + return 0; +} From c4b259f61e7342a93a007808b69956055a0311aa Mon Sep 17 00:00:00 2001 From: Abhishek-star-prog <72180876+Abhishek-star-prog@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:58:00 +0530 Subject: [PATCH 136/394] C Program to Add Two Matrices Using Multi-dimensional Arrays Program to Add Two Matrices Using Multi-dimensional Arrays --- ...wo Matrices Using Multi-dimensional Arrays | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 C Program to Add Two Matrices Using Multi-dimensional Arrays diff --git a/C Program to Add Two Matrices Using Multi-dimensional Arrays b/C Program to Add Two Matrices Using Multi-dimensional Arrays new file mode 100644 index 00000000..136681df --- /dev/null +++ b/C Program to Add Two Matrices Using Multi-dimensional Arrays @@ -0,0 +1,40 @@ +#include +int main() { + int r, c, a[100][100], b[100][100], sum[100][100], i, j; + printf("Enter the number of rows (between 1 and 100): "); + scanf("%d", &r); + printf("Enter the number of columns (between 1 and 100): "); + scanf("%d", &c); + + printf("\nEnter elements of 1st matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &a[i][j]); + } + + printf("Enter elements of 2nd matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &b[i][j]); + } + + // adding two matrices + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + sum[i][j] = a[i][j] + b[i][j]; + } + + // printing the result + printf("\nSum of two matrices: \n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("%d ", sum[i][j]); + if (j == c - 1) { + printf("\n\n"); + } + } + + return 0; +} From 711ec95f5b171f25b7aedb278a629afd352a89ab Mon Sep 17 00:00:00 2001 From: vikashyy08961 <60031737+vikashyy08961@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:58:22 +0530 Subject: [PATCH 137/394] ArmstrongNumber Armstrong Number in C --- ArmstrongNumber | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ArmstrongNumber diff --git a/ArmstrongNumber b/ArmstrongNumber new file mode 100644 index 00000000..a3c2d76d --- /dev/null +++ b/ArmstrongNumber @@ -0,0 +1,19 @@ +#include + int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=sum+(r*r*r); +n=n/10; +} +if(temp==sum) +printf("armstrong number "); +else +printf("not armstrong number"); +return 0; +} From c585b2c3f331605dd8e74791b2a639ceb9248435 Mon Sep 17 00:00:00 2001 From: Ank8873 <72183626+Ank8873@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:00:00 +0530 Subject: [PATCH 138/394] Palindrome n Program to check whether a number is palindrome or not --- palindrome using while loop | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 palindrome using while loop diff --git a/palindrome using while loop b/palindrome using while loop new file mode 100644 index 00000000..c18a0b80 --- /dev/null +++ b/palindrome using while loop @@ -0,0 +1,29 @@ +#include + +int main() +{ + int Number, Temp, Reminder, Reverse = 0; + + printf("\nPlease Enter any number to Check for Palindrome\n"); + scanf("%d", &Number); + + //Helps to prevent altering the original value + Temp = Number; + + while ( Temp > 0) + { + Reminder = Temp %10; + Reverse = Reverse *10+ Reminder; + Temp = Temp /10; + } + + printf("Reverse of entered number is = %d\n", Reverse); + + if ( Number == Reverse ) + printf("\n%d is Palindrome Number.\n", Number); + + else + printf("%d is not the Palindrome Number.\n", Number); + + return 0; +} From 5e2f2e635bb22d90302b3791e1c68c26c4912cea Mon Sep 17 00:00:00 2001 From: dipu007 <72186394+dipu007@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:03:00 +0530 Subject: [PATCH 139/394] LEAP YEAR check whether the year entered by the user is a leap year or not. --- check leap year | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 check leap year diff --git a/check leap year b/check leap year new file mode 100644 index 00000000..b945276c --- /dev/null +++ b/check leap year @@ -0,0 +1,27 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + + // leap year if perfectly visible by 400 + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + // not a leap year if visible by 100 + // but not divisible by 400 + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + // leap year if not divisible by 100 + // but divisible by 4 + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + // all other years are not leap year + else { + printf("%d is not a leap year.", year); + } + + return 0; +} From 2b64cb7a8a358725a96c9e68f2f083412f976655 Mon Sep 17 00:00:00 2001 From: saurabh kumar <67277120+saurabh-kumar0011@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:05:34 +0530 Subject: [PATCH 140/394] GCD program to find gcd. --- find gcd | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 find gcd diff --git a/find gcd b/find gcd new file mode 100644 index 00000000..b7e8ed2a --- /dev/null +++ b/find gcd @@ -0,0 +1,33 @@ +#include +#include + +int gcd(int a, int b) +{ + int r; + while(a) + { + r=b%a; + b=a; + a=r; + } + return b; +} +int gcd_(int* A, int N) +{ + int c=gcd(*A,*(A+1)); + int i,g; + for(i=1;i Date: Fri, 2 Oct 2020 11:11:08 +0530 Subject: [PATCH 141/394] Create greater of three numbers --- greater of three numbers | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 greater of three numbers diff --git a/greater of three numbers b/greater of three numbers new file mode 100644 index 00000000..9b6f073d --- /dev/null +++ b/greater of three numbers @@ -0,0 +1,13 @@ +int main() +{ + int num1,num2,num3; + printf("\nEnter value of num1, num2 and num3:"); + scanf("%d %d %d",&num1,&num2,&num3); + if((num1>num2)&&(num1>num3)) + printf("\n Number1 is greatest"); + else if((num2>num3)&&(num2>num1)) + printf("\n Number2 is greatest"); + else + printf("\n Number3 is greatest"); + return 0; +} From 5ab93d69d9c5e2019335af0d152800f1057f419f Mon Sep 17 00:00:00 2001 From: Yashdhankecha <72219348+Yashdhankecha@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:12:47 +0530 Subject: [PATCH 142/394] c program C Program to Find the Largest Number Among Three Numbers --- cprogram | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cprogram diff --git a/cprogram b/cprogram new file mode 100644 index 00000000..8c571177 --- /dev/null +++ b/cprogram @@ -0,0 +1,20 @@ +#include +int main() { + double n1, n2, n3; + printf("Enter three different numbers: "); + scanf("%lf %lf %lf", &n1, &n2, &n3); + + // if n1 is greater than both n2 and n3, n1 is the largest + if (n1 >= n2 && n1 >= n3) + printf("%.2f is the largest number.", n1); + + // if n2 is greater than both n1 and n3, n2 is the largest + if (n2 >= n1 && n2 >= n3) + printf("%.2f is the largest number.", n2); + + // if n3 is greater than both n1 and n2, n3 is the largest + if (n3 >= n1 && n3 >= n2) + printf("%.2f is the largest number.", n3); + + return 0; +} From b7cce5677308391bee2f7194147906fbaccb1f19 Mon Sep 17 00:00:00 2001 From: balbirsingh08 <66165177+balbirsingh08@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:14:12 +0530 Subject: [PATCH 143/394] Create C program to reverse given string --- C program to reverse given string | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 C program to reverse given string diff --git a/C program to reverse given string b/C program to reverse given string new file mode 100644 index 00000000..ee1b57f7 --- /dev/null +++ b/C program to reverse given string @@ -0,0 +1,18 @@ + +#include + +#include + +int main() + +{ + + char name[30] = "Hello"; + + printf("String before strrev( ) : %s\n",name); + + printf("String after strrev( ) : %s",strrev(name)); + + return 0; + +} From f2604711237aa94afc5f31f2ef9e4d294ad0bdbc Mon Sep 17 00:00:00 2001 From: saurabh kumar <67277120+saurabh-kumar0011@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:14:39 +0530 Subject: [PATCH 144/394] duplicate number in c find the duplicate number in c language. --- Duplicate number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Duplicate number diff --git a/Duplicate number b/Duplicate number new file mode 100644 index 00000000..107a776e --- /dev/null +++ b/Duplicate number @@ -0,0 +1,20 @@ +#include + +int main() +{ + //Initialize array + int arr[] = {1, 2, 3, 4, 2, 7, 8, 8, 3}; + + //Calculate length of array arr + int length = sizeof(arr)/sizeof(arr[0]); + + printf("Duplicate elements in given array: \n"); + //Searches for duplicate element + for(int i = 0; i < length; i++) { + for(int j = i + 1; j < length; j++) { + if(arr[i] == arr[j]) + printf("%d\n", arr[j]); + } + } + return 0; +} From 8e0ff364ed858457aa9b4ad7339fa567e4e62baf Mon Sep 17 00:00:00 2001 From: SunilBhadu <72160705+SunilBhadu@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:17:59 +0530 Subject: [PATCH 145/394] Triplet of three numbers (a,b,c) Input : Triplet of three numbers (a,b,c) Output : 1 if they are either in strictly increasing (a>b>c) or decreasing (a + + + +void main() + +{ + + float arr[4]; + + + + for(int i=0; i<3; i++) + + scanf("%f",&arr[i]); + + + + //To check wether the triplet is strictly increasing or decreasing or none. + + + + if(arr[0]>arr[1]&&arr[1]>arr[2]) + + printf("1"); + + else if(arr[2]>arr[1]&&arr[1]>arr[0]) + + printf("1"); + + else + + printf("0"); + +} From d78f9554797954035e69ecb28bd811d8bec8da53 Mon Sep 17 00:00:00 2001 From: vinayak017 <72243768+vinayak017@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:24:54 +0530 Subject: [PATCH 146/394] cieser-cipher It is an implementation of ceaser cipher algorithm for encryption and decryption. --- cieser-cipher-encryption | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 cieser-cipher-encryption diff --git a/cieser-cipher-encryption b/cieser-cipher-encryption new file mode 100644 index 00000000..5a9be319 --- /dev/null +++ b/cieser-cipher-encryption @@ -0,0 +1,85 @@ + +#include +void encryption(); +void decryption(); + +void main(){ + encryption(); + decryption(); +} + +void encryption() +{ + char message[100], ch; + int i, key; + + printf("Enter a message to encrypt: "); + gets(message); + printf("Enter key: "); + scanf("%d", &key); + + for(i = 0; message[i] != '\0'; ++i){ + ch = message[i]; + + if(ch >= 'a' && ch <= 'z'){ + ch = ch + key; + + if(ch > 'z'){ + ch = ch - 'z' + 'a' - 1; + } + + message[i] = ch; + } + else if(ch >= 'A' && ch <= 'Z'){ + ch = ch + key; + + if(ch > 'Z'){ + ch = ch - 'Z' + 'A' - 1; + } + + message[i] = ch; + } + } + + printf("Encrypted message: %s", message); + + return 0; +} + +void decryption() +{ + char message[100], ch; + int i, key; + + printf("Enter a message to decrypt: "); + gets(message); + printf("Enter key: "); + scanf("%d", &key); + + for(i = 0; message[i] != '\0'; ++i){ + ch = message[i]; + + if(ch >= 'a' && ch <= 'z'){ + ch = ch - key; + + if(ch < 'a'){ + ch = ch + 'z' - 'a' + 1; + } + + message[i] = ch; + } + else if(ch >= 'A' && ch <= 'Z'){ + ch = ch - key; + + if(ch < 'A'){ + ch = ch + 'Z' - 'A' + 1; + } + + message[i] = ch; + } + } + + printf("Decrypted message: %s", message); + + return 0; +} From e5d234aff947a850af174162dc0dcab4938950e8 Mon Sep 17 00:00:00 2001 From: Naman Bansal <70460541+nkbansal-hacks@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:27:58 +0530 Subject: [PATCH 147/394] Create Odd and even --- Odd and even | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Odd and even diff --git a/Odd and even b/Odd and even new file mode 100644 index 00000000..d169ebbc --- /dev/null +++ b/Odd and even @@ -0,0 +1,14 @@ +include +int main() { + int num; + printf("Enter an integer: "); + scanf("%d", &num); + + // True if num is perfectly divisible by 2 + if(num % 2 == 0) + printf("%d is even.", num); + else + printf("%d is odd.", num); + + return 0; +} From c7e82281cdc4c76e22f27b34d0a4e7b32b0a4ec5 Mon Sep 17 00:00:00 2001 From: MANORANJAN SINGH <72244345+ManoCoder@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:31:11 +0530 Subject: [PATCH 148/394] SimpleCalci C Program to Make a Simple Calculator Using switch...case --- SimpleCalci | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SimpleCalci diff --git a/SimpleCalci b/SimpleCalci new file mode 100644 index 00000000..a8bd462a --- /dev/null +++ b/SimpleCalci @@ -0,0 +1,29 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} From 050d68eb2f18af018465efd3570cd61bdf7a7a11 Mon Sep 17 00:00:00 2001 From: juned06 <65291616+juned06@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:36:08 +0530 Subject: [PATCH 149/394] Create prog.c --- prog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 prog.c diff --git a/prog.c b/prog.c new file mode 100644 index 00000000..5a1262e1 --- /dev/null +++ b/prog.c @@ -0,0 +1,19 @@ +#include +int main(){ +int n,i,m=0,flag=0; +printf("Enter the number to check prime:"); +scanf("%d",&n); +m=n/2; +for(i=2;i<=m;i++) +{ +if(n%i==0) +{ +printf("Number is not prime"); +flag=1; +break; +} +} +if(flag==0) +printf("Number is prime"); +return 0; + } From 72202137d4b5440e07b111a84fee960ab64f118d Mon Sep 17 00:00:00 2001 From: amanrajkumar4 <62813940+amanrajkumar4@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:38:53 +0530 Subject: [PATCH 150/394] stack_implementation.c This program is use to implement stack using static array. The default size of stack is give as 5 , you can increase or decrease that size depending upon your choice and other things are very simple. Please check this at once. Thank you. --- stack_implementation.c | 125 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 stack_implementation.c diff --git a/stack_implementation.c b/stack_implementation.c new file mode 100644 index 00000000..34fa4ca6 --- /dev/null +++ b/stack_implementation.c @@ -0,0 +1,125 @@ +//Stack implementation using static array + +#include +#define CAPACITY 5 //Pre-processor macro and change the size if you want +int stack[CAPACITY], top=-1 ; + +void push(int); +int pop(void); +int isFull(void); +int isEmpty(void); +void traverse(void); +void peek(void); + +void main() +{ + char ch; + long int item; + while(1) + { + printf("\n ---------------------- \n 1.Push an element \n 2.PoP element\n 3.Peek \n 4.Traverse\n 5.Quit \n ---------------------- \n"); + printf("Enter your choice:"); + scanf("%d",&ch); + + switch(ch) + { + case 1: + printf("\nEnter element to push:"); + scanf("%d",&item); + push(item); + break; + case 2: item = pop(); + if(item==0) + { + printf("Stack is underflow\n"); + } + else + { + printf("Popped item: %d\n",item); + } + break; + case 3: peek(); + break; + case 4: traverse(); + break; + case 5: exit(0); + default: printf("Invalid input\n\n"); + break; + } + } + +} +int isFull() +{ + if(top== CAPACITY-1) + { + return 1; + } + else + { + return 0; + } +} +int isEmpty() +{ + if(top==-1) + { + return 1; + } + else + { + return 0; + } +} +void push(int ele) +{ + if(isFull()) + { + printf("\n Stack is overflow...\n"); + } + else + { + top++; + stack[top] = ele; + printf("\n %d pushed into stack \n", ele); + } +} + +int pop() +{ + if(isEmpty()) + { + return 0; + } + else + { + return stack[top--]; + } +} +void peek() +{ + if(isEmpty()) + { + printf("\nStack is empty \n"); + } + else + { + printf("\n Peek element: %d \n",stack[top]); + } +} +void traverse() +{ + if(isEmpty()) + { + printf("\n Stack is empty \n"); + } + else + { + int i; + printf("\n Stack elements : \n"); + for(i=0;i<=top;i++) + { + printf("%d\n________________ \n",stack[i]); + } + } +} From fb4b928334e7145e48c623f11bd1c70cf6b5a0e9 Mon Sep 17 00:00:00 2001 From: Rishabh2257 <55252963+Rishabh2257@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:39:17 +0530 Subject: [PATCH 151/394] Larger Program to find larger of two number --- larger | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 larger diff --git a/larger b/larger new file mode 100644 index 00000000..fc8d4fac --- /dev/null +++ b/larger @@ -0,0 +1,15 @@ +#include +int main() +{ +int n1, n2; +scanf(“%d %d”,&n1,&n2); +if(n1 > n2) +{ +printf(“%d is larger”,n1); +} +else +{ +printf(“%d is larger”,n2); +} +return 0; +} From 1088c68a73e31dc69fb4c58b2cdd4ba5dc083112 Mon Sep 17 00:00:00 2001 From: chhavi200 <67577424+chhavi200@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:39:17 +0530 Subject: [PATCH 152/394] Simple Interest Program for Simple Interest --- Simple Interest | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Simple Interest diff --git a/Simple Interest b/Simple Interest new file mode 100644 index 00000000..145727ce --- /dev/null +++ b/Simple Interest @@ -0,0 +1,11 @@ +#include +#include +void main() +{ +int p,r,t,i; +float si; +printf("\n enter Principle amount,rate,time"); +scanf("%d%d%d"&p,&r,&t); +si=(p*r*t)/100; +getch(); +} From 29c4151731c87b46ec4d7990cacd1c6316a4d8fa Mon Sep 17 00:00:00 2001 From: Khush3211 <34205476+khush3211@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:41:02 +0530 Subject: [PATCH 153/394] sachdevakh --- sachdevakh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sachdevakh diff --git a/sachdevakh b/sachdevakh new file mode 100644 index 00000000..21dbe0ff --- /dev/null +++ b/sachdevakh @@ -0,0 +1,18 @@ +// C program to find the greatest of two numbers + +#include +int main() +{ +//Fill the code +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} From a7bbe3bccb4f89a6c01b6d0cf9eccba707c05042 Mon Sep 17 00:00:00 2001 From: Saindanejayesh <64307456+Saindanejayesh@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:43:25 +0530 Subject: [PATCH 154/394] greternumber C Language Program is accept two number from user,check the number and find the gretest number from those two number and display gretest number. --- greternumber | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 greternumber diff --git a/greternumber b/greternumber new file mode 100644 index 00000000..02fee784 --- /dev/null +++ b/greternumber @@ -0,0 +1,54 @@ +#include + + + +int main(void) + +{ + + + int num1,num2; + + printf("Enter two numbers:"); + scanf("%d %d",&num1,&num2); + + + if(num1>num2) + + + { + + printf("%d is greatest",num1); + + +} + + + else if(num2>num1) + + + { + + + printf("%d is greatest",num2); + + +} + + + else + + + { + + + printf("%d and %d are equal",num1,num2); + + + } + + + return 0; + + +} From 20d790a07690e10f3192976a354acca174137072 Mon Sep 17 00:00:00 2001 From: Lokesh Raj Singhi Date: Fri, 2 Oct 2020 12:00:36 +0545 Subject: [PATCH 155/394] ReverseNumber.c A c program to reverse an integer. --- ReverseNumber.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 ReverseNumber.c diff --git a/ReverseNumber.c b/ReverseNumber.c new file mode 100644 index 00000000..2555af0a --- /dev/null +++ b/ReverseNumber.c @@ -0,0 +1,13 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + printf("Reversed number = %d", rev); + return 0; +} From bf5e5b91710941cbb4e87d4ef8b49bd4aecbd8a6 Mon Sep 17 00:00:00 2001 From: abhishek752 <72187095+abhishek752@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:17:28 -0400 Subject: [PATCH 156/394] greatest number program to find greatest numbers in c --- greatest number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 greatest number diff --git a/greatest number b/greatest number new file mode 100644 index 00000000..8c571177 --- /dev/null +++ b/greatest number @@ -0,0 +1,20 @@ +#include +int main() { + double n1, n2, n3; + printf("Enter three different numbers: "); + scanf("%lf %lf %lf", &n1, &n2, &n3); + + // if n1 is greater than both n2 and n3, n1 is the largest + if (n1 >= n2 && n1 >= n3) + printf("%.2f is the largest number.", n1); + + // if n2 is greater than both n1 and n3, n2 is the largest + if (n2 >= n1 && n2 >= n3) + printf("%.2f is the largest number.", n2); + + // if n3 is greater than both n1 and n2, n3 is the largest + if (n3 >= n1 && n3 >= n2) + printf("%.2f is the largest number.", n3); + + return 0; +} From 2c579111cff322eaa86d16bf5eb9a6d8230640d1 Mon Sep 17 00:00:00 2001 From: pavankalyanimadabathini <48764540+pavankalyanimadabathini@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:49:40 +0530 Subject: [PATCH 157/394] greaternumber C Program to Find Largest of Two Numbers --- greatemo | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 greatemo diff --git a/greatemo b/greatemo new file mode 100644 index 00000000..0ff23675 --- /dev/null +++ b/greatemo @@ -0,0 +1,22 @@ +#include + +int main() { + int a, b; + printf("Please Enter Two different values\n"); + scanf("%d %d", &a, &b); + + if(a > b) + { + printf("%d is Largest\n", a); + } + else if (b > a) + { + printf("%d is Largest\n", b); + } + else + { + printf("Both are Equal\n"); + } + + return 0; +} From da5e382e8ca394dd4e353dc23e686753280b2b24 Mon Sep 17 00:00:00 2001 From: abhishek752 <72187095+abhishek752@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:21:41 -0400 Subject: [PATCH 158/394] Odd number program to find odd numbers in c --- odd number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 odd number diff --git a/odd number b/odd number new file mode 100644 index 00000000..24ff1dfd --- /dev/null +++ b/odd number @@ -0,0 +1,14 @@ +#include +int main() { + int num; + printf("Enter an integer: "); + scanf("%d", &num); + + // True if num is perfectly divisible by 2 + if(num % 2 == 0) + printf("%d is even.", num); + else + printf("%d is odd.", num); + + return 0; +} From 9a71e4529d11dacf9bd627a85955c950ee31f102 Mon Sep 17 00:00:00 2001 From: vksince2000 <59836308+vksince2000@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:57:11 +0530 Subject: [PATCH 159/394] Create NUmber to Words conversation --- NUmber to Words conversation | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 NUmber to Words conversation diff --git a/NUmber to Words conversation b/NUmber to Words conversation new file mode 100644 index 00000000..f396ecc9 --- /dev/null +++ b/NUmber to Words conversation @@ -0,0 +1,62 @@ +#include + +int main() +{ + int n, num = 0; + + /* Input number from user */ + printf("Enter any number to print in words: "); + scanf("%d", &n); + + /* Store reverse of n in num */ + while(n != 0) + { + num = (num * 10) + (n % 10); + n /= 10; + } + + /* + * Extract last digit of number and print corresponding digit in words + * till num becomes 0 + */ + while(num != 0) + { + switch(num % 10) + { + case 0: + printf("Zero "); + break; + case 1: + printf("One "); + break; + case 2: + printf("Two "); + break; + case 3: + printf("Three "); + break; + case 4: + printf("Four "); + break; + case 5: + printf("Five "); + break; + case 6: + printf("Six "); + break; + case 7: + printf("Seven "); + break; + case 8: + printf("Eight "); + break; + case 9: + printf("Nine "); + break; + } + + num = num / 10; + } + + return 0; +} From 6e1adad1d4f244d9f0577127e91dfaee07092ac3 Mon Sep 17 00:00:00 2001 From: harshit041 <52853519+harshit041@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:10:29 +0530 Subject: [PATCH 160/394] primefactors Cpp program to count the prime factors of the number using Sieve of Eratosthenes --- primefactors | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 primefactors diff --git a/primefactors b/primefactors new file mode 100644 index 00000000..0d65b01c --- /dev/null +++ b/primefactors @@ -0,0 +1,43 @@ +//To count the number of prime factors of a number i.e. prime factorization for 12246 : 2*3*13*157 +//so number of prime factors=4. + +#include +using namespace std; +#define MAXN 100001 + +long long spf[MAXN]; +void sieve(){ + spf[1] = 1; + for(long long i=2;i getFactorization(long long x){ + vector ret; + while (x != 1){ + ret.push_back(spf[x]); + x = x / spf[x]; + } + return ret; +} + +int main(int argc, char const *argv[]){ + sieve(); + long long n{0}; + cin>>n; + vector p = getFactorization(n); + cout< Date: Fri, 2 Oct 2020 12:17:32 +0530 Subject: [PATCH 161/394] Greater No. Program to find the greatest no. --- Greatest No. | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Greatest No. diff --git a/Greatest No. b/Greatest No. new file mode 100644 index 00000000..7b9bc949 --- /dev/null +++ b/Greatest No. @@ -0,0 +1,25 @@ +#include + +void main() +{ + int num1, num2, num3; + + printf("Enter the values of num1, num2 and num3\n"); + scanf("%d %d %d", &num1, &num2, &num3); + printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3); + if (num1 > num2) + { + if (num1 > num3) + { + printf("num1 is the greatest among three \n"); + } + else + { + printf("num3 is the greatest among three \n"); + } + } + else if (num2 > num3) + printf("num2 is the greatest among three \n"); + else + printf("num3 is the greatest among three \n"); +} From 41a8b8de31b836d76aedc1fdb0379a37f8660190 Mon Sep 17 00:00:00 2001 From: Rahul Dubey <45910545+rahuldubeycse@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:31:59 +0530 Subject: [PATCH 162/394] Create factorial --- factorial | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 factorial diff --git a/factorial b/factorial new file mode 100644 index 00000000..846f0ed4 --- /dev/null +++ b/factorial @@ -0,0 +1,12 @@ + #include + int main() + { + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); + return 0; + } From ca6a083b72a671fcd9fc4e7b4f0f712939caadcd Mon Sep 17 00:00:00 2001 From: Pranav N Date: Fri, 2 Oct 2020 12:32:39 +0530 Subject: [PATCH 163/394] Create BestTimeToBuyStocks.cpp --- BestTimeToBuyStocks.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 BestTimeToBuyStocks.cpp diff --git a/BestTimeToBuyStocks.cpp b/BestTimeToBuyStocks.cpp new file mode 100644 index 00000000..a7610394 --- /dev/null +++ b/BestTimeToBuyStocks.cpp @@ -0,0 +1,21 @@ +/* Say you have an array for which the ith element is the price of a given stock on day i. + +If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. + +Note that you cannot sell a stock before you buy one. */ + + +class Solution { +public: + int maxProfit(vector& v) { + int profit=0; + int mini=INT_MAX; + for(int i=0;i Date: Fri, 2 Oct 2020 12:33:22 +0530 Subject: [PATCH 164/394] Create stack pop up program --- stack pop up program | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 stack pop up program diff --git a/stack pop up program b/stack pop up program new file mode 100644 index 00000000..2d17f0a9 --- /dev/null +++ b/stack pop up program @@ -0,0 +1,82 @@ +#include +#include +#include + +#define MAX 5 //Maximum number of elements that can be stored + +int top=-1,stack[MAX]; +void push(); +void pop(); +void display(); + +void main() +{ + int ch; + + while(1) //infinite loop, will end when choice will be 4 + { + printf("\n*** Stack Menu ***"); + printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit"); + printf("\n\nEnter your choice(1-4):"); + scanf("%d",&ch); + + switch(ch) + { + case 1: push(); + break; + case 2: pop(); + break; + case 3: display(); + break; + case 4: exit(0); + + default: printf("\nWrong Choice!!"); + } + } +} + +void push() +{ + int val; + + if(top==MAX-1) + { + printf("\nStack is full!!"); + } + else + { + printf("\nEnter element to push:"); + scanf("%d",&val); + top=top+1; + stack[top]=val; + } +} + +void pop() +{ + if(top==-1) + { + printf("\nStack is empty!!"); + } + else + { + printf("\nDeleted element is %d",stack[top]); + top=top-1; + } +} + +void display() +{ + int i; + + if(top==-1) + { + printf("\nStack is empty!!"); + } + else + { + printf("\nStack is...\n"); + for(i=top;i>=0;--i) + printf("%d\n",stack[i]); + } +} From f74102a5ea95f1008eeab604cf92028a2f8ac73a Mon Sep 17 00:00:00 2001 From: vanshkhemani <72235371+vanshkhemani@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:38:13 +0530 Subject: [PATCH 165/394] addoftwono addition of two number --- addoftwono | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 addoftwono diff --git a/addoftwono b/addoftwono new file mode 100644 index 00000000..6135c5ae --- /dev/null +++ b/addoftwono @@ -0,0 +1,14 @@ +#include + +int main() { + int a, b, sum; + + printf("\nEnter two no: "); + scanf("%d %d", &a, &b); + + sum = a + b; + + printf("Sum : %d", sum); + + return(0); +} From 821ed011cf4071a538b5c0227b20e2a2adcb6e46 Mon Sep 17 00:00:00 2001 From: Rishi0404 <72246887+Rishi0404@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:42:17 +0530 Subject: [PATCH 166/394] Checking leap year This a source code of finding a leap year in c language. --- program to check leap year | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 program to check leap year diff --git a/program to check leap year b/program to check leap year new file mode 100644 index 00000000..f15b3d3e --- /dev/null +++ b/program to check leap year @@ -0,0 +1,22 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + + // leap year if perfectly visible by 400 + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + else { + printf("%d is not a leap year.", year); + } + + return 0; +} From 7ba649608f506a76890c4c9a72326c0e6c123aad Mon Sep 17 00:00:00 2001 From: subha-code <64766123+subha-code@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:44:14 +0530 Subject: [PATCH 167/394] gassbooking project program to create a project of gassbooking system for user choice. --- gassbooking | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 gassbooking diff --git a/gassbooking b/gassbooking new file mode 100644 index 00000000..323c2183 --- /dev/null +++ b/gassbooking @@ -0,0 +1,83 @@ +#include +#include +#include +#include +void data(){ + int press; + + int id; + char name[50]; + printf("\nThank you for comming :-)"); + + + + printf("\nEnter your valid id number: "); + scanf("%d",&id); + fflush(stdin); + printf("\nEnter your name: "); + gets(name); + printf("\n1.LPG big cylinders\n2.LPG mini cylinders\n3.acetylin cylinders\ndefault.cancel your orders"); + + + + printf("\nEnter your choice:"); + scanf("%d",&press); + switch(press){ + + case 1: + printf("----------------------------------------------------------------------------------"); + printf("\nLpg big cylinders"); + printf("\nyour choice lpg big cylinders\n"); + printf("Your id %d\n",id); + printf("your name: "); + puts(name); + printf("\nyour order is sucessful\nyour gas delivary within 24 days\n"); + printf("----------------------------------------------------------------------------------"); + break; + case 2: + printf("----------------------------------------------------------------------------------"); + printf("\nLpg mini cylinders"); + printf("\nyour choice mini cylinders\n"); + printf("Your id %d\n",id); + printf("your name: "); + puts(name); + printf("\nyour order is sucessful\nyour gas delivary within 24 days\n"); + printf("----------------------------------------------------------------------------------"); + break; + case 3: + printf("----------------------------------------------------------------------------------"); + printf("\nacetylin cylinders"); + printf("\nyour choice acetylin cylinders\n"); + printf("Your id %d\n",id); + printf("your name: "); + puts(name); + printf("\nyour order is sucessful \n your gas delivary within 24 days\n"); + printf("----------------------------------------------------------------------------------"); + break; + default: + printf("----------------------------------------------------------------------------------"); + printf("\ncancel your order "); + printf("\nyour order with name and id cancel sucessfully\n"); + printf("----------------------------------------------------------------------------------"); +} + +} + +int main() +{ + + char choice = 'y'; + + + + data(); + printf("\n\nyou want to continue yes or no\nif yes press y or no press n:"); + choice = getche(); + + }while(choice == 'y'); + + + return 0; + + +} From 59286bccb8dade179aa53b1af0e9eb3d790adfff Mon Sep 17 00:00:00 2001 From: rudrabisht <71915909+rudrabisht@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:45:51 +0530 Subject: [PATCH 168/394] factors This program takes a positive integer from the user and displays all the positive factors of that number. --- factors | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 factors diff --git a/factors b/factors new file mode 100644 index 00000000..75f1ba15 --- /dev/null +++ b/factors @@ -0,0 +1,13 @@ +#include +int main() { + int num, i; + printf("Enter a positive integer: "); + scanf("%d", &num); + printf("Factors of %d are: ", num); + for (i = 1; i <= num; ++i) { + if (num % i == 0) { + printf("%d ", i); + } + } + return 0; +} From a99375ae358120f343615e9bc48ec4943426b136 Mon Sep 17 00:00:00 2001 From: vanshkhemani <72235371+vanshkhemani@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:46:24 +0530 Subject: [PATCH 169/394] multiplyoftwono program of multiplication of two number --- multiplyoftwono | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 multiplyoftwono diff --git a/multiplyoftwono b/multiplyoftwono new file mode 100644 index 00000000..6aabbae8 --- /dev/null +++ b/multiplyoftwono @@ -0,0 +1,14 @@ +#include +int main() { + double a, b, product; + printf("Enter two numbers: "); + scanf("%lf %lf", &a, &b); + + // Calculating product + product = a * b; + + // Result up to 2 decimal point is displayed using %.2lf + printf("Product = %.2lf", product); + + return 0; +} From b6a0ee5f9563ea3652dbe8214ed54add2c65bbb3 Mon Sep 17 00:00:00 2001 From: Kaushal Patil <42778671+kupatil@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:57:08 +0530 Subject: [PATCH 170/394] Program to convert binary to decimal Create program to convert binary to decimal in C language. --- Convert binary to decimal | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Convert binary to decimal diff --git a/Convert binary to decimal b/Convert binary to decimal new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/Convert binary to decimal @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From 98c90c772ed1385155d22e875f429d37626c4ac4 Mon Sep 17 00:00:00 2001 From: SASHWAT12 <65287899+SASHWAT12@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:01:10 +0530 Subject: [PATCH 171/394] HangmangameinC This is a traditional hangman game in which you have to guess a word letter by letter. For this to work you need to create a text file with name "words.txt" in same directory of this program and add some words in it and each word separated by ' | ' symbol. --- HangmangameinC | 320 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 HangmangameinC diff --git a/HangmangameinC b/HangmangameinC new file mode 100644 index 00000000..c083802f --- /dev/null +++ b/HangmangameinC @@ -0,0 +1,320 @@ +#include +#include +#include +#include +#include +#include +#include +/********************************************************************** +* * +* Code written by P Sashwat. * +* More information regarding this code and me can be found on my * +* Linkedin Profile : https://www.linkedin.com/in/sashwat-p-1952471b1/ * +* * +***********************************************************************/ +char fileLoc[500]; // backup file location +void showLogo() { + printf("--------------------------------------------\n"); + printf("| # # # # # #### # # # # # |\n"); + printf("| # # # # ## # # ## ## # # ## # |\n"); + printf("| #### ##### # # # # ## # # # ##### # # # |\n"); + printf("| # # # # # ## # # # # # # # ## |\n"); + printf("| # # # # # # ### # # # # # # |\n"); + printf("--------------------------------------------\n\n"); +} +void prn_galg(int i) { + switch (i) { + case 0 : + printf("Amount of wrong letters: %d\n\n", i); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("\n"); + printf("____________\n\n"); + break; + case 1 : + printf("Amount of wrong letters: %d\n\n", i); + printf("\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 2 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 3 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 4 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" |\n"); + printf(" |\n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 5 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" | |\n"); + printf(" | |\n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 6 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" | \\|\n"); + printf(" | | \n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 7 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" | \\|/\n"); + printf(" | | \n"); + printf(" |\n"); + printf("__|_________\n\n"); + break; + case 8 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" | \\|/\n"); + printf(" | | \n"); + printf(" | /\n"); + printf("__|_________\n\n"); + break; + case 9 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | O \n"); + printf(" | \\|/\n"); + printf(" | | \n"); + printf(" | / \\\n"); + printf("__|_________\n\n"); + break; + case 10 : + printf("Amount of wrong letters: %d\n\n", i); + printf(" _______\n"); + printf(" |/ | \n"); + printf(" | X \n"); + printf(" | \\|/\n"); + printf(" | | \n"); + printf(" | / \\\n"); + printf("__|_________\n\n"); + break; + } +} +char randomNumber(int max_number) { +srand(time(NULL)); +int g = (rand() % (max_number + 1)); +return g; +} +char *getWord() { + char c[50000]; // declare a char array + int n; + FILE *file; // declare a FILE pointer + // Opening words file + if (strcmp(fileLoc, "") != 1) { + // Here is the default words file, you can change this into whatever words file you'd like. + file = fopen("words.txt", "r"); + } else { + file = fopen(fileLoc, "r"); + } + /* Incase the file can't be openend */ + if(file==NULL) { + printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n"); + scanf("%s", fileLoc); + printf("Reading file '%s'.....\n\n", fileLoc); + file = fopen(fileLoc, "r"); + if (file == NULL) { + while (file==NULL) { + printf("That file doesn't exist. Enter the location of the words file:\n"); + scanf("%s", fileLoc); + printf("Reading file '%s'.....\n\n", fileLoc); + file = fopen(fileLoc, "r"); + } + } + printf("File has been read.\n\n"); + n = fread(c, 1, 50000, file); + c[n] = '\0'; + } else { + /* Reading the contents of the file */ + n = fread(c, 1, 50000, file); + c[n] = '\0'; + } + /* Separating the contents, divided by | and declaring variables */ + char *token = strtok(c, "|"); + char *words[200] = {0}; + int f = 0; + while(token != NULL) + { + /* Allocating memory for the pointer */ + words[f] = malloc(strlen(token)+1); + /* Copying entire string to pointer */ + strcpy(words[f],token); + /* Resetting pointer */ + token = strtok(NULL, "|"); + f++; + } + /* Closing the file */ + fclose(file); + /* Retrieving a random number */ + int wordN = randomNumber(f); + /* Freeing all the memory allocated for the strings */ + int q; + for(q = 0; q < 200; q++) + { + if( q != wordN) { + free(words[q]); + } + } + /* Returning string */ + return words[wordN]; +} +int main(void) { +char udi[] = "EMPTY"; +while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) { + strcpy(udi, "EMPTY"); + /* Declaring variables */ + /* Random deciding which word is chosen to be guessed: + guessWord is the word that needs to be guessed + currentWord is the word that is filled with dots */ + /* Retrieving the word that matches with the wordNumber */ + /* Check which number was chosen: printf("%d", wordNumber); */ + char *tempWord = getWord(); + /* Declaring the guessWord with the length of dkljafoue */ + char guessWord[strlen(tempWord)+1]; + /* Copying the string of dkljafoue into guessWord */ + strcpy(guessWord, tempWord); + /* Freeing the pointer */ + free(tempWord); + /* Calculate the length of the guessWord */ + int wordlength = strlen(guessWord); + /* Creating the dotword (name: currentWord) */ + char* currentWord = malloc( wordlength ); + int t; + for (t = 0; t <= wordlength; t++) { + if (t == wordlength) { + currentWord[t] = '\0'; + } else { + currentWord[t] = '.'; + } + } + /* Currentword check: printf("Currentword: \"%s\"", currentWord); */ + /* Declaring variables */ + int errors = 0; /* Error amount, if its higher than 10 the loop stops */ + int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */ + int i,n = 1; + char c; + /* Printing logo */ + showLogo(); + /* Printing introduction message */ + printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n", + "Welcome to the Hangman game!", + "The objective in this game is to guess the word.", + "You can enter both uppercase and lowercase letters.", + "If you think you know the word, you can type it in.", + "You will loose if you have guessed 10 letters wrong.", + " -Made By P Sashwat.\n", + "This is the word you need to guess: ", + currentWord); + printf("%d. %s", n, "Enter the letter(s) you want to guess: "); + /* As long as the word hasn't been guessed or the errors are lower than 10: */ + while( (strcmp(currentWord, guessWord) != 0) && (errors < 10) ){ + scanf("%c", &c); /* Retrieving the user entry */ + c = tolower(c); /* Removing caps */ + if (c != '\n') { + if (isalpha(c)) { /* Making sure that the letter is alphanumeric */ + /* Checking wether the letter that has been entered (c) occurs in the guessWord */ + for (i = 0; i < wordlength; i++) { + if (guessWord[i] == c) { + currentWord[i] = c; + guessedLetter = 1; + } + } + /* Actions taken if the letter c doesn't occur in the guessWord and when it does */ + if (guessedLetter == 0) { + errors++; + printf("\nThat letter was incorrect.\n\n"); + } else { + guessedLetter = 0; + printf("\nThat letter was correct.\n\n"); + } + /* Showing the galg and the amount of errors */ + printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord); + prn_galg(errors); + n++; /* Increasing attempt amount */ + /* Showing header if the word has not been guessed and the errors are lower than 10 */ + if ( (strcmp(currentWord, guessWord) != 0) && (errors < 10) ) { + printf("%d. %s", n, "Enter the letter(s) you want to guess: "); + } + /* If the letter isn't alphanumeric (isalpha()) */ + } else { + printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n"); + } + } + } + /* Showing the results, wether the player won or not */ + printf("---------------\n"); + printf("--- Results ---\n"); + printf("---------------\n\n"); + if (errors < 10) { + if (strcmp(currentWord, guessWord) == 0) { + printf("Congratulations you have guessed the right word!\n\n"); + } else { + printf("You have guessed the wrong word, better luck next time!\n\n"); + } + } else { + printf("You have guessed the wrong word, better luck next time!\n\n"); + } + printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord); + printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n"); + // Making sure that the user doesn't enter strange things + while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) { + if (strcmp(udi, "EMPTY") != 0) { + printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n"); + } + // Retrieving the udi (udi = user determined input) + scanf("%s", udi); + // Converting the udi to uppercase + int x; + for (x = 0; x < 5; x++) { + udi[x] = toupper(udi[x]); + } + } + printf("\n\n--------------------------------------------\n\n"); +} +return 0; +} From 489b65dede4bc4418f304f7d8f7fc2f50181f3df Mon Sep 17 00:00:00 2001 From: Rishi Sharma <72246887+Rishi0404@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:04:23 +0530 Subject: [PATCH 172/394] program for whether a no. is prime or not creating a c program for checking a no. is a prime one or not --- check whether a no. is prime or not | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 check whether a no. is prime or not diff --git a/check whether a no. is prime or not b/check whether a no. is prime or not new file mode 100644 index 00000000..ce336769 --- /dev/null +++ b/check whether a no. is prime or not @@ -0,0 +1,25 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From eed2d88666118bcb80b2d2042b753e3cad63dfa0 Mon Sep 17 00:00:00 2001 From: ajeers <54639791+sus5pect@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:11:48 +0530 Subject: [PATCH 173/394] Create gcd_of_2_numbers --- gcd_of_2_numbers | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gcd_of_2_numbers diff --git a/gcd_of_2_numbers b/gcd_of_2_numbers new file mode 100644 index 00000000..efb2e9f5 --- /dev/null +++ b/gcd_of_2_numbers @@ -0,0 +1,33 @@ +// C program to find GCD of two numbers +#include + +// Recursive function to return gcd of a and b +int gcd(int a, int b) +{ + // Everything divides 0 + if (a == 0) + return b; + if (b == 0) + return a; + + // base case + if (a == b) + return a; + + // a is greater + if (a > b) + return gcd(a-b, b); + return gcd(a, b-a); +} + +// Driver program to test above function +int main() +{ + + int a , b ; + printf("Enter 2 numbers to find their gcd"); + scanf("%d%d",&a,&b); + printf("GCD of %d and %d is %d ", a, b, gcd(a, b)); + return 0; + +} From 24009f25ce43594c1d225870cced781178ddeb52 Mon Sep 17 00:00:00 2001 From: Pankaj Yadav <35138119+pankajpkpj@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:21:43 +0530 Subject: [PATCH 174/394] while loop --- while loop | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 while loop diff --git a/while loop b/while loop new file mode 100644 index 00000000..b8a6b9b3 --- /dev/null +++ b/while loop @@ -0,0 +1,15 @@ +// Print numbers from 1 to 5 + +#include +int main() +{ + int i = 1; + + while (i <= 5) + { + printf("%d\n", i); + ++i; + } + + return 0; +} From b944b2367ea5efb0bb9c595b3b5448a7b7f86e33 Mon Sep 17 00:00:00 2001 From: ruchiranjan21 <69226532+ruchiranjan21@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:22:00 +0530 Subject: [PATCH 175/394] Fibonacci Fibonacci series --- Fibonacci | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Fibonacci diff --git a/Fibonacci b/Fibonacci new file mode 100644 index 00000000..88b630aa --- /dev/null +++ b/Fibonacci @@ -0,0 +1,15 @@ +#include +int fib(int n) +{ + if (n <= 1) + return n; + return fib(n-1) + fib(n-2); +} + +int main () +{ + int n = 9; + printf("%d", fib(n)); + getchar(); + return 0; +} From 1a4a21e751b4467b546995f595f0c0fd9470d39a Mon Sep 17 00:00:00 2001 From: lalit19 <38009481+lalit19@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:26:54 +0530 Subject: [PATCH 176/394] Create leapYear program to find the leap year. --- leapYear | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 leapYear diff --git a/leapYear b/leapYear new file mode 100644 index 00000000..7e74f2f1 --- /dev/null +++ b/leapYear @@ -0,0 +1,21 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + +if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + else { + printf("%d is not a leap year.", year); + } + + return 0; +} From 6a40a1a46c13c4f501d6c08c8289b924502b6817 Mon Sep 17 00:00:00 2001 From: vidur-ui <56824234+vidur-ui@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:29:30 +0530 Subject: [PATCH 177/394] adding two numbers in c --- add two numbers in c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 add two numbers in c diff --git a/add two numbers in c b/add two numbers in c new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/add two numbers in c @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} From c54f38cf099ae2d01f1dfd48f1b6fcc92cc2ff1e Mon Sep 17 00:00:00 2001 From: SHAIK SAJEETH Date: Fri, 2 Oct 2020 13:43:26 +0530 Subject: [PATCH 178/394] Swapping numbers --- Swapnumbers | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Swapnumbers diff --git a/Swapnumbers b/Swapnumbers new file mode 100644 index 00000000..98a679ae --- /dev/null +++ b/Swapnumbers @@ -0,0 +1,21 @@ +#include + + int main() + +{ + +int a=10, b=20; + +printf("Before swap a=%d b=%d",a,b); + +a=a+b;//a=30 (10+20) + +b=a-b;//b=10 (30-20) + +a=a-b;//a=20 (30-10) + +printf("\nAfter swap a=%d b=%d",a,b); + +return 0; + +} From 90117ffcdaa1a74d9e1006f4203ac355b8ebf3c0 Mon Sep 17 00:00:00 2001 From: Rishi Sharma <72246887+Rishi0404@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:50:20 +0530 Subject: [PATCH 179/394] Create Covert degree celsius into fahrenheit Source code in c language for converting degree celsius into fahrenheit --- Covert degree celsius into fahrenheit | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Covert degree celsius into fahrenheit diff --git a/Covert degree celsius into fahrenheit b/Covert degree celsius into fahrenheit new file mode 100644 index 00000000..3ac2a733 --- /dev/null +++ b/Covert degree celsius into fahrenheit @@ -0,0 +1,15 @@ + +#include + +int main() +{ + float celsius, fahrenheit; + + printf("Enter temperature in Celsius: "); + scanf("%f", &celsius); + fahrenheit = (celsius * 9 / 5) + 32; + + printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit); + + return 0; +} From cd2afe72bfc20c55f082ba9f830ee5844f775694 Mon Sep 17 00:00:00 2001 From: hackethical <72248570+hackethical@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:51:14 +0530 Subject: [PATCH 180/394] Product of two No. Program for Multiply two Numbers --- Product of two No. | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Product of two No. diff --git a/Product of two No. b/Product of two No. new file mode 100644 index 00000000..bd79f0d0 --- /dev/null +++ b/Product of two No. @@ -0,0 +1,22 @@ +#include +#include + +void main(){ + +int one, two, multiply; + +printf("Enter first number - "); + +scanf("%d",&one); + +printf("Enter second number - "); + +scanf("%d",&two); + +multiply = one * two; + +printf("The multiplication of numbers %d and %d is %d",one,two,multiply); + +getch(); + +} From 4dd9d44fc85ba8c4fcf0f21a45093b3e7e29f60e Mon Sep 17 00:00:00 2001 From: vikashyy08961 <60031737+vikashyy08961@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:56:00 +0530 Subject: [PATCH 181/394] Palindrome --- Palindrome | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Palindrome diff --git a/Palindrome b/Palindrome new file mode 100644 index 00000000..9a3edbd7 --- /dev/null +++ b/Palindrome @@ -0,0 +1,19 @@ +#include +int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=(sum*10)+r; +n=n/10; +} +if(temp==sum) +printf("palindrome number "); +else +printf("not palindrome"); +return 0; +} From eefefb387bc0f5576495a050fe54ddf8585ee0f5 Mon Sep 17 00:00:00 2001 From: ujjwal kumar tiwari <62056777+ujjwaltiwari07@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:01:26 +0530 Subject: [PATCH 182/394] print integer program to print the integer --- program to print integer | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 program to print integer diff --git a/program to print integer b/program to print integer new file mode 100644 index 00000000..907a4197 --- /dev/null +++ b/program to print integer @@ -0,0 +1,14 @@ +#include +int main() { + int number; + + printf("Enter an integer: "); + + // reads and stores input + scanf("%d", &number); + + // displays output + printf("You entered: %d", number); + + return 0; +} From 1c3910dd148c9d65756b7c4d6618f049128d620b Mon Sep 17 00:00:00 2001 From: AdnanSE <72250612+AdnanSE@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:33:27 +0500 Subject: [PATCH 183/394] created new file --- negativeNumber.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 negativeNumber.c diff --git a/negativeNumber.c b/negativeNumber.c new file mode 100644 index 00000000..3beb72fb --- /dev/null +++ b/negativeNumber.c @@ -0,0 +1,18 @@ +// Program to display a number if it is negative + +#include +int main() { + int number; + + printf("Enter an integer: "); + scanf("%d", &number); + + // true if number is less than 0 + if (number < 0) { + printf("You entered %d.\n", number); + } + + printf("The if statement is easy."); + + return 0; +} From cff39d53508668b9cfc6da8b11ce06bf9c14f125 Mon Sep 17 00:00:00 2001 From: Rishi Sharma <72246887+Rishi0404@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:13:29 +0530 Subject: [PATCH 184/394] Create finding the largest element in an array Source code for finding the largest element in an array --- finding the largest element in an array | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 finding the largest element in an array diff --git a/finding the largest element in an array b/finding the largest element in an array new file mode 100644 index 00000000..39b4864b --- /dev/null +++ b/finding the largest element in an array @@ -0,0 +1,21 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From f47b995e04f727a51d36b7030e1a3f3ac1a7713d Mon Sep 17 00:00:00 2001 From: Akashyy <64836641+Akashyy@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:30:44 +0530 Subject: [PATCH 185/394] added the Matrixmultiplication --- Matrixmultiplication.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Matrixmultiplication.c diff --git a/Matrixmultiplication.c b/Matrixmultiplication.c new file mode 100644 index 00000000..6aed5ded --- /dev/null +++ b/Matrixmultiplication.c @@ -0,0 +1,49 @@ +#include +#include +int main(){ +int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; +system("cls"); +printf("enter the number of row="); +scanf("%d",&r); +printf("enter the number of column="); +scanf("%d",&c); +printf("enter the first matrix element=\n"); +for(i=0;i Date: Fri, 2 Oct 2020 14:36:57 +0530 Subject: [PATCH 186/394] Create C program enter 2 integer no --- C program enter 2 integer no | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 C program enter 2 integer no diff --git a/C program enter 2 integer no b/C program enter 2 integer no new file mode 100644 index 00000000..56f4285b --- /dev/null +++ b/C program enter 2 integer no @@ -0,0 +1,23 @@ +#include + +int main() { + + int number1, number2, sum; + + + + printf("Enter two integers: "); + + scanf("%d %d", &number1, &number2); + + // calculating sum + + sum = number1 + number2; + + + + printf("%d + %d = %d", number1, number2, sum); + + return 0; + +} From 90a3818cc7ae6f9baf3ae13e35fadbff22f48ce5 Mon Sep 17 00:00:00 2001 From: PriyaKaushik890 <64940946+PriyaKaushik890@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:37:19 +0530 Subject: [PATCH 187/394] swapping of two numbers. Program to swap two numbers using third variable in C. --- swapping of two numbers | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 swapping of two numbers diff --git a/swapping of two numbers b/swapping of two numbers new file mode 100644 index 00000000..0bed3c7f --- /dev/null +++ b/swapping of two numbers @@ -0,0 +1,19 @@ + +// C program to swap two variables +#include + +int main() +{ + int x, y; + printf("Enter Value of x "); + scanf("%d", &x); + printf("\nEnter Value of y "); + scanf("%d", &y); + + int temp = x; + x = y; + y = temp; + + printf("\nAfter Swapping: x = %d, y = %d", x, y); + return 0; +} From 8eb25edef4f286fa88a7832367c5a6a5ac62d3e7 Mon Sep 17 00:00:00 2001 From: Mayank Pathak Date: Fri, 2 Oct 2020 14:38:14 +0530 Subject: [PATCH 188/394] Count largest elements in Array Program to count the largest element in array-hackerRank solution for Birthday Cake Candles --- Count largest elements in Array | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Count largest elements in Array diff --git a/Count largest elements in Array b/Count largest elements in Array new file mode 100644 index 00000000..9701c76b --- /dev/null +++ b/Count largest elements in Array @@ -0,0 +1,34 @@ +#include +/* Given by Mayank Pathak */ +int main() +{ + int n,i,large=0,count=0; + scanf("%d",&n); + int a[n]; + for(i=0;ilarge) + { + large=a[i]; + } + } + + //Counting the large element + for(i=0;i Date: Fri, 2 Oct 2020 14:44:34 +0530 Subject: [PATCH 189/394] Create febonacci series --- febonacci series | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 febonacci series diff --git a/febonacci series b/febonacci series new file mode 100644 index 00000000..e9f5157b --- /dev/null +++ b/febonacci series @@ -0,0 +1,17 @@ +# febonacci series +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From eaee6af5be1455fb425cc95bf9d9791abc26d89d Mon Sep 17 00:00:00 2001 From: saketh_gollapudi <54179083+saketh018@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:50:17 +0530 Subject: [PATCH 190/394] Merge two sorted arrays An easier approach to merge two sorted arrays would be by traversing both the arrays to keep track of current element in both the arrays, finding the least value among the two and updating the final array with the least value --- Merge two sorted arrays | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Merge two sorted arrays diff --git a/Merge two sorted arrays b/Merge two sorted arrays new file mode 100644 index 00000000..3937a3a9 --- /dev/null +++ b/Merge two sorted arrays @@ -0,0 +1,63 @@ +#include +#include +int merge_two_sorted_arrays(int arr1[], int arr2[], int arr3[], int m, int n) +{ +int i,j,k; +i = j = k = 0; +for(i=0;i < m && j < n;) +{ +if(arr1[i] < arr2[j]) +{ +arr3[k] = arr1[i]; +k++; +i++; +} +else +{ +arr3[k] = arr2[j]; +k++; +j++; +} +} +while(i < m) +{ +arr3[k] = arr1[i]; +k++; +i++; +} +while(j < n) +{ +arr3[k] = arr2[j]; +k++; +j++; +} +} +int main() +{ +int n,m; +printf("\nEnter the size of Array 1 : "); +scanf("%d",&m); +printf("\nEnter the size of Array 2 : "); +scanf("%d",&n); +int arr1[m],arr2[n]; +int arr3[m+n]; +int i; +printf("\nInput the Array 1 elements : "); +for(i = 0; i < m; i++) +{ +scanf("%d",&arr1[i]); +} +printf("\nInput the Array 2 elements : "); +for(i = 0;i Date: Fri, 2 Oct 2020 14:54:31 +0530 Subject: [PATCH 191/394] Finding number of tickets required . this is basically finding the number of tickets need for particular seats in bus or train. --- findingtickets | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 findingtickets diff --git a/findingtickets b/findingtickets new file mode 100644 index 00000000..c35f8997 --- /dev/null +++ b/findingtickets @@ -0,0 +1,18 @@ +#include + +int main() +{ + int num_s,tickets,r; + printf("please enter number of rows!!"); + scanf("%d",&r); + printf("please enter number of seats!!"); + scanf("%d",&num_s); + printf("please enter number of tickets!!"); + scanf("%d",&tickets); + int n=r*num_s; + if(n>tickets) + printf("Opps!! tickets is less then number of seats:)"); + else + printf("%d %d",n,tickets-n); + +} From 75454388bff72ff18b6fb8747d331cc53e272e56 Mon Sep 17 00:00:00 2001 From: Aayush Thakur Date: Fri, 2 Oct 2020 15:02:05 +0530 Subject: [PATCH 192/394] Armstrong Number How to find armstrong number using c --- Armstrong Number | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Armstrong Number diff --git a/Armstrong Number b/Armstrong Number new file mode 100644 index 00000000..12d5f697 --- /dev/null +++ b/Armstrong Number @@ -0,0 +1,24 @@ +#include +int main() { + int num, originalNum, remainder, result = 0; + printf("Enter a three-digit integer: "); + scanf("%d", &num); + originalNum = num; + + while (originalNum != 0) { + // remainder contains the last digit + remainder = originalNum % 10; + + result += remainder * remainder * remainder; + + // removing last digit from the orignal number + originalNum /= 10; + } + + if (result == num) + printf("%d is an Armstrong number.", num); + else + printf("%d is not an Armstrong number.", num); + + return 0; +} From 69e00116bff3930929c60061ad1b33641408bc50 Mon Sep 17 00:00:00 2001 From: sayali1-deshmukh Date: Fri, 2 Oct 2020 15:31:46 +0530 Subject: [PATCH 193/394] Missing number to find the missing number --- Find missing number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Find missing number diff --git a/Find missing number b/Find missing number new file mode 100644 index 00000000..20dc8287 --- /dev/null +++ b/Find missing number @@ -0,0 +1,20 @@ +#include + +/* getMissingNo takes array and size of array as arguments*/ +int getMissingNo(int a[], int n) +{ + int i, total; + total = (n + 1) * (n + 2) / 2; + for (i = 0; i < n; i++) + total -= a[i]; + return total; +} + +/*program to test above function */ +int main() +{ + int a[] = { 1, 2, 4, 5, 6 }; + int miss = getMissingNo(a, 5); + printf("%d", miss); + getchar(); +} From 94f7338cb7dee8f46e1a82857ebf0a4a3a805e79 Mon Sep 17 00:00:00 2001 From: shubhamkr83 <72254047+shubhamkr83@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:36:55 +0530 Subject: [PATCH 194/394] C program Program to Add Two Integers --- sum of two no. | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sum of two no. diff --git a/sum of two no. b/sum of two no. new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/sum of two no. @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} From 860f397b318cbd5d7ac832ea585c127db467ccad Mon Sep 17 00:00:00 2001 From: amitdas2000 <72251886+amitdas2000@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:45:18 +0530 Subject: [PATCH 195/394] greater number program to find greatest of two number in c --- greater number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 greater number diff --git a/greater number b/greater number new file mode 100644 index 00000000..73c31935 --- /dev/null +++ b/greater number @@ -0,0 +1,15 @@ +#include +#include +int main() +{ + int a, b, big; + printf("Enter any two number: "); + scanf("%d%d", &a, &b); + if(a>b) + big=a; + else + big=b; + printf("\nBiggest of the two number is: %d", big); + getch(); + return 0; +} From f18dd0edfdea0f680dfd6889c7e7a9c0a633c625 Mon Sep 17 00:00:00 2001 From: SATHIYASEELAN2001 <72245770+SATHIYASEELAN2001@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:47:01 +0530 Subject: [PATCH 196/394] addnos Program to Add two numbers in C --- addnos | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 addnos diff --git a/addnos b/addnos new file mode 100644 index 00000000..a1f72afe --- /dev/null +++ b/addnos @@ -0,0 +1,12 @@ + Program to Add two numbers in C + +#include +int main() +{ +int number1, number2, sum; +printf("Enter two integers: "); +scanf("%d %d", &number1, &number2); +sum = number1 + number2; +printf("%d + %d = %d", number1, number2, sum); +return 0; +} From 90500ff8fd7cb44a74e59ef56d1c73878bb50331 Mon Sep 17 00:00:00 2001 From: vikrantneve <56770834+vikrantneve@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:47:17 +0530 Subject: [PATCH 197/394] pascaltriangle C program to print Pascal's triangle by taking input from user. --- pascaltriangle | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 pascaltriangle diff --git a/pascaltriangle b/pascaltriangle new file mode 100644 index 00000000..f2764093 --- /dev/null +++ b/pascaltriangle @@ -0,0 +1,20 @@ + +#include +int main() { + int rows, coef = 1, space, i, j; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 0; i < rows; i++) { + for (space = 1; space <= rows - i; space++) + printf(" "); + for (j = 0; j <= i; j++) { + if (j == 0 || i == 0) + coef = 1; + else + coef = coef * (i - j + 1) / j; + printf("%4d", coef); + } + printf("\n"); + } + return 0; +} From a0de5d267c0c81c20ffaeaa6509287191e47ef27 Mon Sep 17 00:00:00 2001 From: Harsh-r-c <62848594+Harsh-r-c@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:50:10 +0530 Subject: [PATCH 198/394] fibonacci series The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. --- fibonacci | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibonacci diff --git a/fibonacci b/fibonacci new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/fibonacci @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 2acdecb7e6b3180f4f92bbefa5bde81507d16f1f Mon Sep 17 00:00:00 2001 From: arpitsharma17 <54912241+arpitsharma17@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:54:43 +0530 Subject: [PATCH 199/394] Merge two arrays C program to merge two arrays --- Merge two arrays | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Merge two arrays diff --git a/Merge two arrays b/Merge two arrays new file mode 100644 index 00000000..ea923446 --- /dev/null +++ b/Merge two arrays @@ -0,0 +1,66 @@ +#include +void merge(int [], int, int [], int, int []); + +int main() { + int a[100], b[100], m, n, c, sorted[200]; + + printf("Input number of elements in first array\n"); + scanf("%d", &m); + + printf("Input %d integers\n", m); + for (c = 0; c < m; c++) { + scanf("%d", &a[c]); + } + + printf("Input number of elements in second array\n"); + scanf("%d", &n); + + printf("Input %d integers\n", n); + for (c = 0; c < n; c++) { + scanf("%d", &b[c]); + } + + merge(a, m, b, n, sorted); + + printf("Sorted array:\n"); + + for (c = 0; c < m + n; c++) { + printf("%d\n", sorted[c]); + } + + return 0; +} + +void merge(int a[], int m, int b[], int n, int sorted[]) { + int i, j, k; + + j = k = 0; + + for (i = 0; i < m + n;) { + if (j < m && k < n) { + if (a[j] < b[k]) { + sorted[i] = a[j]; + j++; + } + else { + sorted[i] = b[k]; + k++; + } + i++; + } + else if (j == m) { + for (; i < m + n;) { + sorted[i] = b[k]; + k++; + i++; + } + } + else { + for (; i < m + n;) { + sorted[i] = a[j]; + j++; + i++; + } + } + } +} From 0135a5d4e1c5540ac7fde9d479fba738c9ee1bbd Mon Sep 17 00:00:00 2001 From: ShrutiPandey27 <69622082+ShrutiPandey27@users.noreply.github.com> Date: Fri, 2 Oct 2020 16:03:06 +0530 Subject: [PATCH 200/394] find the duplicate characters in a given string In this program I have used very simple idea to find duplicate characters in a string in C Language --- ...find duplicate character in a given string | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 c program to find duplicate character in a given string diff --git a/c program to find duplicate character in a given string b/c program to find duplicate character in a given string new file mode 100644 index 00000000..3dea56fa --- /dev/null +++ b/c program to find duplicate character in a given string @@ -0,0 +1,33 @@ +#include +#include + +int main() +{ + +int i,j,len,v=1; +char str[100]; + +printf("enter string : "); +scanf("%[^\n]%c",str); + +len=strlen(str); + +printf("duplicates character found in the string are: "); + for(i=0;i Date: Fri, 2 Oct 2020 16:58:46 +0530 Subject: [PATCH 201/394] ReverseString A Simple Program to Find Reverse String in C Language. --- ...erse a String using C programming Language | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 How to Reverse a String using C programming Language diff --git a/How to Reverse a String using C programming Language b/How to Reverse a String using C programming Language new file mode 100644 index 00000000..16834b69 --- /dev/null +++ b/How to Reverse a String using C programming Language @@ -0,0 +1,22 @@ +#include +#include +void main() +{ + int i, j, k; + char str[100]; + char rev[100]; + printf("Enter a string:\t"); + scanf("%s", str); + printf("The original string is %s\n", str); + for(i = 0; str[i] != '\0'; i++); + { + k = i-1; + } + for(j = 0; j <= i-1; j++) + { + rev[j] = str[k]; + k--; + } + printf("The reverse string is %s\n", rev); + getch(); +} From 82466d77f1ef56d5927e07157fb6539d0f0a77ba Mon Sep 17 00:00:00 2001 From: suddodhan <68599647+suddodhan@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:58:34 +0530 Subject: [PATCH 202/394] greatearno Calculator in c Program --- greatearno | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 greatearno diff --git a/greatearno b/greatearno new file mode 100644 index 00000000..a8bd462a --- /dev/null +++ b/greatearno @@ -0,0 +1,29 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} From 40fbc59266214f0d4ddcd67843c87af5fd71f939 Mon Sep 17 00:00:00 2001 From: Pranav N Date: Fri, 2 Oct 2020 18:02:16 +0530 Subject: [PATCH 203/394] PascalTrinagle --- PascalTriangle.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 PascalTriangle.cpp diff --git a/PascalTriangle.cpp b/PascalTriangle.cpp new file mode 100644 index 00000000..43feabdc --- /dev/null +++ b/PascalTriangle.cpp @@ -0,0 +1,30 @@ + +#include +#include +using namespace std; + + vector> pascal(int numRows) { + vector> res(numRows); + for(int i=0;i>row; + vector> res(row); + res=pascal(row); + for(int i=0;i Date: Fri, 2 Oct 2020 18:14:55 +0530 Subject: [PATCH 204/394] Create printing pattern --- printing pattern | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 printing pattern diff --git a/printing pattern b/printing pattern new file mode 100644 index 00000000..70a1a944 --- /dev/null +++ b/printing pattern @@ -0,0 +1,13 @@ +#include +int main() { + int i, j, rows; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 1; i <= rows; ++i) { + for (j = 1; j <= i; ++j) { + printf("* "); + } + printf("\n"); + } + return 0; +} From 23a9c471f30c3140a70c4b764df3117326a15371 Mon Sep 17 00:00:00 2001 From: target-manish <72259968+target-manish@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:17:55 +0530 Subject: [PATCH 205/394] greatorno Program to find greatest of three numbers in c. --- greatorno | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 greatorno diff --git a/greatorno b/greatorno new file mode 100644 index 00000000..35025350 --- /dev/null +++ b/greatorno @@ -0,0 +1,18 @@ +#include +int main() +{ + int num1,num2,num3; + + //Ask user to input any three integer numbers + printf("\nEnter value of num1, num2 and num3:"); + //Store input values in variables for comparsion + scanf("%d %d %d",&num1,&num2,&num3); + + if((num1>num2)&&(num1>num3)) + printf("\n Number1 is greatest"); + else if((num2>num3)&&(num2>num1)) + printf("\n Number2 is greatest"); + else + printf("\n Number3 is greatest"); + return 0; +} From 9fb94ce0eed9e128507af662793eed6caa3a3bc6 Mon Sep 17 00:00:00 2001 From: Pranav29g <56110593+Pranav29g@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:18:18 +0530 Subject: [PATCH 206/394] reverse the digits of a number this program in c language reverse the digits of a number --- reverse_digits | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 reverse_digits diff --git a/reverse_digits b/reverse_digits new file mode 100644 index 00000000..57d7d952 --- /dev/null +++ b/reverse_digits @@ -0,0 +1,23 @@ +#include + +/* Iterative function to reverse digits of num*/ +int reversDigits(int num) +{ + int rev_num = 0; + while(num > 0) + { + rev_num = rev_num*10 + num%10; + num = num/10; + } + return rev_num; +} + +/*Driver program to test reversDigits*/ +int main() +{ + int num = 3217; + printf("Reverse of no. is %d", reversDigits(num)); + + getchar(); + return 0; +} From 25ddb4f6f219aa5c91ea1bc8dd2c76b588ac9a11 Mon Sep 17 00:00:00 2001 From: Azbar-coder <70653674+Azbar-coder@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:24:19 +0530 Subject: [PATCH 207/394] GreaterNumber Program to find greatest of two numbers in C --- GreaterNumber | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 GreaterNumber diff --git a/GreaterNumber b/GreaterNumber new file mode 100644 index 00000000..44608557 --- /dev/null +++ b/GreaterNumber @@ -0,0 +1,24 @@ +/* C Program to Find Largest of Two numbers */ + +#include + +int main() { + int a, b; + printf("Please Enter Two different values\n"); + scanf("%d %d", &a, &b); + + if(a > b) + { + printf("%d is Largest\n", a); + } + else if (b > a) + { + printf("%d is Largest\n", b); + } + else + { + printf("Both are Equal\n"); + } + + return 0; +} From c65dad525e0442f757135dadeebb368c67062e5f Mon Sep 17 00:00:00 2001 From: SATHIYA2001 <72261144+SATHIYA2001@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:33:01 +0530 Subject: [PATCH 208/394] product Program to multiply two numbers --- product | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product diff --git a/product b/product new file mode 100644 index 00000000..9ddd14a1 --- /dev/null +++ b/product @@ -0,0 +1,16 @@ +Program to Multiply Two Numbers + +#include +int main() { + double a, b, product; + printf("Enter two numbers: "); + scanf("%lf %lf", &a, &b); + + + product = a * b; + + + printf("Product = %.2lf", product); + + return 0; +} From bf063243d8416ba6f9d9fa6231ade9267c7c999b Mon Sep 17 00:00:00 2001 From: sid050 <60535097+sid050@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:42:40 +0530 Subject: [PATCH 209/394] Tic_Tac_Toe A simple Tic Tac Toe game --- Tac Toe game | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 Tac Toe game diff --git a/Tac Toe game b/Tac Toe game new file mode 100644 index 00000000..521f347d --- /dev/null +++ b/Tac Toe game @@ -0,0 +1,284 @@ +#include +#include +#include +#include + +int board[10] = {2,2,2,2,2,2,2,2,2,2}; +int turn = 1,flag = 0; +int player,comp; + +void menu(); +void go(int n); +void start_game(); +void check_draw(); +void draw_board(); +void player_first(); +void put_X_O(char ch,int pos); +COORD coord= {0,0}; // this is global variable +//center of axis is set to the top left cornor of the screen +void gotoxy(int x,int y) +{ + coord.X=x; + coord.Y=y; + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); +} + +void main() +{ + system("cls"); + menu(); + getch(); + +} + +void menu() +{ + int choice; + system("cls"); + printf("\n--------MENU--------"); + printf("\n1 : Play with X"); + printf("\n2 : Play with O"); + printf("\n3 : Exit"); + printf("\nEnter your choice:>"); + scanf("%d",&choice); + turn = 1; + switch (choice) + { + case 1: + player = 1; + comp = 0; + player_first(); + break; + case 2: + player = 0; + comp = 1; + start_game(); + break; + case 3: + exit(1); + default: + menu(); + } +} + +int make2() +{ + if(board[5] == 2) + return 5; + if(board[2] == 2) + return 2; + if(board[4] == 2) + return 4; + if(board[6] == 2) + return 6; + if(board[8] == 2) + return 8; + return 0; +} + +int make4() +{ + if(board[1] == 2) + return 1; + if(board[3] == 2) + return 3; + if(board[7] == 2) + return 7; + if(board[9] == 2) + return 9; + return 0; +} + +int posswin(int p) +{ +// p==1 then X p==0 then O + int i; + int check_val,pos; + + if(p == 1) + check_val = 18; + else + check_val = 50; + + i = 1; + while(i<=9)//row check + { + if(board[i] * board[i+1] * board[i+2] == check_val) + { + if(board[i] == 2) + return i; + if(board[i+1] == 2) + return i+1; + if(board[i+2] == 2) + return i+2; + } + i+=3; + } + + i = 1; + while(i<=3)//column check + { + if(board[i] * board[i+3] * board[i+6] == check_val) + { + if(board[i] == 2) + return i; + if(board[i+3] == 2) + return i+3; + if(board[i+6] == 2) + return i+6; + } + i++; + } + + if(board[1] * board[5] * board[9] == check_val) + { + if(board[1] == 2) + return 1; + if(board[5] == 2) + return 5; + if(board[9] == 2) + return 9; + } + + if(board[3] * board[5] * board[7] == check_val) + { + if(board[3] == 2) + return 3; + if(board[5] == 2) + return 5; + if(board[7] == 2) + return 7; + } + return 0; +} + +void go(int n) +{ + if(turn % 2) + board[n] = 3; + else + board[n] = 5; + turn++; +} + +void player_first() +{ + int pos; + + check_draw(); + draw_board(); + gotoxy(30,18); + printf("Your Turn :> "); + scanf("%d",&pos); + + if(board[pos] != 2) + player_first(); + + if(pos == posswin(player)) + { + go(pos); + draw_board(); + gotoxy(30,20); + //textcolor(128+RED); + printf("Player Wins"); + getch(); + exit(0); + } + + go(pos); + draw_board(); + start_game(); +} + +void start_game() +{ +// p==1 then X p==0 then O + if(posswin(comp)) + { + go(posswin(comp)); + flag = 1; + } + else if(posswin(player)) + go(posswin(player)); + else if(make2()) + go(make2()); + else + go(make4()); + draw_board(); + + if(flag) + { + gotoxy(30,20); + //textcolor(128+RED); + printf("Computer wins"); + getch(); + } + else + player_first(); +} + +void check_draw() +{ + if(turn > 9) + { + gotoxy(30,20); + //textcolor(128+RED); + printf("Game Draw"); + getch(); + exit(0); + } +} + +void draw_board() +{ + int j; + + for(j=9; j<17; j++) + { + gotoxy(35,j); + printf("| |"); + } + gotoxy(28,11); + printf("-----------------------"); + gotoxy(28,14); + printf("-----------------------"); + + for(j=1; j<10; j++) + { + if(board[j] == 3) + put_X_O('X',j); + else if(board[j] == 5) + put_X_O('O',j); + } +} + +void put_X_O(char ch,int pos) +{ + int m; + int x = 31, y = 10; + + m = pos; + + if(m > 3) + { + while(m > 3) + { + y += 3; + m -= 3; + } + } + if(pos % 3 == 0) + x += 16; + else + { + pos %= 3; + pos--; + while(pos) + { + x+=8; + pos--; + } + } + gotoxy(x,y); + printf("%c",ch); +} From 417103bd4e3d81101328225f5064cde7f6d41c76 Mon Sep 17 00:00:00 2001 From: gajendranmori <34879572+gajendranmori@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:44:47 +0530 Subject: [PATCH 210/394] calculator Write a c program to create calculator using switch case --- calculator | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 calculator diff --git a/calculator b/calculator new file mode 100644 index 00000000..a8bd462a --- /dev/null +++ b/calculator @@ -0,0 +1,29 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} From ee690458afbd08df705098e2f1fa9b893c99c113 Mon Sep 17 00:00:00 2001 From: SHARIQ78692 <72261692+SHARIQ78692@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:50:57 +0530 Subject: [PATCH 211/394] Palindromenumbercheck This program is strictly written in C language to check whether a given number is palindrome or not. --- palindromecheck | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 palindromecheck diff --git a/palindromecheck b/palindromecheck new file mode 100644 index 00000000..2d0bd1c7 --- /dev/null +++ b/palindromecheck @@ -0,0 +1,18 @@ +int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=(sum*10)+r; +n=n/10; +} +if(temp==sum) +printf("palindrome number "); +else +printf("not palindrome"); +return 0; +} From 59afd71f64d69b2aa86000c53b21803400ee3bbc Mon Sep 17 00:00:00 2001 From: Vishnu Santhosh Date: Fri, 2 Oct 2020 06:21:21 -0700 Subject: [PATCH 212/394] basicgameinc A basic roll game in C Language --- basicgameinc | 509 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 509 insertions(+) create mode 100644 basicgameinc diff --git a/basicgameinc b/basicgameinc new file mode 100644 index 00000000..8dad81bb --- /dev/null +++ b/basicgameinc @@ -0,0 +1,509 @@ +#include +#include +#include +#include +#include +#define MAX 10 +#define A "P" +#define B "Q" +int getRandom(int low, int high); +int getValidInteger(int low, int high); +unsigned int playerRoll(int low, int high); + +void seed(void) +{ + srand(time(NULL)); +} +void space(unsigned int size) // create space +{ + printf(" "); +} +char getDisplayType(unsigned int index, unsigned int playerPosition, char playerName) // check the index and return character +{ + + if (playerName != '#') + { + if (index == playerPosition) + return playerName; + + if (index == 0) + return ('C'); + + if (index % 3 == 0) + if (index % 5 == 0) + if (index % 7 == 0) + return('G'); + else return ('L'); + else return ('W'); + + if (index % 5 == 0) + if (index % 7 == 0) + return('G'); + else return ('L'); + + if (index % 7 == 0) { + return('G'); + } + else return (' '); + } + + if (playerName == '#') + { + + if (index == 0) + return ('C'); + + if (index % 3 == 0) { + if (index % 5 == 0) { + if (index % 7 == 0) { + return('G'); + } + else return ('L'); + } + else return ('W'); + } + + if (index % 5 == 0) { + if (index % 7 == 0) { + return('G'); + } + else return ('L'); + } + if (index % 7 == 0) { + return('G'); + } + else + return (' '); + + + + } +} +void firstLine(unsigned int size) // create the upper line of the square for the first and last line +{ + int i; + + for (i = 0; i < size; i++) + { + printf(" ___ "); + } + printf("\n"); +} + +void secondLine(unsigned int size, unsigned int i, unsigned int playerPosition, char playerName) //create the inside and return the type for the first line +{ + int x, j; + for (j = 0; j < size; j++) + { + x = j; + printf("| %c |", getDisplayType(x, playerPosition, playerName)); + } + printf("\n"); +} + +void secondLine2nd(unsigned int size, unsigned int i, unsigned int playerPosition, char playerName) { //create the inside and return the type for the last line + int x, y, z; + y = 3 * (size - 1); + printf("| %c |", getDisplayType(y, playerPosition, playerName)); + for (i = 0; i < size - 2; i++) + { + z = 2 * (size - 1) + ((size - 2) - i); + printf("| %c |", getDisplayType(z, playerPosition, playerName)); + } + x = size + i; + printf("| %c |", getDisplayType(x, playerPosition, playerName)); + + + printf("\n"); +} + + +void thirdLine(unsigned int size) // create lower line for the first and last line +{ + int i; + + for (i = 0; i < size; i++) + { + printf("|___|"); + } + printf("\n"); +} +void upperrow(unsigned int size) // create the upper line for the square of the row +{ + int i; + printf(" ___"); + for (i = 0; i < size - 2; i++) { + space(size); + } + printf(" ___"); + printf("\n"); +} + +void lowerrow(unsigned int size) //create the lower line for the square of the row +{ + int i; + printf("|___|"); + for (i = 0; i < size - 2; i++) { + space(size); + } + + printf("|___|"); + printf("\n"); +} + +void middlerow(unsigned int size, unsigned int i, unsigned int playerPosition, char playerName) //create the inside and return the type for the square of the row +{ + int q, b, p; + b = i; + q = 3 * (size - 1) + ((size - 1) - i); + printf("| %c |", getDisplayType(q, playerPosition, playerName)); + for (b = 0; b < size - 2; b++) { + space(size); + } + p = size - 1 + i; + printf("| %c |", getDisplayType(p, playerPosition, playerName)); + printf("\n"); +} + + +char getValidCharacter(char a, char b) //make sure the character input is right// +{ + char c, choice; + do { + scanf_s("%c", &choice); + getchar(); + if ((choice != 'p' && choice != 'q' && choice != 'r' && choice != 's')) + { + printf("Invalid input, please try again: "); + } + } while (choice != 'p' && choice != 'q' && choice != 'r' && choice != 's'); + return choice; +} + +int getValidInteger(int low, int high) //validate the input number// +{ + int a; int choice; + do { + a = scanf_s("%d", &choice); + if (choice high) + { + printf("Invalid input, please try again: "); + } + + } while (choice < low || choice > high); + return choice; +} + +int getRandom(int low, int high) //get a rando number +{ + int a; + a = rand() % (high - low) + low; + + return a; +} + +unsigned int playerRoll(int low, int high) //prompt and output the roll +{ + int a = 1, b, c, d, e, choice; + do { + printf("\nyour turn, how many dice will you roll : "); + scanf_s("%d", &choice); + if (choice == 1) + { + b = getRandom(low, high); + //printf("b: \n"); + //scanf_s("%d", &b); + printf("You rolled %d\n", b); + printf("Advancing %d space\n", b); + a = 0; + return b; + } + else if (choice == 2) + { + c = getRandom(low, high); + //printf("c: "); + //scanf_s("%d", &c); + d = getRandom(low, high); + //printf("d: "); + //scanf_s("%d", &d); + b = c + d; + printf("You rolled %d %d\n ", c, d); + printf("Advancing %d space\n", b); + a = 0; + return b; + } + else if (choice == 3) { + c = getRandom(low, high); + d = getRandom(low, high); + e = getRandom(low, high); + b = c + d + e; + printf("You rolled %d %d %d\n ", c, d, e); + printf("Advancing %d space\n", b); + a = 0; + return b; + } + else + printf("Try again,"); + } while (a = 1); +} + +void winPrize(int playerPrizes[], unsigned int* prizeCount) //do the winprize function +{ + int i; + unsigned int prize; + prize = getRandom(10, 100); + printf("%d\n", prize); + if (*prizeCount < MAX) + { + playerPrizes[*prizeCount] = prize; + printf("you won a prize of %d\n", prize); + *prizeCount = *prizeCount + 1; + } + else + printf("Your inventory is full \n"); +} +void winGrandPrize(int playerPrizes[], unsigned int* prizeCount) // do the win grand prize function +{ + int i; + unsigned int prize; + prize = getRandom(100, 200); + printf("%d\n", prize); + if (*prizeCount < MAX) + { + playerPrizes[*prizeCount] = prize; + printf("you won a grand prize of %d\n", prize); + *prizeCount = *prizeCount + 1; + } + else + printf("Your inventory is full "); +} +int loseItem(int playerPrizes[], unsigned int *prizeCount) // do the loseitem fuction +{ + int i, j, k, r, ran = 2; + + if (*prizeCount == 0) + { + printf("Nothing happened,Move On\n"); + } + else + { + + ran = getRandom(0, *prizeCount); + playerPrizes[ran] = 0; + *prizeCount = *prizeCount - 1; + printf("you lost the prize"); + for (i = ran - 1; i < MAX; i++) //arange the array in order + for (j = i; j < MAX; j++) + if (playerPrizes[i] == 0) + { + k = playerPrizes[i]; + playerPrizes[i] = playerPrizes[j]; + playerPrizes[j] = k; + } + + } +} + + +void initPlayer(int *playerScore, int playerPrizes[], unsigned int *prizeCount, char *playerName, int *playerPosition) //do the initplayer function, set everything to 0 +{ + int i; + playerPrizes[MAX] = 0; + + *playerScore = 0; + printf("playerPrizes: %d\n", playerPrizes[MAX]); + *prizeCount = 0; + *playerPosition = 0; + printf("Enter Player ID: "); + scanf_s("%c", playerName); +} + + + + +void displayBoard(unsigned int size, unsigned int playerPosition, char playerName) //display the boardgame +{ + + int k, size1, loop; + float loop2, playerPosition1, size2; + //printf("player name in display board: %c\n", playerName); + //printf("%d\n", r); + //printf("%d", playerPosition); + playerPosition1 = (float)playerPosition; + size1 = (4 * (size - 1)); + + size2 = (float)size1; + //printf("size2: %.2f\n", size2); + // printf("playerPo1: %.2f\n", playerPosition1); + //playerPosition2 = float size; + //printf("playerPos: %d\n", playerPosition); + loop2 = playerPosition1 / size2; + + loop = trunc(loop2); + + + k = playerPosition - (4 * (size - 1))*loop; + + playerPosition = k; + + { + int i = 0; + if (size == 1) + { + printf(" ___ \n"); + printf(" | ? | \n"); + printf(" |___|"); + printf("\n"); + } + else { + + for (i = 0; i < size - 1; i++) + { + + if (i == 0) + { + firstLine(size); + secondLine(size, i, playerPosition, playerName); + thirdLine(size); + } + } + for (i = 1; i < size - 1; i++) + { + upperrow(size); + middlerow(size, i, playerPosition, playerName); + lowerrow(size); + } + for (i = size - 2; i < size - 1; i++) + { + firstLine(size); + secondLine2nd(size, i, playerPosition, playerName); + thirdLine(size); + } + } + } +} + +int checkout(int *playerScore, int playerPrizes[], unsigned int* prizeCount) //do the checkout +{ + int i; + for (i = 0; i < *prizeCount; i++) + *playerScore += playerPrizes[i]; + *prizeCount = 0; + printf("You check out for $%d score is now: $%d \n", *playerScore, *playerScore); + if (*playerScore >= 200) + { + return 1; + } + else + { + return 0; + } + +} + + +void playGame(unsigned int size, int *playerScore, int playerPrizes[], unsigned int *prizeCount, char *playerName, int* playerPosition) //play the game +{ + printf("playerName in playgame %c\n", *playerName); + //printf("%d\n",*prizeCount); + //printf("%d\n", *playerScore); + int i, l = 1; + while (l) + { + displayBoard(size, *playerPosition, *playerName); + + printf("Score: %d inventory (%d items): ", *playerScore, *prizeCount); + for (i = 0; i < *prizeCount; i++) { + printf("%d, ", playerPrizes[i]); + + } + + *playerPosition = *playerPosition + playerRoll(1, 6); + if (*playerPosition >= 4 * (size - 1)) + *playerPosition = *playerPosition - 4 * (size - 1); + //printf("player position in display %d\n", *playerPosition); + //printf("display type in play game: %c\n", getDisplayType(*playerPosition, *playerPosition, '#')); + //displayBoard(boardSize, playerPosition, playerName); + if (getDisplayType(*playerPosition, *playerPosition, '#') == 'G') + { + winGrandPrize(playerPrizes, prizeCount); + } + else if (getDisplayType(*playerPosition, *playerPosition, '#') == 'W') + { + + winPrize(playerPrizes, prizeCount); + } + else if (getDisplayType(*playerPosition, *playerPosition, '#') == 'L') + { + + loseItem(playerPrizes, prizeCount); + } + else if (getDisplayType(*playerPosition, *playerPosition, '#') == 'C') + { + + + if (checkout(playerScore, playerPrizes, prizeCount) == 1) + { + printf("You Win\n"); + l = 0; + } + } + else + printf("nothing happens, go again.\n"); + } +} + + + + + + + +int main(void) +{ + int i, l = 1; + char a, choice; + char c = '#'; + int playerScore; + int playerPrizes[MAX]; + unsigned int prizeCount; + char playerName; + unsigned int size; + unsigned int playerPosition; + printf("Welcome to CHECKOUT\n"); + while (l) { + printf("Main Menu\n"); + printf("p-(p)lay q-(q)uit r-inst(r)uctions s-HI(s)core: \n"); + choice = getValidCharacter('P', 'Q'); + if (choice == 'p') { + printf("Number of players is 1\n"); + initPlayer(&playerScore, playerPrizes, &prizeCount, &playerName, &playerPosition); + + printf("Enter board size: "); + scanf_s("%d", &size); + + playGame(size, &playerScore, playerPrizes, &prizeCount, &playerName, &playerPosition); + + + + getchar(); + + } + if (choice == 's') + { + printf("--\n"); + printf(" \\ "); + printf("_______\n"); + printf(" \\++++++|\n"); + printf(" \\=====|\n"); + printf(" 0--- 0\n"); + printf("HI SCORE: %d Player Name: %c \n", playerScore, playerName); + } + if (choice == 'q') + { + printf("dont go, I will miss you :("); + l = 0; + getchar(); + } + } +} From f15d80a543baa384a1adeafe1412df51318caf2f Mon Sep 17 00:00:00 2001 From: anuja2930 <72262408+anuja2930@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:59:12 +0530 Subject: [PATCH 213/394] grester number 3 C Program to Find the Biggest of 3 Numbers --- greaternumber | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 greaternumber diff --git a/greaternumber b/greaternumber new file mode 100644 index 00000000..21c18ea9 --- /dev/null +++ b/greaternumber @@ -0,0 +1,28 @@ +/* + * C program to find the biggest of three numbers + */ +#include + +void main() +{ + int num1, num2, num3; + + printf("Enter the values of num1, num2 and num3\n"); + scanf("%d %d %d", &num1, &num2, &num3); + printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3); + if (num1 > num2) + { + if (num1 > num3) + { + printf("num1 is the greatest among three \n"); + } + else + { + printf("num3 is the greatest among three \n"); + } + } + else if (num2 > num3) + printf("num2 is the greatest among three \n"); + else + printf("num3 is the greatest among three \n"); +} From ab7fd4e19ed07aabe74e5357e267464b790d8c5a Mon Sep 17 00:00:00 2001 From: Pranav29g <56110593+Pranav29g@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:10:31 +0530 Subject: [PATCH 214/394] calculate compound interest this c program allows user to calculate compoudt interest for his or her investments --- compond_interest | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 compond_interest diff --git a/compond_interest b/compond_interest new file mode 100644 index 00000000..91042da4 --- /dev/null +++ b/compond_interest @@ -0,0 +1,25 @@ +#include +#include + +int main() +{ + float principle, rate, time, CI; + + /* Input principle, time and rate */ + printf("Enter principle (amount): "); + scanf("%f", &principle); + + printf("Enter time: "); + scanf("%f", &time); + + printf("Enter rate: "); + scanf("%f", &rate); + + /* Calculate compound interest */ + CI = principle* (pow((1 + rate / 100), time)); + + /* Print the resultant CI */ + printf("Compound Interest = %f", CI); + + return 0; +} From 7692e8592cfa45be009a13819790c4879a4cd639 Mon Sep 17 00:00:00 2001 From: shreeamahadik <55586302+shreeamahadik@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:10:35 +0530 Subject: [PATCH 215/394] C Program to Find the Size of int, float, double and char C Program to Find the Size of int, float, double and char --- int, float, double and char | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 int, float, double and char diff --git a/int, float, double and char b/int, float, double and char new file mode 100644 index 00000000..1faedbc2 --- /dev/null +++ b/int, float, double and char @@ -0,0 +1,15 @@ +#include +int main() { + int intType; + float floatType; + double doubleType; + char charType; + + // sizeof evaluates the size of a variable + printf("Size of int: %ld bytes\n", sizeof(intType)); + printf("Size of float: %ld bytes\n", sizeof(floatType)); + printf("Size of double: %ld bytes\n", sizeof(doubleType)); + printf("Size of char: %ld byte\n", sizeof(charType)); + + return 0; +} From 7cdd4dd929fa7b8978fae7956fe66b29d53e78f4 Mon Sep 17 00:00:00 2001 From: Raichur Mahendra Kumar <51109700+Mahendra14@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:10:50 +0530 Subject: [PATCH 216/394] merge_two_sorted_arrays Program to merge two sorted arrays into one single array. --- mergetwosortedarrays | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mergetwosortedarrays diff --git a/mergetwosortedarrays b/mergetwosortedarrays new file mode 100644 index 00000000..76d2ea43 --- /dev/null +++ b/mergetwosortedarrays @@ -0,0 +1,43 @@ + +#include +using namespace std; + +void mergeArrays(int arr1[], int arr2[], int n1, + int n2, int arr3[]) +{ + int i = 0, j = 0, k = 0; + while (i>n1>>n2; + int arr1[n1],arr2[n2]; + for(int i=0;i>arr1[i]; + } + for(int i=0;i>arr2[i]; + } + + int arr3[n1+n2]; + mergeArrays(arr1, arr2, n1, n2, arr3); + + cout << "Array after merging into one" < Date: Fri, 2 Oct 2020 19:13:56 +0530 Subject: [PATCH 217/394] factorial.c C program to find factorial of number --- factorial.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 factorial.c diff --git a/factorial.c b/factorial.c new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/factorial.c @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From 91ecce2021b873fe2b90424fe1d9dfa19103a57d Mon Sep 17 00:00:00 2001 From: Kirtan4939 <67429129+Kirtan4939@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:17:12 +0530 Subject: [PATCH 218/394] primenumber c program to find weather a number is prime or not --- primeno | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 primeno diff --git a/primeno b/primeno new file mode 100644 index 00000000..dbb53c1c --- /dev/null +++ b/primeno @@ -0,0 +1,31 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} +Output + +Enter a positive integer: 29 +29 is a prime number. From 81b4b2e1f377e2d768faf7e7f2736ffa74bf9465 Mon Sep 17 00:00:00 2001 From: kirankumarsk <57290570+kirankumarsk@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:22:43 +0530 Subject: [PATCH 219/394] Create calculate the salary program to calculate the salary as per the following table: _________________________ Gender | Years of Service | Qualification | Salary. | _________________________ Male | >=10 | Post-Graduate | 15000. | | >=10 | Graduate | 10000 | | <10 | Post-Graduate | 10000. | | <10 | Graduate | 7000. | ---------------------------------------------------------------------- Female | >=10 | Post-Graduate | 12000. | | >=10 | Graduate | 9000. | | <10 | Post-Graduate | 10000. | | <10 | Graduate | 6000. | --- calculate the salary | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 calculate the salary diff --git a/calculate the salary b/calculate the salary new file mode 100644 index 00000000..d6fc8072 --- /dev/null +++ b/calculate the salary @@ -0,0 +1,30 @@ +#include + +int main() +{ + char g; + int yos,qual,sal=0; + + printf("Enter Gender, Years of Service and Qualifications (0=Graduate, 1=Post-graduate):\n"); + scanf("%c%d%d",&g,&yos,&qual); + + if(g == 'm'&& yos >= 10 && qual == 1) + sal = 15000; + else if((g == 'm' && yos >=10 && qual == 0) || (g == 'm' && yos < 10 && qual == 1)) + sal = 10000; + else if(g == 'm' && yos < 10 && qual == 0) + sal = 7000; + else if(g == 'f' && yos >= 10 && qual == 1) + sal = 12000; + else if(g == 'f' && yos >= 10 && qual == 0) + sal = 9000; + else if(g == 'f' && yos < 10 && qual == 1) + sal = 10000; + else if(g == 'f' && yos < 10 && qual == 0) + sal = 6000; + + printf("\nSalary of Employee = %d\n",sal); + + return 0; + +} From 06fcf2bb3d47335a1220f947de0efb7f773dd047 Mon Sep 17 00:00:00 2001 From: Kirtan4939 <67429129+Kirtan4939@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:22:54 +0530 Subject: [PATCH 220/394] prime c program tnumber o find prime --- prime | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 prime diff --git a/prime b/prime new file mode 100644 index 00000000..dbb53c1c --- /dev/null +++ b/prime @@ -0,0 +1,31 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} +Output + +Enter a positive integer: 29 +29 is a prime number. From 951b450bf23af3c060669e31c9b718eaea33671d Mon Sep 17 00:00:00 2001 From: Mohit5700 <72152449+Mohit5700@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:28:12 +0530 Subject: [PATCH 221/394] Tower of hanoi problem Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time. 2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. 3) No disk may be placed on top of a smaller disk. --- tower of hanoi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tower of hanoi diff --git a/tower of hanoi b/tower of hanoi new file mode 100644 index 00000000..19cb8bb9 --- /dev/null +++ b/tower of hanoi @@ -0,0 +1,18 @@ +void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) +{ + if (n == 1) + { + printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod); + return; + } + towerOfHanoi(n-1, from_rod, aux_rod, to_rod); + printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod); + towerOfHanoi(n-1, aux_rod, to_rod, from_rod); +} + +int main() +{ + int n = 4; // Number of disks + towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods + return 0; +} From 4802404ac9e13983c8f6c6ea9d3c4ef95f093fd2 Mon Sep 17 00:00:00 2001 From: SHARIQ78692 <72261692+SHARIQ78692@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:38:15 +0530 Subject: [PATCH 222/394] armstronginC program to check whether a number is armstrong or not in C language. --- armstrongC | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 armstrongC diff --git a/armstrongC b/armstrongC new file mode 100644 index 00000000..8655134e --- /dev/null +++ b/armstrongC @@ -0,0 +1,18 @@ +int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=sum+(r*r*r); +n=n/10; +} +if(temp==sum) +printf("armstrong number "); +else +printf("not armstrong number"); +return 0; +} From 59374995cfc4b689f4faab9ac7897a167a2f661d Mon Sep 17 00:00:00 2001 From: rohanpk123 <36415374+rohanpk123@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:40:14 +0530 Subject: [PATCH 223/394] Convert Numbers to Roman Numerals 1. Take a decimal number as input. 2. Check if the number is greater than 1000 or 900 or 500 or 400 or 100 or 90 or 50 or 40 or 10 or 9 or 5 or 4 or 1. 3. If it is, then store its equivalent roman number in a array. 4. Repeat the step 2-3 with the left over number. --- Convert Numbers to Roman Numerals | 123 ++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Convert Numbers to Roman Numerals diff --git a/Convert Numbers to Roman Numerals b/Convert Numbers to Roman Numerals new file mode 100644 index 00000000..708ab350 --- /dev/null +++ b/Convert Numbers to Roman Numerals @@ -0,0 +1,123 @@ +#include + +void predigit(char num1, char num2); +void postdigit(char c, int n); + +char romanval[1000]; +int i = 0; +int main() +{ + int j; + long number; + + printf("Enter the number: "); + scanf("%d", &number); + if (number <= 0) + { + printf("Invalid number"); + return 0; + } + while (number != 0) + { + if (number >= 1000) + { + postdigit('M', number / 1000); + number = number - (number / 1000) * 1000; + } + else if (number >= 500) + { + if (number < (500 + 4 * 100)) + { + postdigit('D', number / 500); + number = number - (number / 500) * 500; + } + else + { + predigit('C','M'); + number = number - (1000-100); + } + } + else if (number >= 100) + { + if (number < (100 + 3 * 100)) + { + postdigit('C', number / 100); + number = number - (number / 100) * 100; + } + else + { + predigit('L', 'D'); + number = number - (500 - 100); + } + } + else if (number >= 50 ) + { + if (number < (50 + 4 * 10)) + { + postdigit('L', number / 50); + number = number - (number / 50) * 50; + } + else + { + predigit('X','C'); + number = number - (100-10); + } + } + else if (number >= 10) + { + if (number < (10 + 3 * 10)) + { + postdigit('X', number / 10); + number = number - (number / 10) * 10; + } + else + { + predigit('X','L'); + number = number - (50 - 10); + } + } + else if (number >= 5) + { + if (number < (5 + 4 * 1)) + { + postdigit('V', number / 5); + number = number - (number / 5) * 5; + } + else + { + predigit('I', 'X'); + number = number - (10 - 1); + } + } + else if (number >= 1) + { + if (number < 4) + { + postdigit('I', number / 1); + number = number - (number / 1) * 1; + } + else + { + predigit('I', 'V'); + number = number - (5 - 1); + } + } + } + printf("Roman number is: "); + for(j = 0; j < i; j++) + printf("%c", romanval[j]); + return 0; +} + +void predigit(char num1, char num2) +{ + romanval[i++] = num1; + romanval[i++] = num2; +} + +void postdigit(char c, int n) +{ + int j; + for (j = 0; j < n; j++) + romanval[i++] = c; +} From 7defb780fd3a41a762b0e7baa8afeffc9e8faab6 Mon Sep 17 00:00:00 2001 From: rishu2734 <38551703+rishu2734@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:48:30 +0530 Subject: [PATCH 224/394] greatestoftwonumbersprogram To find greatest of two numbers using C program --- greatestoftwonumbers | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 greatestoftwonumbers diff --git a/greatestoftwonumbers b/greatestoftwonumbers new file mode 100644 index 00000000..51ec9ef3 --- /dev/null +++ b/greatestoftwonumbers @@ -0,0 +1,17 @@ +// C program to find largest of three numbers in C using nested if +#include +int main() +{ +int a,b,c; +printf("Enter three numbers : "); +scanf("%d %d %d", &a,&b,&c); +int max = 0; +if(a > b && a > c) +printf("\nThe largest among the three numbers is %d",a); +else if(b > a && b > c) +printf("\nThe largest among the three numbers is %d",b); +else +printf("\nThe largest among the three numbers is %d",c); +printf("\n"); +return 0; +} From 5668989bd5b8ed65fc74e55e458c686b43803925 Mon Sep 17 00:00:00 2001 From: abhiray310 <64996064+abhiray310@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:51:02 +0530 Subject: [PATCH 225/394] simple print rainbow using c program i am very excited becauce i sucessfull print rainbow. thanku. --- print rainbow | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 print rainbow diff --git a/print rainbow b/print rainbow new file mode 100644 index 00000000..12f35a5a --- /dev/null +++ b/print rainbow @@ -0,0 +1,21 @@ +#include +#include +#include +#include +void main() +{ +int gdriver = DETECT,gmode; +int x,y,i; +initgraph(&gdriver,&gmode,”C:\\Turboc3\\BGI”); +x=getmaxx()/2; +y=getmaxy()/2; +for(i=30;i<200;i++) +{ +delay(100); +setcolor(i/10); +arc(x,y,0,180,i-10); +} +getch(); +} + +//please sir accept my pull. From 6fd7393ef420febf50a330809f3f17cdd6571787 Mon Sep 17 00:00:00 2001 From: 100009224730519 <40620392+100009224730519@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:57:29 +0530 Subject: [PATCH 226/394] Create Print Upper case Lower case alphabet It can print Upper case as well as lower case alphabets --- Print Upper case Lower case alphabet | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Print Upper case Lower case alphabet diff --git a/Print Upper case Lower case alphabet b/Print Upper case Lower case alphabet new file mode 100644 index 00000000..bb9d67b9 --- /dev/null +++ b/Print Upper case Lower case alphabet @@ -0,0 +1,37 @@ +#include + +int main() + +{ + +char ch,ch1; + +for(ch='a';ch<='z';ch++) + +{ + +printf("%c %c\n",ch,ch-32); + +} + +} + +With ascii + +#include + +int main() + +{ + +char ch; + +for(ch='a';ch<='z';ch++) + +{ + +printf("%c %c %d %d\n",ch,ch-32,ch,ch-32); + +} + +} From ce1cd8a9998474ac07625bcf06968dc1a2977b84 Mon Sep 17 00:00:00 2001 From: tanuchaurasiya <60622131+tanuchaurasiya@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:02:59 +0530 Subject: [PATCH 227/394] Create DDA_Algo --- DDA_Algo | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 DDA_Algo diff --git a/DDA_Algo b/DDA_Algo new file mode 100644 index 00000000..288ae990 --- /dev/null +++ b/DDA_Algo @@ -0,0 +1,33 @@ +#include +#include +#include + +int main() +{ + int gd = DETECT, gm, i; + int dx, dy, steps, x, y; + float xinc, yinc; + int x0, x1, y0, y1; + initgraph(&gd, &gm, ""); + x0 =10, y0=20, x1=100, y1=110; + dx = x1-x0; + dy = y1-y0; + if(abs(dx)>=abs(dy)){ + steps = abs(dx); + } + else{ + steps = abs(dy); + } + xinc = dx/steps; + yinc = dy/steps; + x=x0; + y=y0; + putpixel(x0, y0, 3); + for (i=0; i Date: Fri, 2 Oct 2020 20:11:00 +0530 Subject: [PATCH 228/394] Create primenumber1 Program to find prime nu --- primenumber1 | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 primenumber1 diff --git a/primenumber1 b/primenumber1 new file mode 100644 index 00000000..b9e5215e --- /dev/null +++ b/primenumber1 @@ -0,0 +1,7 @@ +#include int main() +{ int n, i, flag = 0; printf("Enter a positive integer: "); +scanf("%d", &n); for (i = 2; i <= n / 2; ++i) { + // condition for non-prime if (n % i == 0) { flag = 1; break; } } +if (n == 1) { printf("1 is neither prime nor composite."); } +else { if (flag == 0) printf("%d is a prime number.", n); + else printf("%d is not a prime number.", n); } return 0; } From 72e63e4e24822c6f60ed87ca77dc166017779842 Mon Sep 17 00:00:00 2001 From: Abhijith720 <55933586+Abhijith720@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:23:19 +0530 Subject: [PATCH 229/394] Decimal to Binary number conversion Program to convert a Decimal number to its respective binary number --- Decimal to Binary Number Conversion | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Decimal to Binary Number Conversion diff --git a/Decimal to Binary Number Conversion b/Decimal to Binary Number Conversion new file mode 100644 index 00000000..e6969300 --- /dev/null +++ b/Decimal to Binary Number Conversion @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +int main() { + long n; + scanf("%ld",&n); + int a[64],i=0; + if(n==0)printf("0"); + else{ + while(n>0){ + a[i]=n%2; + n/=2; + i++; + } + for(int j=i-1;j>=0;j--)printf("%d",a[j]); + } + + return 0; +} From eb2d78d6900cf7c43aa168e2d75328e1c6c6b1c6 Mon Sep 17 00:00:00 2001 From: Vipin Kumar <68346071+Vipinkumar24@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:24:49 +0530 Subject: [PATCH 230/394] Revert "C Program:- Leap Year" --- Leap year | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 Leap year diff --git a/Leap year b/Leap year deleted file mode 100644 index 18e38f36..00000000 --- a/Leap year +++ /dev/null @@ -1,32 +0,0 @@ -#include -int main() { - int year; - printf("Enter a year: "); - scanf("%d", &year); - - if (year % 400 == 0) { - printf("%d is a leap year.", year); - } - - else if (year % 100 == 0) { - printf("%d is not a leap year.", year); - } - - else if (year % 4 == 0) { - printf("%d is a leap year.", year); - } - - else { - printf("%d is not a leap year.", year); - } - - return 0; -} -Output 1 - -Enter a year: 1900 -1900 is not a leap year. -Output 2 - -Enter a year: 2012 -2012 is a leap year. From 0bb6738ec932f0a1323270ab1a3756001270b8c8 Mon Sep 17 00:00:00 2001 From: Freak29 <72217338+Freak29@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:26:58 +0530 Subject: [PATCH 231/394] Create C program to insert an element in an array this a program to insert an element in an array --- C program to insert an element in an array | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 C program to insert an element in an array diff --git a/C program to insert an element in an array b/C program to insert an element in an array new file mode 100644 index 00000000..8316bef3 --- /dev/null +++ b/C program to insert an element in an array @@ -0,0 +1,31 @@ +#include + +int main() +{ + int array[100], position, c, n, value; + printf("Enter number of elements in array\n"); + scanf("%d", &n); + + printf("Enter %d elements\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + printf("Enter the location where you wish to insert an element\n"); + scanf("%d", &position); + + printf("Enter the value to insert\n"); + scanf("%d", &value); + + for (c = n - 1; c >= position - 1; c--) + array[c+1] = array[c]; + + array[position-1] = value; + + printf("Resultant array is\n"); + + for (c = 0; c <= n; c++) + printf("%d\n", array[c]); + + return 0; +} From 69f9af8f8e1b8fb4ae72384ddfa15873dd647fcf Mon Sep 17 00:00:00 2001 From: sinu0809 <72242874+sinu0809@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:27:56 +0530 Subject: [PATCH 232/394] Revert "Create C program enter 2 integer no" --- C program enter 2 integer no | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 C program enter 2 integer no diff --git a/C program enter 2 integer no b/C program enter 2 integer no deleted file mode 100644 index 56f4285b..00000000 --- a/C program enter 2 integer no +++ /dev/null @@ -1,23 +0,0 @@ -#include - -int main() { - - int number1, number2, sum; - - - - printf("Enter two integers: "); - - scanf("%d %d", &number1, &number2); - - // calculating sum - - sum = number1 + number2; - - - - printf("%d + %d = %d", number1, number2, sum); - - return 0; - -} From 5fa52f94a7e203b108fc2c8c01e37f75b6c5e591 Mon Sep 17 00:00:00 2001 From: mrlazyProgrammer <72256784+mrlazyProgrammer@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:58:50 +0530 Subject: [PATCH 233/394] Sort the Array in an Ascending Order This program will implement a one-dimensional array of some fixed size, filled with some random numbers, then will sort all the filled elements of the array. --- Sorting Arrays | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Sorting Arrays diff --git a/Sorting Arrays b/Sorting Arrays new file mode 100644 index 00000000..a24526d2 --- /dev/null +++ b/Sorting Arrays @@ -0,0 +1,40 @@ + /* + * C program to accept N numbers and arrange them in an ascending order + */ + + #include + void main() + { + + int i, j, a, n, number[30]; + printf("Enter the value of N \n"); + scanf("%d", &n); + + printf("Enter the numbers \n"); + for (i = 0; i < n; ++i) + scanf("%d", &number[i]); + + for (i = 0; i < n; ++i) + { + + for (j = i + 1; j < n; ++j) + { + + if (number[i] > number[j]) + { + + a = number[i]; + number[i] = number[j]; + number[j] = a; + + } + + } + + } + + printf("The numbers arranged in ascending order are given below \n"); + for (i = 0; i < n; ++i) + printf("%d\n", number[i]); + + } From 919c75938edad3356e626782750d9f5ce92c7646 Mon Sep 17 00:00:00 2001 From: Md Shahriyar Al Mustakim Mitul <57193846+mitul3737@users.noreply.github.com> Date: Fri, 2 Oct 2020 21:56:32 +0600 Subject: [PATCH 234/394] Snake and Laddder A snake and ladder game code written in C++ --- Snake and Ladder Game | 1486 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1486 insertions(+) create mode 100644 Snake and Ladder Game diff --git a/Snake and Ladder Game b/Snake and Ladder Game new file mode 100644 index 00000000..e38c3b98 --- /dev/null +++ b/Snake and Ladder Game @@ -0,0 +1,1486 @@ +//Contributed by Mitul +Snake And Ladder + +#include +#include +#include +#include +#include +#include +#include + +enum whoplays{p1,p2}; +int counter1=0,counter2=0,counter11=0,counter22=0; +void graph(int,int,int); +void sohaib(void); +void ladder(int,int,int,int); +void cp1(int,int); +void cp2(int,int); +void snake(int,int,int,int); +whoplays setplayer(whoplays); +class dice +{ + private: + int dice1; + public: + dice(); + int rolldice(void); + operator int() + { + return dice1/1; + } +}; +void dice::dice() +{ + dice1=0; +} +int dice::rolldice(void) +{ + randomize(); + dice1=rand()%6+1; + return dice1; +} +class player1 +{ + private: + int a; + public: + player1(); + returna(); + reseta(int); + minusa(int); + operator int() + { + return a/1; + } + +}; +void player1::player1() +{ + a=0; +} +int player1::returna() +{ + return a; +} +int player1::reseta(int ra) +{ + a+=ra; +} +int player1::minusa(int ma) +{ + a-=ma; +} +class player2 +{ + private: + int b; + public: + player2(); + returnb(); + minusb(int); + resetb(int); + operator int() + { + return b/1; + } + +}; +void player2::player2() +{ + b=0; +} +int player2::returnb() +{ + return b; +} + +int player2::resetb(int rb) +{ + b+=rb; +} +int player2::minusb(int mb) +{ + b-=mb; +} +//starting of main +void main() +{ + sohaib(); +} +//end of main +void sohaib(void) +{ + int l=VGA,k=VGAMED; + initgraph(&l,&k,"e:\tc\bgi"); + static int x=0; + dice dice1; + player1 obj1; + player2 obj2; + int one=0,two=0,y=0; + y=setplayer(1); + g:if(x==6) + { + if(y==0) + { + y=setplayer(0); + } + else + if(y==1) + { + y=setplayer(1); + } + } + else + { + if(y==0) + { + y=setplayer(1); + } + else + if(y==1) + { + y=setplayer(0); + } + } + + x=int(dice1.rolldice()); + one=int(obj1.returna()); + two=int(obj2.returnb()); + graph(y,one,two); + if(x==6&&y==0) + { + counter11=1; + } + if(x==6&&y==1) + { + counter22=1; + } + if(y==0&&counter11==1) + { + counter1=1; + } + if(y==1&&counter22==1) + { + counter2=1; + } + if(y==0&&counter1>=1) + { + obj1.reseta(x); + if(one==10) + { + obj1.reseta(27); + cout<=1) + { + obj2.resetb(x); + if(two==24) + { + obj2.resetb(27); + cout<=100) + { + cout<<" +congratulations player 1 have won"; + goto b; + } + if(two>=100) + { + cout<<" +congratulations player 2 have won"; + goto b; + } + if((one<101&&two<101)&&(one>=0&&two>=0)) + { + goto g; + } + b:getch(); +} +whoplays setplayer(whoplays p) +{ + whoplays player=p; + return player; +} + +void graph(int y,int one,int two) +{ + int a=VGA,b=VGAMED; + initgraph(&a,&b,"e:\tc\bgi"); + cleardevice(); + int count=0,r=21; + if(y==0) + { + rectangle(200,100,400,200); + setfillstyle(1,BLUE); + floodfill(201,101,WHITE); + moveto(210,110); + setcolor(GREEN); + settextstyle(SCRIPT_FONT,HORIZ_DIR,5); + outtext("Player 2"); + getch(); + cleardevice(); + } + if(y==1) + { + rectangle(200,100,400,200); + setfillstyle(1,RED); + floodfill(201,101,WHITE); + moveto(210,110); + setcolor(YELLOW); + settextstyle(SCRIPT_FONT,HORIZ_DIR,5); + outtext("Player 2"); + getch(); + cleardevice(); + } + setcolor(4); + moveto(75,5); + settextstyle(GOTHIC_FONT,HORIZ_DIR,5); + outtext("SNAKE AND LADDER"); + rectangle(65,8,535,53); + setcolor(GREEN); + rectangle(15,58,590,298); + for(int e=73;e<590;e=e+58) + { + line(e,58,e,298); + } + for(int d=82;d<298;d=d+24) + { + line(15,d,590,d); + } + setcolor(RED); + moveto(44,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("1"); + moveto(102,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("2"); + moveto(160,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("3"); + moveto(218,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("4"); + moveto(276,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("5"); + moveto(334,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("6"); + moveto(392,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("7"); + moveto(450,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("8"); + moveto(508,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("9"); + moveto(566,286); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("10"); + moveto(44,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("11"); + moveto(102,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("12"); + moveto(160,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("13"); + moveto(218,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("14"); + moveto(276,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("15"); + moveto(334,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("16"); + moveto(392,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("17"); + moveto(450,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("18"); + moveto(508,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("19"); + moveto(566,262); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("20"); + moveto(44,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("21"); + moveto(102,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("22"); + moveto(160,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("23"); + moveto(218,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("24"); + moveto(276,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("25"); + moveto(334,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("26"); + moveto(392,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("27"); + moveto(450,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("28"); + moveto(508,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("29"); + moveto(566,238); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("30"); + moveto(44,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("31"); + moveto(102,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("32"); + moveto(160,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("33"); + moveto(218,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("34"); + moveto(276,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("35"); + moveto(334,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("36"); + moveto(392,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("37"); + moveto(450,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("38"); + moveto(508,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("39"); + moveto(566,214); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("40"); + moveto(44,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("41"); + moveto(102,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("42"); + moveto(160,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("43"); + moveto(218,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("44"); + moveto(276,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("45"); + moveto(334,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("46"); + moveto(392,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("47"); + moveto(450,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("48"); + moveto(508,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("49"); + moveto(566,190); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("50"); + moveto(44,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("51"); + moveto(102,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("52"); + moveto(160,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("53"); + moveto(218,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("54"); + moveto(276,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("55"); + moveto(334,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("56"); + moveto(392,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("57"); + moveto(450,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("58"); + moveto(508,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("59"); + moveto(566,166); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("60"); + moveto(44,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("61"); + moveto(102,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("62"); + moveto(160,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("63"); + moveto(218,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("64"); + moveto(276,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("65"); + moveto(334,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("66"); + moveto(392,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("67"); + moveto(450,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("68"); + moveto(508,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("69"); + moveto(566,142); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("70"); + moveto(44,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("71"); + moveto(102,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("72"); + moveto(160,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("73"); + moveto(218,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("74"); + moveto(276,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("75"); + moveto(334,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("76"); + moveto(392,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("77"); + moveto(450,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("78"); + moveto(508,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("79"); + moveto(566,118); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("80"); + moveto(44,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("81"); + moveto(102,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("82"); + moveto(160,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("83"); + moveto(218,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("84"); + moveto(276,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("85"); + moveto(334,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("86"); + moveto(392,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("87"); + moveto(450,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("88"); + moveto(508,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("89"); + moveto(566,94); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("90"); + moveto(44,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("91"); + moveto(102,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("92"); + moveto(160,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("93"); + moveto(218,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("94"); + moveto(276,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("95"); + moveto(334,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("96"); + moveto(392,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("97"); + moveto(450,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("98"); + moveto(508,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("99"); + moveto(558,70); + settextstyle(DEFAULT_FONT,HORIZ_DIR,1); + outtext("100"); + settextstyle(SMALL_FONT,HORIZ_DIR,5); + setcolor(GREEN); + rectangle(363,300,590,349); + setcolor(6); + moveto(375,306); + outtext("Dice -> "); + moveto(375,317); + outtext("Player 1 -> "); + moveto(375,328); + outtext("Player 2 -> "); + setcolor(GREEN); + rectangle(15,300,350,349); + setcolor(YELLOW); + moveto(19,302); + outtext("Help : "); + setcolor(7); + settextstyle(SMALL_FONT,HORIZ_DIR,4); + outtext("Just press any key, a number will appear before "); + moveto(72,312); + outtext("dice. The mark of player will automatically move"); + moveto(19,322); + outtext("to the accurate position. The player who will reach 100 "); + moveto(19,332); + outtext("will Win the game. "); + ladder(392,214,566,286); + ladder(218,142,276,166); + //ladder(508,94,508,118); + ladder(44,166,218,238); + ladder(160,190,450,166); + ladder(450,70,450,94); + snake(508,70,556,238); + snake(334,166,334,238); + snake(392,118,102,166); + snake(450,238,160,262); + snake(508,142,508,214); + cp1(515,310); + moveto(520,307); + outtext(" Player 1"); + cp2(515,330); + moveto(520,327); + outtext(" Player 2"); + + + if(one==1) + { + cp1(44,286); + } + if(one==2) + { + cp1(102,286); + } + if(one==3) + { + cp1(160,286); + } + if(one==4) + { + cp1(218,286); + } + if(one==5) + { + cp1(276,286); + } + if(one==6) + { + cp1(334,286); + } + if(one==7) + { + cp1(392,286); + } + if(one==8) + { + cp1(450,286); + } + if(one==9) + { + cp1(508,286); + } + if(one==10) + { + cp1(566,286); + } + if(one==11) + { + cp1(44,262); + } + if(one==12) + { + cp1(102,262); + } + if(one==13) + { + cp1(160,262); + } + if(one==14) + { + cp1(218,262); + } + if(one==15) + { + cp1(276,262); + } + if(one==16) + { + cp1(334,262); + } + if(one==17) + { + cp1(392,262); + } + if(one==18) + { + cp1(450,262); + } + if(one==19) + { + cp1(508,262); + } + if(one==20) + { + cp1(566,262); + } + if(one==21) + { + cp1(44,238); + } + if(one==22) + { + cp1(102,238); + } + if(one==23) + { + cp1(160,238); + } + if(one==24) + { + cp1(218,238); + } + if(one==25) + { + cp1(276,238); + } + if(one==26) + { + cp1(334,238); + } + if(one==27) + { + cp1(392,238); + } + if(one==28) + { + cp1(450,238); + } + if(one==29) + { + cp1(508,238); + } + if(one==30) + { + cp1(566,238); + } + if(one==31) + { + cp1(44,214); + } + if(one==32) + { + cp1(102,214); + } + if(one==33) + { + cp1(160,214); + } + if(one==34) + { + cp1(218,214); + } + if(one==35) + { + cp1(276,214); + } + if(one==36) + { + cp1(334,214); + } + if(one==37) + { + cp1(392,214); + } + if(one==38) + { + cp1(450,214); + } + if(one==39) + { + cp1(508,214); + } + if(one==40) + { + cp1(566,214); + } + if(one==41) + { + cp1(44,190); + } + if(one==42) + { + cp1(102,190); + } + if(one==43) + { + cp1(160,190); + } + if(one==44) + { + cp1(218,190); + } + if(one==45) + { + cp1(276,190); + } + if(one==46) + { + cp1(334,190); + } + if(one==47) + { + cp1(392,190); + } + if(one==48) + { + cp1(450,190); + } + if(one==49) + { + cp1(508,190); + } + if(one==50) + { + cp1(566,190); + } + if(one==51) + { + cp1(44,166); + } + if(one==52) + { + cp1(102,166); + } + if(one==53) + { + cp1(160,166); + } + if(one==54) + { + cp1(218,166); + } + if(one==55) + { + cp1(276,166); + } + if(one==56) + { + cp1(334,166); + } + if(one==57) + { + cp1(392,166); + } + if(one==58) + { + cp1(450,166); + } + if(one==59) + { + cp1(508,166); + } + if(one==60) + { + cp1(566,166); + } + if(one==61) + { + cp1(44,142); + } + if(one==62) + { + cp1(102,142); + } + if(one==63) + { + cp1(160,142); + } + if(one==64) + { + cp1(218,142); + } + if(one==65) + { + cp1(276,142); + } + if(one==66) + { + cp1(334,142); + } + if(one==67) + { + cp1(392,142); + } + if(one==68) + { + cp1(450,142); + } + if(one==69) + { + cp1(508,142); + } + if(one==70) + { + cp1(566,142); + } + if(one==71) + { + cp1(44,118); + } + if(one==72) + { + cp1(102,118); + } + if(one==73) + { + cp1(160,118); + } + if(one==74) + { + cp1(218,118); + } + if(one==75) + { + cp1(276,118); + } + if(one==76) + { + cp1(334,118); + } + if(one==77) + { + cp1(392,118); + } + if(one==78) + { + cp1(450,118); + } + if(one==79) + { + cp1(508,118); + } + if(one==80) + { + cp1(566,118); + } + if(one==81) + { + cp1(44,94); + } + if(one==82) + { + cp1(102,94); + } + if(one==83) + { + cp1(160,94); + } + if(one==84) + { + cp1(218,94); + } + if(one==85) + { + cp1(276,94); + } + if(one==86) + { + cp1(334,94); + } + if(one==87) + { + cp1(392,94); + } + if(one==88) + { + cp1(450,94); + } + if(one==89) + { + cp1(508,94); + } + if(one==90) + { + cp1(566,94); + } + if(one==91) + { + cp1(44,70); + } + if(one==92) + { + cp1(102,70); + } + if(one==93) + { + cp1(160,70); + } + if(one==70) + { + cp1(218,70); + } + if(one==95) + { + cp1(276,70); + } + if(one==96) + { + cp1(334,70); + } + if(one==97) + { + cp1(392,70); + } + if(one==98) + { + cp1(450,70); + } + if(one==99) + { + cp1(508,70); + } + if(one==100) + { + cp1(566,70); + } + + + + if(two==1) + { + cp2(44,286); + } + if(two==2) + { + cp2(102,286); + } + if(two==3) + { + cp2(160,286); + } + if(two==4) + { + cp2(218,286); + } + if(two==5) + { + cp2(276,286); + } + if(two==6) + { + cp2(334,286); + } + if(two==7) + { + cp2(392,286); + } + if(two==8) + { + cp2(450,286); + } + if(two==9) + { + cp2(508,286); + } + if(two==10) + { + cp2(566,286); + } + if(two==11) + { + cp2(44,262); + } + if(two==12) + { + cp2(102,262); + } + if(two==13) + { + cp2(160,262); + } + if(two==14) + { + cp2(218,262); + } + if(two==15) + { + cp2(276,262); + } + if(two==16) + { + cp2(334,262); + } + if(two==17) + { + cp2(392,262); + } + if(two==18) + { + cp2(450,262); + } + if(two==19) + { + cp2(508,262); + } + if(two==20) + { + cp2(566,262); + } + if(two==21) + { + cp2(44,238); + } + if(two==22) + { + cp2(102,238); + } + if(two==23) + { + cp2(160,238); + } + if(two==24) + { + cp2(218,238); + } + if(two==25) + { + cp2(276,238); + } + if(two==26) + { + cp2(334,238); + } + if(two==27) + { + cp2(392,238); + } + if(two==28) + { + cp2(450,238); + } + if(two==29) + { + cp2(508,238); + } + if(two==30) + { + cp2(566,238); + } + if(two==31) + { + cp2(44,214); + } + if(two==32) + { + cp2(102,214); + } + if(two==33) + { + cp2(160,214); + } + if(two==34) + { + cp2(218,214); + } + if(two==35) + { + cp2(276,214); + } + if(two==36) + { + cp2(334,214); + } + if(two==37) + { + cp2(392,214); + } + if(two==38) + { + cp2(450,214); + } + if(two==39) + { + cp2(508,214); + } + if(two==40) + { + cp2(566,214); + } + if(two==41) + { + cp2(44,190); + } + if(two==42) + { + cp2(102,190); + } + if(two==43) + { + cp2(160,190); + } + if(two==44) + { + cp2(218,190); + } + if(two==45) + { + cp2(276,190); + } + if(two==46) + { + cp2(334,190); + } + if(two==47) + { + cp2(392,190); + } + if(two==48) + { + cp2(450,190); + } + if(two==49) + { + cp2(508,190); + } + if(two==50) + { + cp2(566,190); + } + if(two==51) + { + cp2(44,166); + } + if(two==52) + { + cp2(102,166); + } + if(two==53) + { + cp2(160,166); + } + if(two==54) + { + cp2(218,166); + } + if(two==55) + { + cp2(276,166); + } + if(two==56) + { + cp2(334,166); + } + if(two==57) + { + cp2(392,166); + } + if(two==58) + { + cp2(450,166); + } + if(two==59) + { + cp2(508,166); + } + if(two==60) + { + cp2(566,166); + } + if(two==61) + { + cp2(44,142); + } + if(two==62) + { + cp2(102,142); + } + if(two==63) + { + cp2(160,142); + } + if(two==64) + { + cp2(218,142); + } + if(two==65) + { + cp2(276,142); + } + if(two==66) + { + cp2(334,142); + } + if(two==67) + { + cp2(392,142); + } + if(two==68) + { + cp2(450,142); + } + if(two==69) + { + cp2(508,142); + } + if(two==70) + { + cp2(566,142); + } + if(two==71) + { + cp2(44,118); + } + if(two==72) + { + cp2(102,118); + } + if(two==73) + { + cp2(160,118); + } + if(two==74) + { + cp2(218,118); + } + if(two==75) + { + cp2(276,118); + } + if(two==76) + { + cp2(334,118); + } + if(two==77) + { + cp2(392,118); + } + if(two==78) + { + cp2(450,118); + } + if(two==79) + { + cp2(508,118); + } + if(two==80) + { + cp2(566,118); + } + if(two==81) + { + cp2(44,94); + } + if(two==82) + { + cp2(102,94); + } + if(two==83) + { + cp2(160,94); + } + if(two==84) + { + cp2(218,94); + } + if(two==85) + { + cp2(276,94); + } + if(two==86) + { + cp2(334,94); + } + if(two==87) + { + cp2(392,94); + } + if(two==88) + { + cp2(450,94); + } + if(two==89) + { + cp2(508,94); + } + if(two==90) + { + cp2(566,94); + } + if(two==91) + { + cp2(44,70); + } + if(two==92) + { + cp2(102,70); + } + if(two==93) + { + cp2(160,70); + } + if(two==70) + { + cp2(218,70); + } + if(two==95) + { + cp2(276,70); + } + if(two==96) + { + cp2(334,70); + } + if(two==97) + { + cp2(392,70); + } + if(two==98) + { + cp2(450,70); + } + if(two==99) + { + cp2(508,70); + } + if(two==100) + { + cp2(566,70); + } + + getch(); + closegraph(); +} +void ladder(int s1,int s2,int s3,int s4) +{ + setcolor(WHITE); + setlinestyle(1,10,3); + line(s1,s2,s3,s4); + line(s1,s2,s1,s2+10); + line(s1,s2,s1+17,s2); + //circle(s1,s2,3); + +} +void cp1(int xx,int yy) +{ + setcolor(7); + circle(xx,yy,10); + setfillstyle(1,9); + floodfill(xx,yy,7); +} +void cp2(int xx,int yy) +{ + setcolor(7); + circle(xx,yy,10); + setfillstyle(1,4); + floodfill(xx,yy,7); +} + +void snake(int s1,int s2,int s3,int s4) +{ + setcolor(YELLOW); + setlinestyle(1,10,3); + line(s1,s2,s3,s4); + circle(s1,s2,4); +} From 2c9f7fe62d3eaa1469ebfc5ee069383b24800cb2 Mon Sep 17 00:00:00 2001 From: sohongjaduuniv <72270226+sohongjaduuniv@users.noreply.github.com> Date: Fri, 2 Oct 2020 21:42:36 +0530 Subject: [PATCH 235/394] greaterno Program to find the greatest of two numbers --- greatno | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 greatno diff --git a/greatno b/greatno new file mode 100644 index 00000000..c8138701 --- /dev/null +++ b/greatno @@ -0,0 +1,15 @@ +int main() +{ +//Fill the code +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} From b19e62124f130e36239d884dbd535e5632b3ef55 Mon Sep 17 00:00:00 2001 From: Vanshjin <70649785+Vanshjin@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:34:56 +0300 Subject: [PATCH 236/394] quicksort program plz accept my code --- quickSort | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 quickSort diff --git a/quickSort b/quickSort new file mode 100644 index 00000000..6b80d2a3 --- /dev/null +++ b/quickSort @@ -0,0 +1,83 @@ +Live Demo +#include +#include + +#define MAX 7 + +int intArray[MAX] = {4,6,3,2,1,9,7}; + +void printline(int count) { + int i; + + for(i = 0;i < count-1;i++) { + printf("="); + } + + printf("=\n"); +} + +void display() { + int i; + printf("["); + + // navigate through all items + for(i = 0;i < MAX;i++) { + printf("%d ",intArray[i]); + } + + printf("]\n"); +} + +void swap(int num1, int num2) { + int temp = intArray[num1]; + intArray[num1] = intArray[num2]; + intArray[num2] = temp; +} + +int partition(int left, int right, int pivot) { + int leftPointer = left -1; + int rightPointer = right; + + while(true) { + while(intArray[++leftPointer] < pivot) { + //do nothing + } + + while(rightPointer > 0 && intArray[--rightPointer] > pivot) { + //do nothing + } + + if(leftPointer >= rightPointer) { + break; + } else { + printf(" item swapped :%d,%d\n", intArray[leftPointer],intArray[rightPointer]); + swap(leftPointer,rightPointer); + } + } + + printf(" pivot swapped :%d,%d\n", intArray[leftPointer],intArray[right]); + swap(leftPointer,right); + printf("Updated Array: "); + display(); + return leftPointer; +} + +void quickSort(int left, int right) { + if(right-left <= 0) { + return; + } else { + int pivot = intArray[right]; + int partitionPoint = partition(left, right, pivot); + quickSort(left,partitionPoint-1); + quickSort(partitionPoint+1,right); + } +} + +int main() { + printf("Input Array: "); + display(); + printline(50); + quickSort(0,MAX-1); + printf("Output Array: "); + display(); + printline(50); From 23886cf5664461b7082d0c058907defe59273149 Mon Sep 17 00:00:00 2001 From: ahmedmahmood153 <72175800+ahmedmahmood153@users.noreply.github.com> Date: Fri, 2 Oct 2020 21:37:21 +0500 Subject: [PATCH 237/394] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b71346c..71b4d610 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# cprogram +# cprogram - An Amazing Project # The CP is a framework of international education that incorporates the values of the IB into a unique programme addressing the needs of students engaged in career-related education. From d55dc923599f43af7db7d0fe317ecf74921ce27c Mon Sep 17 00:00:00 2001 From: debasish212 <72241065+debasish212@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:18:38 +0530 Subject: [PATCH 238/394] armstrong number Program to display armstrong number between two intervals --- armstrong number | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 armstrong number diff --git a/armstrong number b/armstrong number new file mode 100644 index 00000000..23d17e44 --- /dev/null +++ b/armstrong number @@ -0,0 +1,41 @@ +#include +#include +int main() { + int low, high, number, originalNumber, rem, count = 0; + double result = 0.0; + printf("Enter two numbers(intervals): "); + scanf("%d %d", &low, &high); + printf("Armstrong numbers between %d and %d are: ", low, high); + + // iterate number from (low + 1) to (high - 1) + // In each iteration, check if number is Armstrong + for (number = low + 1; number < high; ++number) { + originalNumber = number; + + // number of digits calculation + while (originalNumber != 0) { + originalNumber /= 10; + ++count; + } + + originalNumber = number; + + // result contains sum of nth power of individual digits + while (originalNumber != 0) { + rem = originalNumber % 10; + result += pow(rem, count); + originalNumber /= 10; + } + + // check if number is equal to the sum of nth power of individual digits + if ((int)result == number) { + printf("%d ", number); + } + + // resetting the values + count = 0; + result = 0; + } + + return 0; +} From 19681c6f8d53ae0253b8299afaa4f460b21de69a Mon Sep 17 00:00:00 2001 From: Nayan Jain <71127472+NayanJain7@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:20:33 +0530 Subject: [PATCH 239/394] Create ReadWrite.cpp C++ program to read and write in a file --- ReadWrite.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ReadWrite.cpp diff --git a/ReadWrite.cpp b/ReadWrite.cpp new file mode 100644 index 00000000..e8940d04 --- /dev/null +++ b/ReadWrite.cpp @@ -0,0 +1,49 @@ +#include + +#include + +using namespace std; + +int main() { + + ofstream MyFile("sample.txt"); + + cout<<"Writing into a file\n"; + + string data; + + cout<<"Enter your name : \n"; + + cin>>data; + + + + MyFile << data << endl; + + cout<<"Enter your age : "; + + cin>>data; + + MyFile << data << endl; + + + + MyFile.close(); + + string myText; + +ifstream MyReadFile("sample.txt"); + +cout<<"Reading from a file\n"; + +while (getline (MyReadFile, myText)) { + + cout << myText< Date: Fri, 2 Oct 2020 22:28:27 +0530 Subject: [PATCH 240/394] affinecypher It is an encryption code (Affine Cypher) --- affinecypher | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 affinecypher diff --git a/affinecypher b/affinecypher new file mode 100644 index 00000000..cfe2c652 --- /dev/null +++ b/affinecypher @@ -0,0 +1,111 @@ +#include +#include +#include + +int checkcoprime(int num) +{ + int a,b,temp; + a=num; + b=26; + + while(b!=0) + { + temp=b; + b=a%b; + a=temp; + + } + + return a; + +} +main() +{ + int a,b,check,numstr[1000]; + char str[1000]; + printf("Enter a ( 1 to 25) both included which is co-prime with 26\n"); + scanf("%d",&a); + if(a>=1 && a<=25) + { + check=checkcoprime(a); + if(check!=1) + { + printf("Enter the one which is co-prime with 26\n"); + exit(0); + } + + } + else + { + printf("Enter between 1 and 25\n "); + exit(1); + } + + printf("Enter b ( 0 to 25) both included \n"); + scanf("%d",&b); + if(b<1 || a>25) + { + printf("Enter b between 0 to 25 \n"); + exit(3); + + } + + printf("Enter the string to be encypted: \n"); + fflush(stdin); + gets(str); + + // converting string into capital letters + + int i,j; + + for(i=0;i Date: Fri, 2 Oct 2020 22:31:56 +0530 Subject: [PATCH 241/394] fibonacci no. c program of fibonacci number --- fibonacci no. | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibonacci no. diff --git a/fibonacci no. b/fibonacci no. new file mode 100644 index 00000000..3a8309e9 --- /dev/null +++ b/fibonacci no. @@ -0,0 +1,16 @@ +#include + +int main(){ +int fib1=0,fib2=1,fib,n; +printf("enter the lmits:"); +scanf("%d",&n); + +for(int i=1;i<=n;i++){ + printf("%d\n",fib1); + + fib=fib1+fib2; + fib1=fib2; + fib2=fib; +} +return 0; +} From 846c5553523577b712b70243722ec0fb60863a60 Mon Sep 17 00:00:00 2001 From: priya425mk <72222196+priya425mk@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:38:25 +0530 Subject: [PATCH 242/394] example to calculate income tax An example to calculate income tax --- example to calculate income tax | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 example to calculate income tax diff --git a/example to calculate income tax b/example to calculate income tax new file mode 100644 index 00000000..1e6dcd84 --- /dev/null +++ b/example to calculate income tax @@ -0,0 +1,17 @@ +/*to calculate income tax*/ +#include + +int main(){ +float tax=0, income; +printf("enter your income\n"); +scanf("%f",&income); + +if(income>=250000 && income<=500000){ + tax=tax+0.05*(income-250000); +} +if(income<=500000){ + tax=tax+0.20*(income-500000); +} +printf("your net income tax to be paid is %f\n",tax); +return 0; +} From e8e83cee19538680a8f8cfb3735e399abf9ed32f Mon Sep 17 00:00:00 2001 From: Shreyash-cyber <72146041+Shreyash-cyber@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:40:50 +0530 Subject: [PATCH 243/394] snake game in c hope you like it too litle bit different --- anke game in c language | 179 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 anke game in c language diff --git a/anke game in c language b/anke game in c language new file mode 100644 index 00000000..95c19c83 --- /dev/null +++ b/anke game in c language @@ -0,0 +1,179 @@ +Snake Game in c language + +check(); +end(); +win(); +int m[500],n[500],con=20; +clock_t start,stop; + void main(void) +{ + +int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100; + +initgraph(&gd,&gm,"..\bgi"); + +setcolor(WHITE); +settextstyle(3,0,6); +outtextxy(200,2," SNAKE 2 "); +settextstyle(6,0,2); +outtextxy(20,80," Use Arrow Keys To Direct The Snake "); +outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake +"); +outtextxy(20,160," Pick The Beats Untill You Win The Game "); +outtextxy(20,200," Press 'Esc' Anytime To Exit "); +outtextxy(20,220," Press Any Key To Continue "); +ch=getch(); +if(ch==27) exit(0); +cleardevice(); +maxx=getmaxx(); +maxy=getmaxy(); + +randomize(); + +p=random(maxx); +int temp=p%13; +p=p-temp; +q=random(maxy); +temp=q%14; +q=q-temp; + + + + start=clock(); +int a=0,i=0,j,t; +while(1) +{ + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con+5); + circle(p,q,5); + floodfill(p,q,WHITE); + + if( kbhit() ) + { + ch=getch(); if(ch==0) ch=getch(); + if(ch==72&& a!=2) a=1; + if(ch==80&& a!=1) a=2; + if(ch==75&& a!=4) a=3; + if(ch==77&& a!=3) a=4; + } + else + { + if(ch==27 + ) break; + } + + if(i<20){ + m[i]=x; + n[i]=y; + i++; + } + + if(i>=20) + + { + for(j=con;j>=0;j--){ + m[1+j]=m[j]; + n[1+j]=n[j]; + } + m[0]=x; + n[0]=y; + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con); + circle(m[0],n[0],8); + floodfill(m[0],n[0],WHITE); + + setcolor(WHITE); + for(j=1;j=5) spd=spd-5; else spd=5; + if(con>490) win(); + p=random(maxx); temp=p%13; p=p-temp; + q=random(maxy); temp=q%14; q=q-temp; + } + if(a==1) y = y-14; if(y<0) { temp=maxy%14;y=maxy-temp;} + if(a==2) y = y+14; if(y>maxy) y=0; + if(a==3) x = x-13; if(x<0) { temp=maxx%13;x=maxx-temp;} + if(a==4) x = x+13; if(x>maxx) x=0; + if(a==0){ y = y+14 ; x=x+13; } + } + + } + + +check(){ + int a; + for(a=1;a Date: Fri, 2 Oct 2020 22:46:14 +0530 Subject: [PATCH 244/394] celcius to farenheit A C program to convert temperature of celcius to farenheit --- celcius to farenheit | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 celcius to farenheit diff --git a/celcius to farenheit b/celcius to farenheit new file mode 100644 index 00000000..628c03e7 --- /dev/null +++ b/celcius to farenheit @@ -0,0 +1,11 @@ +/*to convert celcius to farenheit*/ +#include + +int main(){ +float celcius,farenheit; +printf("enter the value of celcius:"); +scanf("%f",&celcius); +farenheit=(celcius*9/5)+32; +printf("the temperature in farenheit is:%f",farenheit); +return 0; +} From 89b9cbfde151d01469b922537555e11d7b9c702f Mon Sep 17 00:00:00 2001 From: Nayan Gupta <61581273+nayanmanojgupta@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:49:42 +0530 Subject: [PATCH 245/394] Create MagicSquare.c A C program to generate a Magic Square for given odd number. --- MagicSquare.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 MagicSquare.c diff --git a/MagicSquare.c b/MagicSquare.c new file mode 100644 index 00000000..ac62695f --- /dev/null +++ b/MagicSquare.c @@ -0,0 +1,72 @@ +#include +#include +// program to generate a magic square for a odd given input +main() +{ + int n,i,j,r,c; + printf("Enter the size of magic square: \n"); + scanf("%d",&n); + int a[n][n]; + memset(a,0,sizeof(a)); + + if(n%2!=0) + { + + r=n/2; + c=n-1; + + for(i=1;i<=n*n;i++) + { + + + if(r==-1 && c==n) + { + r=0; + c=n-2; + + } + + + else if(r==-1) + { + r=n-1; + } + else if(c==n) + { + c=0; + } + + if(a[r][c]) + { + r=(r+1)%n; + c=c-2; + if(c==-1) + c=n-1; + else if (c==-2) + c=1; + a[r][c]=i; + r--; + c++; + } + else + { + a[r][c]=i; + r--; + c++; + } + + + } + + for(i=0;i Date: Fri, 2 Oct 2020 22:50:51 +0530 Subject: [PATCH 246/394] Strassen's Matrix Multiplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C program to multiply two NxN matrices using Strassen’s Matrix Multiplication method. --- strassen's matrix multiplication | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 strassen's matrix multiplication diff --git a/strassen's matrix multiplication b/strassen's matrix multiplication new file mode 100644 index 00000000..6d1e0e4e --- /dev/null +++ b/strassen's matrix multiplication @@ -0,0 +1,53 @@ +#include +#include +#include +int main() +{ + int a[10][10],b[10][10],c[10][10],i,j; + int m1,m2,m3,m4,m5,m6,m7,n; + clock_t st,et; + double ts; + printf("Enter the size of two matrices: "); + scanf("%d",&n); + for(i=0;i Date: Fri, 2 Oct 2020 22:51:14 +0530 Subject: [PATCH 247/394] graterNumber program to find grater number --- graterNumber | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 graterNumber diff --git a/graterNumber b/graterNumber new file mode 100644 index 00000000..a3023d78 --- /dev/null +++ b/graterNumber @@ -0,0 +1,17 @@ +#include +int main() +{ + int a,b; + printf("Enter two values); + scanf("%d%d",&a,&b); + if(a>b) + { + return(a); + } + else + { + return(b); + } + + +} From bcf3d3f9cd11285d64f6ffe02fdb083be38af66e Mon Sep 17 00:00:00 2001 From: venkat2319 <61793052+venkat2319@users.noreply.github.com> Date: Fri, 2 Oct 2020 23:09:39 +0530 Subject: [PATCH 248/394] Create simple game --- simple game | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 simple game diff --git a/simple game b/simple game new file mode 100644 index 00000000..d6a83acc --- /dev/null +++ b/simple game @@ -0,0 +1,208 @@ +#include +using namespace std; + +#define COMPUTER 1 +#define HUMAN 2 + +#define SIDE 3 // Length of the board + +// Computer will move with 'O' +// and human with 'X' +#define COMPUTERMOVE 'O' +#define HUMANMOVE 'X' + +// A function to show the current board status +void showBoard(char board[][SIDE]) +{ + printf("\n\n"); + + printf("\t\t\t %c | %c | %c \n", board[0][0], + board[0][1], board[0][2]); + printf("\t\t\t--------------\n"); + printf("\t\t\t %c | %c | %c \n", board[1][0], + board[1][1], board[1][2]); + printf("\t\t\t--------------\n"); + printf("\t\t\t %c | %c | %c \n\n", board[2][0], + board[2][1], board[2][2]); + + return; +} + +// A function to show the instructions +void showInstructions() +{ + printf("\t\t\t Tic-Tac-Toe\n\n"); + printf("Choose a cell numbered from 1 to 9 as below" + " and play\n\n"); + + printf("\t\t\t 1 | 2 | 3 \n"); + printf("\t\t\t--------------\n"); + printf("\t\t\t 4 | 5 | 6 \n"); + printf("\t\t\t--------------\n"); + printf("\t\t\t 7 | 8 | 9 \n\n"); + + printf("-\t-\t-\t-\t-\t-\t-\t-\t-\t-\n\n"); + + return; +} + + +// A function to initialise the game +void initialise(char board[][SIDE], int moves[]) +{ + // Initiate the random number generator so that + // the same configuration doesn't arises + srand(time(NULL)); + + // Initially the board is empty + for (int i=0; i Date: Fri, 2 Oct 2020 23:32:09 +0530 Subject: [PATCH 249/394] factorialno program to find factorial of a number in c --- factorailno | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 factorailno diff --git a/factorailno b/factorailno new file mode 100644 index 00000000..1663258b --- /dev/null +++ b/factorailno @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); +return 0; +} From 98635d06dc35870b9280a348573270fb76849cc5 Mon Sep 17 00:00:00 2001 From: shikharuttam <49878742+shikharuttam@users.noreply.github.com> Date: Fri, 2 Oct 2020 23:33:02 +0530 Subject: [PATCH 250/394] Create To Print a Rombus star pattern In this program we will see how to print a rombus star pattern in c --- To Print a Rombus star pattern | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 To Print a Rombus star pattern diff --git a/To Print a Rombus star pattern b/To Print a Rombus star pattern new file mode 100644 index 00000000..b84519e7 --- /dev/null +++ b/To Print a Rombus star pattern @@ -0,0 +1,21 @@ +#include + +int main() +{ + int n; + printf("Enter the number of rows"); + scanf("%d",&n); + for(int i=n;i>=1;i--) + { + for(int j=1;j<=i-1;j++) + { + printf(" "); + } + for(int k=1;k<=n;k++) + { + printf("*"); + } + printf("\n"); + } + return 0; +} From e4ec876138c376b1695fa57fb4b5fbe4831297c8 Mon Sep 17 00:00:00 2001 From: Rajdip Mondal Date: Fri, 2 Oct 2020 23:58:16 +0530 Subject: [PATCH 251/394] Create Gcdrecursion.cpp --- Gcdrecursion.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Gcdrecursion.cpp diff --git a/Gcdrecursion.cpp b/Gcdrecursion.cpp new file mode 100644 index 00000000..17f58714 --- /dev/null +++ b/Gcdrecursion.cpp @@ -0,0 +1,16 @@ +#include +int hcf(int n1, int n2); +int main() { + int n1, n2; + printf("Enter two positive integers: "); + scanf("%d %d", &n1, &n2); + printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2)); + return 0; +} + +int hcf(int n1, int n2) { + if (n2 != 0) + return hcf(n2, n1 % n2); + else + return n1; +} From f66e2bd43c16a31b243a9c41be6d51a819432896 Mon Sep 17 00:00:00 2001 From: ShivamMittalcool <72269062+ShivamMittalcool@users.noreply.github.com> Date: Sat, 3 Oct 2020 01:00:35 +0530 Subject: [PATCH 252/394] Factorial number program to find factorial of a number --- Factorial number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Factorial number diff --git a/Factorial number b/Factorial number new file mode 100644 index 00000000..a200050f --- /dev/null +++ b/Factorial number @@ -0,0 +1,15 @@ +#include + +int main() +{ + int c,n,f=1; + + printf("Enter a number to calculate its factorial\n"); + scanf("%d", &n); + for (c=1; c<=n; c++) + f=f*c; + + printf("Factorial of %d = %d\n", n, f); + + return 0; +} From 8814748bb61a752078b5820978e1f19d73849bdf Mon Sep 17 00:00:00 2001 From: nikengoswami <66886066+nikengoswami@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:32:27 +0530 Subject: [PATCH 253/394] Create decimaltobinary --- decimaltobinary | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 decimaltobinary diff --git a/decimaltobinary b/decimaltobinary new file mode 100644 index 00000000..246fccbe --- /dev/null +++ b/decimaltobinary @@ -0,0 +1,34 @@ +// C++ program to convert a decimal +// number to binary number + +#include +using namespace std; + +// function to convert decimal to binary +void decToBinary(int n) +{ + // array to store binary number + int binaryNum[32]; + + // counter for binary array + int i = 0; + while (n > 0) { + + // storing remainder in binary array + binaryNum[i] = n % 2; + n = n / 2; + i++; + } + + // printing binary array in reverse order + for (int j = i - 1; j >= 0; j--) + cout << binaryNum[j]; +} + +// Driver program to test above function +int main() +{ + int n = 17; + decToBinary(n); + return 0; +} From 6678394b1d2c00ac5be599f075836f3046f01fd5 Mon Sep 17 00:00:00 2001 From: Fazalahmad44 <71704478+Fazalahmad44@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:38:38 +0530 Subject: [PATCH 254/394] C pattern program n=... --- pattern programs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pattern programs diff --git a/pattern programs b/pattern programs new file mode 100644 index 00000000..caad6b52 --- /dev/null +++ b/pattern programs @@ -0,0 +1,18 @@ +#include + +int main() +{ int i,j,n; +printf("enter n= "); +scanf("%d",&n); +for(i=1;i<=n;i++) +{ + for(j=1;j<=n;j++) + {if(i==j) + printf("\\"); + else if(i+j==n+1) + printf("/"); + else printf("*"); + } + printf("\n"); + +}} From ea0c7257d5b1ec67de47356beaa31278087e973b Mon Sep 17 00:00:00 2001 From: Fazalahmad44 <71704478+Fazalahmad44@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:41:34 +0530 Subject: [PATCH 255/394] C Pattern n=... --- C Pattern | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 C Pattern diff --git a/C Pattern b/C Pattern new file mode 100644 index 00000000..99c37768 --- /dev/null +++ b/C Pattern @@ -0,0 +1,18 @@ +include + +int main() +{ int i,j,n; +printf("enter n= "); +scanf("%d",&n); +for(i=1;i<=n;i++) +{ + for(j=1;j<=n;j++) + {if(i==j) + printf("\\"); + else if(i+j==n+1) + printf("/"); + else printf("*"); + } + printf("\n"); + +}} From 6b77d619c4627d1d630fcfba68512ea0d7ddc7c2 Mon Sep 17 00:00:00 2001 From: nikengoswami <66886066+nikengoswami@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:43:27 +0530 Subject: [PATCH 256/394] hexadecimaltodecimal converts hexadecimal to decimal --- hexadecimaltodecimal | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 hexadecimaltodecimal diff --git a/hexadecimaltodecimal b/hexadecimaltodecimal new file mode 100644 index 00000000..e24680c4 --- /dev/null +++ b/hexadecimaltodecimal @@ -0,0 +1,51 @@ +// C++ program to convert hexadecimal to decimal +#include +#include +using namespace std; + +// Function to convert hexadecimal to decimal +int hexadecimalToDecimal(char hexVal[]) +{ + int len = strlen(hexVal); + + // Initializing base value to 1, i.e 16^0 + int base = 1; + + int dec_val = 0; + + // Extracting characters as digits from last character + for (int i=len-1; i>=0; i--) + { + // if character lies in '0'-'9', converting + // it to integral 0-9 by subtracting 48 from + // ASCII value. + if (hexVal[i]>='0' && hexVal[i]<='9') + { + dec_val += (hexVal[i] - 48)*base; + + // incrementing base by power + base = base * 16; + } + + // if character lies in 'A'-'F' , converting + // it to integral 10 - 15 by subtracting 55 + // from ASCII value + else if (hexVal[i]>='A' && hexVal[i]<='F') + { + dec_val += (hexVal[i] - 55)*base; + + // incrementing base by power + base = base*16; + } + } + + return dec_val; +} + +// Driver program to test above function +int main() +{ + char hexNum[] = "1A"; + cout << hexadecimalToDecimal(hexNum) << endl; + return 0; +} From bbfd07c2f6b3c43768e21e1049a2d73ac7d7bbaa Mon Sep 17 00:00:00 2001 From: YASH3166 <70128865+YASH3166@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:57:43 +0530 Subject: [PATCH 257/394] biggernumber program to find the greatest of two number in c --- biggernumber | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 biggernumber diff --git a/biggernumber b/biggernumber new file mode 100644 index 00000000..44608557 --- /dev/null +++ b/biggernumber @@ -0,0 +1,24 @@ +/* C Program to Find Largest of Two numbers */ + +#include + +int main() { + int a, b; + printf("Please Enter Two different values\n"); + scanf("%d %d", &a, &b); + + if(a > b) + { + printf("%d is Largest\n", a); + } + else if (b > a) + { + printf("%d is Largest\n", b); + } + else + { + printf("Both are Equal\n"); + } + + return 0; +} From 5e538f7d76a290b5b13582e25f62a83e6be54605 Mon Sep 17 00:00:00 2001 From: Samarth2104 <72270188+Samarth2104@users.noreply.github.com> Date: Sat, 3 Oct 2020 07:52:44 +0530 Subject: [PATCH 258/394] Convert decimal to binary This program converts a decimal number into binary. --- Convert decimal to binary | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Convert decimal to binary diff --git a/Convert decimal to binary b/Convert decimal to binary new file mode 100644 index 00000000..41e931f8 --- /dev/null +++ b/Convert decimal to binary @@ -0,0 +1,31 @@ +#include +using namespace std; + +// function to convert decimal to binary +void decToBinary(int n) +{ + // array to store binary number + int binaryNum[32]; + + // counter for binary array + int i = 0; + while (n > 0) { + + // storing remainder in binary array + binaryNum[i] = n % 2; + n = n / 2; + i++; + } + + // printing binary array in reverse order + for (int j = i - 1; j >= 0; j--) + cout << binaryNum[j]; +} + +// Driver program to test above function +int main() +{ + int n = 17; + decToBinary(n); + return 0; +} From bae24824a3c3c325dcfe9e038b1a27eb7bf0b64a Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Sat, 3 Oct 2020 08:07:21 +0530 Subject: [PATCH 259/394] Neon C program to find a neon number A neon number is a number where the sum of digits of square of the number is equal to the number. For example, if the input number is 9, its square is 9*9 = 81 and the sum of the digits is 9. i.e. 9 is a neon. --- Neon | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Neon diff --git a/Neon b/Neon new file mode 100644 index 00000000..e2a5fb77 --- /dev/null +++ b/Neon @@ -0,0 +1,28 @@ +#include +int isNeon(int num) +{ + //storing the square of x + int square = 0; + //Store sum of digits (square number) + int sum_digits = 0; + //Calculate square of given number + square = (num * num); + while (square != 0) + { + sum_digits = (sum_digits + (square % 10)); + square = (square / 10); + } + return (sum_digits == num); +} +int main() +{ + int data = 0; + int isNeonNumber = 0; + //Ask to enter the number + printf("Enter the number = "); + scanf("%d",&data); + // if is isNeonNumber is 1, then neon number + isNeonNumber = isNeon(data); + (isNeonNumber)? printf("neon number\n\n"):printf("Not a neon number\n\n"); + return 0; +} From 54f9bc07628624519dffafb363bead391932f9da Mon Sep 17 00:00:00 2001 From: Ritanshusharma2 <72288468+Ritanshusharma2@users.noreply.github.com> Date: Sat, 3 Oct 2020 08:24:13 +0530 Subject: [PATCH 260/394] gretter new Program to find the greatest of two number in c --- gretter new | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 gretter new diff --git a/gretter new b/gretter new new file mode 100644 index 00000000..3b23501c --- /dev/null +++ b/gretter new @@ -0,0 +1,18 @@ +/ C program to find the greatest of two numbers + +#include +int main() +{ +//Fill the code +int num1, num2; +scanf(“%d %d”,&num1,&num2); +if(num1 > num2) +{ +printf(“%d is greater”,num1); +} +else +{ +printf(“%d is greater”,num2); +} +return 0; +} From 8235d62a6027c4033b7c01f78ff19dc318d78922 Mon Sep 17 00:00:00 2001 From: rahulkumarcse102 <72254492+rahulkumarcse102@users.noreply.github.com> Date: Sat, 3 Oct 2020 08:41:35 +0530 Subject: [PATCH 261/394] infix to postfix c program to convert an infix expression in to postfix expression --- infix to postfix | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 infix to postfix diff --git a/infix to postfix b/infix to postfix new file mode 100644 index 00000000..d51271b8 --- /dev/null +++ b/infix to postfix @@ -0,0 +1,110 @@ +#include +#include +#include +// Stack type +struct Stack +{ + int top; + unsigned capacity; + int* array; +}; +// Stack Operations +struct Stack* createStack( unsigned capacity ) +{ + struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack)); + if (!stack) + return NULL; + stack->top = -1; + stack->capacity = capacity; + stack->array = (int*) malloc(stack->capacity * sizeof(int)); + return stack; +} +int isEmpty(struct Stack* stack) +{ + return stack->top == -1 ; +} +char peek(struct Stack* stack) +{ + return stack->array[stack->top]; +} +char pop(struct Stack* stack) +{ + if (!isEmpty(stack)) + return stack->array[stack->top--] ; + return '$'; + } +void push(struct Stack* stack, char op) +{ + stack->array[++stack->top] = op; +} +// A utility function to check if the given character is operand +int isOperand(char ch) +{ + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); +} +// A utility function to return precedence of a given operator +// Higher returned value means higher precedence +int Prec(char ch) +{ + switch (ch) + { + case '+': + case '-': + return 1; + case '*': + case '/': + return 2; + case '^': + return 3; + } +return -1; +} +// The main function that converts given infix expression +// to postfix expression. +int infixToPostfix(char* exp) +{ + int i, k; + // Create a stack of capacity equal to expression size + struct Stack* stack = createStack(strlen(exp)); + if(!stack) // See if stack was created successfully + return -1 ; + for (i = 0, k = -1; exp[i]; ++i) + { + // If the scanned character is an operand, add it to output. + if (isOperand(exp[i])) + exp[++k] = exp[i]; + // If the scanned character is an ‘(‘, push it to the stack. + else if (exp[i] == '(') + push(stack, exp[i]); + // If the scanned character is an ‘)’, pop and output from the stack + // until an ‘(‘ is encountered. + else if (exp[i] == ')') + { + while (!isEmpty(stack) && peek(stack) != '(') + exp[++k] = pop(stack); + if (!isEmpty(stack) && peek(stack) != '(') + return -1; // invalid expression + else + pop(stack); + } + else // an operator is encountered + { + while (!isEmpty(stack) && Prec(exp[i]) <= Prec(peek(stack))) + exp[++k] = pop(stack); + push(stack, exp[i]); + } + } + // pop all the operators from the stack + while (!isEmpty(stack)) + exp[++k] = pop(stack ); + exp[++k] = '\0'; + printf( "%s", exp ); +} +// Driver program to test above functions +int main() +{ + char exp[]={ "a+b*(c^d-e)^(f+g*h)-i"}; + printf("OUTPUT IS:\n"); + infixToPostfix(exp); + return 0; + } From b67c3ad1dae23002b00c1d0d5c1e9c0a4baf8298 Mon Sep 17 00:00:00 2001 From: abhishek-a11y <72289106+abhishek-a11y@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:03:40 +0530 Subject: [PATCH 262/394] Greaterno program to find the greatest of two numbers in C --- program to find the greatest of two numbers in C | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 program to find the greatest of two numbers in C diff --git a/program to find the greatest of two numbers in C b/program to find the greatest of two numbers in C new file mode 100644 index 00000000..73c31935 --- /dev/null +++ b/program to find the greatest of two numbers in C @@ -0,0 +1,15 @@ +#include +#include +int main() +{ + int a, b, big; + printf("Enter any two number: "); + scanf("%d%d", &a, &b); + if(a>b) + big=a; + else + big=b; + printf("\nBiggest of the two number is: %d", big); + getch(); + return 0; +} From f16d47d14befcfb6321d6a3e7cfdd2df82004b7a Mon Sep 17 00:00:00 2001 From: Deepak0748 <72266575+Deepak0748@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:20:51 +0530 Subject: [PATCH 263/394] multiply Program to Multiply Two Numbers in c --- multiply | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 multiply diff --git a/multiply b/multiply new file mode 100644 index 00000000..6aabbae8 --- /dev/null +++ b/multiply @@ -0,0 +1,14 @@ +#include +int main() { + double a, b, product; + printf("Enter two numbers: "); + scanf("%lf %lf", &a, &b); + + // Calculating product + product = a * b; + + // Result up to 2 decimal point is displayed using %.2lf + printf("Product = %.2lf", product); + + return 0; +} From efeaf4e027cfe75513b85ecaf98db80a6e2cdbae Mon Sep 17 00:00:00 2001 From: Pratyush2005 <72202147+Pratyush2005@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:39:11 +0530 Subject: [PATCH 264/394] Smart Calculator A fast working calculator --- Smart Calculator | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Smart Calculator diff --git a/Smart Calculator b/Smart Calculator new file mode 100644 index 00000000..8aed0821 --- /dev/null +++ b/Smart Calculator @@ -0,0 +1,48 @@ +# Program make a simple calculator + +# This function adds two numbers +def add(x, y): + return x + y + +# This function subtracts two numbers +def subtract(x, y): + return x - y + +# This function multiplies two numbers +def multiply(x, y): + return x * y + +# This function divides two numbers +def divide(x, y): + return x / y + + +print("Select operation.") +print("1.Add") +print("2.Subtract") +print("3.Multiply") +print("4.Divide") + +while True: + # Take input from the user + choice = input("Enter choice(1/2/3/4): ") + + # Check if choice is one of the four options + if choice in ('1', '2', '3', '4'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + + elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + + elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + + elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + break + else: + print("Invalid Input") From b28df12af1c00369ad7067c507d0453a5fda4c60 Mon Sep 17 00:00:00 2001 From: MishraVishal-crypto <66715904+MishraVishal-crypto@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:12:22 +0530 Subject: [PATCH 265/394] Revert "ReverseString" --- ...erse a String using C programming Language | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 How to Reverse a String using C programming Language diff --git a/How to Reverse a String using C programming Language b/How to Reverse a String using C programming Language deleted file mode 100644 index 16834b69..00000000 --- a/How to Reverse a String using C programming Language +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -void main() -{ - int i, j, k; - char str[100]; - char rev[100]; - printf("Enter a string:\t"); - scanf("%s", str); - printf("The original string is %s\n", str); - for(i = 0; str[i] != '\0'; i++); - { - k = i-1; - } - for(j = 0; j <= i-1; j++) - { - rev[j] = str[k]; - k--; - } - printf("The reverse string is %s\n", rev); - getch(); -} From e95324599167725bb55563608a85c8ec9f95db0b Mon Sep 17 00:00:00 2001 From: Royalsolanki <68107825+Royalsolanki@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:39:57 +0530 Subject: [PATCH 266/394] Create C Program to print Number Triangle --- C Program to print Number Triangle | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 C Program to print Number Triangle diff --git a/C Program to print Number Triangle b/C Program to print Number Triangle new file mode 100644 index 00000000..e08868c3 --- /dev/null +++ b/C Program to print Number Triangle @@ -0,0 +1,25 @@ +#include +#include +int main(){ + int i,j,k,l,n; +system("cls"); +printf("enter the range="); +scanf("%d",&n); +for(i=1;i<=n;i++) +{ +for(j=1;j<=n-i;j++) +{ +printf(" "); +} +for(k=1;k<=i;k++) +{ +printf("%d",k); +} +for(l=i-1;l>=1;l--) +{ +printf("%d",l); +} +printf("\n"); +} +return 0; +} From 5d653228306d5d2d89c8eaf8a67b3504e3f41e84 Mon Sep 17 00:00:00 2001 From: Royalsolanki <68107825+Royalsolanki@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:42:03 +0530 Subject: [PATCH 267/394] Create C Program to print Alphabet Triangle --- C Program to print Alphabet Triangle | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 C Program to print Alphabet Triangle diff --git a/C Program to print Alphabet Triangle b/C Program to print Alphabet Triangle new file mode 100644 index 00000000..6f01273b --- /dev/null +++ b/C Program to print Alphabet Triangle @@ -0,0 +1,20 @@ +#include +#include +int main(){ + int ch=65; + int i,j,k,m; + system("cls"); + for(i=1;i<=5;i++) + { + for(j=5;j>=i;j--) + printf(" "); + for(k=1;k<=i;k++) + printf("%c",ch++); + ch--; + for(m=1;m Date: Sat, 3 Oct 2020 10:43:00 +0530 Subject: [PATCH 268/394] Create C Program to convert Decimal to Binary --- C Program to convert Decimal to Binary | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 C Program to convert Decimal to Binary diff --git a/C Program to convert Decimal to Binary b/C Program to convert Decimal to Binary new file mode 100644 index 00000000..7a53d3f7 --- /dev/null +++ b/C Program to convert Decimal to Binary @@ -0,0 +1,19 @@ +#include +#include +int main(){ +int a[10],n,i; +system ("cls"); +printf("Enter the number to convert: "); +scanf("%d",&n); +for(i=0;n>0;i++) +{ +a[i]=n%2; +n=n/2; +} +printf("\nBinary of Given Number is="); +for(i=i-1;i>=0;i--) +{ +printf("%d",a[i]); +} +return 0; +} From deeeb1b4c81271fd2d4f7a99cd4088b3f343d214 Mon Sep 17 00:00:00 2001 From: Royalsolanki <68107825+Royalsolanki@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:43:56 +0530 Subject: [PATCH 269/394] Create Octal to Hexadecimal in C --- Octal to Hexadecimal in C | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Octal to Hexadecimal in C diff --git a/Octal to Hexadecimal in C b/Octal to Hexadecimal in C new file mode 100644 index 00000000..539ac8c6 --- /dev/null +++ b/Octal to Hexadecimal in C @@ -0,0 +1,97 @@ +#include +#include +int main() +{ + int octaltobinary[]={0,1,10,11,100,101,110,111}; + char hexadecimal[10]; + char hex[10]; + long int binary=0; + int octal; + int rem=0; + int position=1; + int len=0; + int k=0; + printf("Enter a octal number"); + scanf("%d",&octal); +// Converting octal number into a binary number. +while(octal!=0) + { + rem=octal%10; + binary=octaltobinary[rem]*position+binary; + octal=octal/10; + position=position*1000; + } + printf("The binary number is : %ld",binary); + + // Converting binary number into a hexadecimal number. + while(binary > 0) + { + rem = binary % 10000; + switch(rem) + { + case 0: + strcat(hexadecimal, "0"); + break; + case 1: + strcat(hexadecimal, "1"); + break; + case 10: + strcat(hexadecimal, "2"); + break; + case 11: + strcat(hexadecimal, "3"); + break; + case 100: + strcat(hexadecimal, "4"); + break; + case 101: + strcat(hexadecimal, "5"); + break; + case 110: + strcat(hexadecimal, "6"); + break; + case 111: + strcat(hexadecimal, "7"); + break; + case 1000: + strcat(hexadecimal, "8"); + break; + case 1001: + strcat(hexadecimal, "9"); + break; + case 1010: + strcat(hexadecimal, "A"); + break; + case 1011: + strcat(hexadecimal, "B"); + break; + case 1100: + strcat(hexadecimal, "C"); + break; + case 1101: + strcat(hexadecimal, "D"); + break; + case 1110: + strcat(hexadecimal, "E"); + break; + case 1111: + strcat(hexadecimal, "F"); + break; + } +len=len+1; + binary /= 10000; + } + for(int i=len-1;i>=0;i--) +{ + hex[k]=hexadecimal[i]; + k++; +} +hex[len]='\0'; +printf("\nThe hexadecimal number is :"); +for(int i=0; hex[i]!='\0';i++) +{ + printf("%c",hex[i]); +} + + return 0; +} From 36f5057ca6b12d0ce1b28b4329f306ab8f005997 Mon Sep 17 00:00:00 2001 From: InfinityEye <60550405+InfinityEye@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:49:17 +0530 Subject: [PATCH 270/394] Greatest Integer Find the greatest integer among 2 integer input. --- Greater Integer | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Greater Integer diff --git a/Greater Integer b/Greater Integer new file mode 100644 index 00000000..7df937ac --- /dev/null +++ b/Greater Integer @@ -0,0 +1,9 @@ +#include +#include +using namespace std; +int main(){ + int a,b; + cin>>a>>b; + cout< Date: Sat, 3 Oct 2020 01:22:25 -0400 Subject: [PATCH 271/394] Update Array --- Array | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Array b/Array index a328ddc9..e7c71599 100644 --- a/Array +++ b/Array @@ -1,18 +1,19 @@ -// Program to take 5 values from the user and store them in an array +/ Program to take 5 values from the user and store them in an array // Print the elements stored in the array #include int main() { int values[5]; - printf("Enter 5 integers: "); + printf("Enter 5 integers:\n"); // taking input and storing it in an array for(int i = 0; i < 5; ++i) { scanf("%d", &values[i]); + } - printf("Displaying integers: "); + printf("Displaying integers:\n"); // printing elements of an array for(int i = 0; i < 5; ++i) { From 9cccb94e6b250c901b22758386394faa5c44df68 Mon Sep 17 00:00:00 2001 From: prathameshviralekar <71594205+prathameshviralekar@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:54:54 +0530 Subject: [PATCH 272/394] Create Half pyramid of * The program creates a half pyramid of *. --- Half pyramid of * | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Half pyramid of * diff --git a/Half pyramid of * b/Half pyramid of * new file mode 100644 index 00000000..70a1a944 --- /dev/null +++ b/Half pyramid of * @@ -0,0 +1,13 @@ +#include +int main() { + int i, j, rows; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 1; i <= rows; ++i) { + for (j = 1; j <= i; ++j) { + printf("* "); + } + printf("\n"); + } + return 0; +} From 374a2dbd0dce270f9ca845164bac639668955ab8 Mon Sep 17 00:00:00 2001 From: JAYANTI MALA <52104784+jayantimala@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:56:52 +0530 Subject: [PATCH 273/394] Selection sort Sorting an array using selection sort in C. --- Selection sort | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Selection sort diff --git a/Selection sort b/Selection sort new file mode 100644 index 00000000..90425629 --- /dev/null +++ b/Selection sort @@ -0,0 +1,34 @@ +#include +int main(){ + /* Here i & j for loop counters, temp for swapping, + * count for total number of elements, number[] to + * store the input numbers in array. You can increase + * or decrease the size of number array as per requirement + */ + int i, j, count, temp, number[25]; + + printf("How many numbers u are going to enter?: "); + scanf("%d",&count); + + printf("Enter %d elements: ", count); + // Loop to get the elements stored in array + for(i=0;inumber[j]){ + temp=number[i]; + number[i]=number[j]; + number[j]=temp; + } + } + } + + printf("Sorted elements: "); + for(i=0;i Date: Sat, 3 Oct 2020 11:13:55 +0530 Subject: [PATCH 274/394] Leap Year Checker C program to check whether the year is a leap year or not. --- Leap Year Checker | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Leap Year Checker diff --git a/Leap Year Checker b/Leap Year Checker new file mode 100644 index 00000000..2b513647 --- /dev/null +++ b/Leap Year Checker @@ -0,0 +1,26 @@ +#include +int main() +{ + int y; + + printf("Enter year: "); + scanf("%d",&y); + + if(y % 4 == 0) + { + //Nested if else + if( y % 100 == 0) + { + if ( y % 400 == 0) + printf("%d is a Leap Year", y); + else + printf("%d is not a Leap Year", y); + } + else + printf("%d is a Leap Year", y ); + } + else + printf("%d is not a Leap Year", y); + + return 0; +} From 40817ecd56ee8f5f8d39332cc1f75a2d3996eb98 Mon Sep 17 00:00:00 2001 From: shubham thakre <37706059+shubhthakre@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:16:59 +0530 Subject: [PATCH 275/394] C Program to identify missing Numbers in a given Array This C Program identifies missing numbers in a given array. Here is source code of the C Program to identify missing numbers in a given array. The C program is successfully compiled and run on a Linux system. The program output is also shown below. output should be : Enter size of array : 6 Enter elements into array : 1 2 3 5 6 Missing element is : 4 --- Identifies_missing_numbers | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Identifies_missing_numbers diff --git a/Identifies_missing_numbers b/Identifies_missing_numbers new file mode 100644 index 00000000..4d7944e0 --- /dev/null +++ b/Identifies_missing_numbers @@ -0,0 +1,23 @@ +/* + * C Program to identify missing numbers in a given array + */ +#include + +void main() +{ + int n, i, j, c, t, b; + + printf("Enter size of array : "); + scanf("%d", &n); + int array[n - 1]; /* array size-1 */ + printf("Enter elements into array : \n"); + for (i = 0; i < n - 1; i++) + scanf("%d", &array[i]); + b = array[0]; + for (i = 1; i < n - 1; i++) + b = b ^ array[i]; + for (i = 2, c = 1; i <= n; i++) + c = c ^ i; + c = c ^ b; + printf("Missing element is : %d \n", c); +} From e58c29fbd39edae519f641f53a53ace48d7fe0ba Mon Sep 17 00:00:00 2001 From: Swappy012 <72292418+Swappy012@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:18:16 +0530 Subject: [PATCH 276/394] squareno Program to find square of two no --- squarepogram | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 squarepogram diff --git a/squarepogram b/squarepogram new file mode 100644 index 00000000..8cad1a4f --- /dev/null +++ b/squarepogram @@ -0,0 +1,19 @@ +#include + +double square(double num) +{ + return (num * num); +} +int main() +{ + int num; + double n; + printf("\n\n Function : find square of any number :\n"); + printf("------------------------------------------------\n"); + + printf("Input any number for square : "); + scanf("%d", &num); + n = square(num); + printf("The square of %d is : %.2f\n", num, n); + return 0; +} From d5d86b5a4fff6acbf6df24b97966985cb1f08d1c Mon Sep 17 00:00:00 2001 From: RitvizRanjan <71558635+RitvizRanjan@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:39:22 +0530 Subject: [PATCH 277/394] hangaman game Hangman Game in C is a simple C program which has been designed to demonstrate different application formats and syntaxes of C programming language. The game is very simple to play and the coding has been done such as way that the applicatoin is an interesting and entertaining game. In the game, there is not any use of graphics, user defined function and user defined header file. --- hangman game | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 hangman game diff --git a/hangman game b/hangman game new file mode 100644 index 00000000..d9843926 --- /dev/null +++ b/hangman game @@ -0,0 +1,87 @@ +#include +#include +#include + +void main() +{ +int i,j,c,count=0,ans=0,flag=0,*ptr; +char a[1][6]={"dogodo"}; + +char b[10],alpha; +char d='_'; +clrscr(); +c=strlen(&a[0][0]); +//printf("\n\t\t**************\n\n\t\t\t"); +printf("\n\n\t\t\t ** HANGMAN ** \n"); + printf("\n\t\t\t**************\t\t\t"); + printf("\n\t\t\t..............\n\n\t\t\t "); +for(j=0;j Date: Sat, 3 Oct 2020 11:41:54 +0530 Subject: [PATCH 278/394] Sleep_sort MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) The above algorithm tries to sort it in ascending order. Can you sort an input array in descending order using sleep sort. Think upon it. 2) Is it a comparison based sorting algorithm ? How many comparisons this algorithm makes ? [ Answer : No, it makes zero comparisons ] 3) Can we do sleeping sort without using windows.h header and without using Sleep() function? [One idea can be to create a priority queue where the elements are arranged according to the time left before waking up and getting printed. The element at the front of the priority queue will be the first one to get waked up. However the implementation doesn’t looks easy. Think on it.] Time Complexity Although there are many conflicting opinions about the time complexity of sleep sort, but we can approximate the time complexity using the below reasoning- Since Sleep() function and creating multiple threads is done internally by the OS using a priority queue (used for scheduling purposes). Hence inserting all the array elements in the priority queue takes O(Nlog N) time. Also the output is obtained only when all the threads are processed, i.e- when all the elements ‘wakes’ up. Since it takes O(arr[i]) time to wake the ith array element’s thread. So it will take a maximum of O(max(input)) for the largest element of the array to wake up. Thus the overall time complexity can be assumed as O(NlogN + max(input)), where, N = number of elements in the input array, and input = input array elements Auxiliary Space All the things are done by the internal priority queue of the OS. Hence auxiliary space can be ignored. Conclusion Sleep Sort is related to Operating System more than any other sorting algorithm. This sorting algorithm is a perfect demonstration of multi-threading and scheduling done by OS. The phrase “Sorting while Sleeping” itself sounds very unique. Overall it is a fun, lazy, weird algorithm. But as rightly said by someone- “If it works then it is not lazy”. --- sleep_sort | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sleep_sort diff --git a/sleep_sort b/sleep_sort new file mode 100644 index 00000000..fb23ad86 --- /dev/null +++ b/sleep_sort @@ -0,0 +1,40 @@ +#include +#include +#include +void routine(void *a) +{ + int n = *(int *) a; // typecasting from void to int + + // Sleeping time is proportional to the number + // More precisely this thread sleep for 'n' milliseconds + Sleep(n); + + // After the sleep, print the number + printf("%d ", n); +} +void sleepSort(int arr[], int n) +{ + // An array of threads, one for each of the elements + // in the input array + HANDLE threads[n]; + + // Create the threads for each of the input array elements + for (int i = 0; i < n; i++) + threads[i] = (HANDLE)_beginthread(&routine, 0, &arr[i]); + + // Process these threads + WaitForMultipleObjects(n, threads, TRUE, INFINITE); + return; +} + +// Driver program to test above functions +int main() +{ + // Doesn't work for negative numbers + int arr[] = {34, 23, 122, 9}; + int n = sizeof(arr) / sizeof(arr[0]); + + sleepSort (arr, n); + + return(0); +} From 78c276595f48e4cb96a267e06c5bd9e29f335e7d Mon Sep 17 00:00:00 2001 From: irshad958 <72293072+irshad958@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:52:28 +0530 Subject: [PATCH 279/394] multiple of 3 program to find multiple of 3.. --- multiple of 3 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 multiple of 3 diff --git a/multiple of 3 b/multiple of 3 new file mode 100644 index 00000000..e7bf35ba --- /dev/null +++ b/multiple of 3 @@ -0,0 +1,14 @@ +#include +using namespace std; + +void findMultiples(int n){ + for(int i = 0; i <= n; i++) + if(i % 3 == 0 && i % 5 == 0) + cout << i << endl; +} + +int main() { + findMultiples(120); + + return 0; +} From e08f347ee74f7799e135089b59fb591251281c6a Mon Sep 17 00:00:00 2001 From: ANAND SAURAV <72293098+anandsaurav07@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:59:29 +0530 Subject: [PATCH 280/394] bubble_sort bubble sort using C. --- bubble_sort | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 bubble_sort diff --git a/bubble_sort b/bubble_sort new file mode 100644 index 00000000..a491d8db --- /dev/null +++ b/bubble_sort @@ -0,0 +1,32 @@ +#include + +int main(){ + + int count, temp, i, j, number[30]; + + printf("How many numbers are u going to enter?: "); + scanf("%d",&count); + + printf("Enter %d numbers: ",count); + + for(i=0;i=0;i--){ + for(j=0;j<=i;j++){ + if(number[j]>number[j+1]){ + temp=number[j]; + number[j]=number[j+1]; + number[j+1]=temp; + } + } + } + + printf("Sorted elements: "); + for(i=0;i Date: Sat, 3 Oct 2020 12:27:44 +0530 Subject: [PATCH 281/394] Matrix Multiplication Program to Multiply 2D matrix in C. --- 2D Matrix Multiplication | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 2D Matrix Multiplication diff --git a/2D Matrix Multiplication b/2D Matrix Multiplication new file mode 100644 index 00000000..f6a47566 --- /dev/null +++ b/2D Matrix Multiplication @@ -0,0 +1,51 @@ +#include + +int main() +{ + int m, n, p, q, c, d, k, sum = 0; + int first[10][10], second[10][10], multiply[10][10]; + + printf("Enter number of rows and columns of first matrix\n"); + scanf("%d%d", &m, &n); + printf("Enter elements of first matrix\n"); + + for (c = 0; c < m; c++) + for (d = 0; d < n; d++) + scanf("%d", &first[c][d]); + + printf("Enter number of rows and columns of second matrix\n"); + scanf("%d%d", &p, &q); + + if (n != p) + printf("The multiplication isn't possible.\n"); + else + { + printf("Enter elements of second matrix\n"); + + for (c = 0; c < p; c++) + for (d = 0; d < q; d++) + scanf("%d", &second[c][d]); + + for (c = 0; c < m; c++) { + for (d = 0; d < q; d++) { + for (k = 0; k < p; k++) { + sum = sum + first[c][k]*second[k][d]; + } + + multiply[c][d] = sum; + sum = 0; + } + } + + printf("Product of the matrices:\n"); + + for (c = 0; c < m; c++) { + for (d = 0; d < q; d++) + printf("%d\t", multiply[c][d]); + + printf("\n"); + } + } + + return 0; +} From 152053233c5ebe5cc40816082c28552b06d1fb5e Mon Sep 17 00:00:00 2001 From: ankitsingh999 <55996182+ankitsingh999@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:28:12 +0530 Subject: [PATCH 282/394] factoralbyrecursion program to find factorial by recursion --- factorial by recursion | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 factorial by recursion diff --git a/factorial by recursion b/factorial by recursion new file mode 100644 index 00000000..4c4cbe7b --- /dev/null +++ b/factorial by recursion @@ -0,0 +1,22 @@ +#include +#include + +int fact(int); + +int main() { + int factorial, num; + + printf("Enter the value of num :"); + scanf("%d", &num); + + factorial = fact(num); + printf("Factorial is %d", factorial); + + return (0); +} + +int fact(int n) { + if (n == 0) { + return (1); + } + return (n * fact(n - 1)); From 345d80dddbb5315cb0d5891b11ddc0a6cabdd3d7 Mon Sep 17 00:00:00 2001 From: shockwave <38135550+shockwave008@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:35:22 +0530 Subject: [PATCH 283/394] bubble sort program Optimized Implementation of Bubble Sort Program --- optimized implementation of bubble sort | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 optimized implementation of bubble sort diff --git a/optimized implementation of bubble sort b/optimized implementation of bubble sort new file mode 100644 index 00000000..386b2f00 --- /dev/null +++ b/optimized implementation of bubble sort @@ -0,0 +1,31 @@ +#include +int main() +{ +int array[100], n, i, j, swap,flag=0; +printf("Enter number of elementsn"); +scanf("%d", &n); +printf("Enter %d Numbers:n", n); +for(i = 0; i < n; i++) +scanf("%d", &array[i]); +for(i = 0 ; i < n - 1; i++) +{ +for(j = 0 ; j < n-i-1; j++) +{ +if(array[j] > array[j+1]) +{ +swap = array[j]; +array[j] = array[j+1]; +array[j+1] = swap; +flag=1; +} +if(!flag) +{ +break; +} +} +} +printf("Sorted Array:n"); +for(i = 0; i < n; i++) +printf("%dn", array[i]); +return 0; +} From 94468fd2fa4d09e33b15b07df3304f18a301f95c Mon Sep 17 00:00:00 2001 From: kvikash855 <56692597+kvikash855@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:37:49 +0530 Subject: [PATCH 284/394] Diamond star pattern Diamond star pattern using c --- Star Pattern | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Star Pattern diff --git a/Star Pattern b/Star Pattern new file mode 100644 index 00000000..3aa2cba5 --- /dev/null +++ b/Star Pattern @@ -0,0 +1,30 @@ +#include +int main(void) { + int n; + printf("Enter the number of rows\n"); + scanf("%d",&n); + int spaces=n-1; + int stars=1; + for(int i=1;i<=n;i++) + { + for(int j=1;j<=spaces;j++) + { + printf(" "); + } + for(int k=1;k<=stars;k++) + { + printf("*"); + } + if(spaces>i) + { + spaces=spaces-1; + stars=stars+2; + } + if(spaces Date: Sat, 3 Oct 2020 12:47:35 +0530 Subject: [PATCH 285/394] sum To find sum of two numbers --- Sum of Two numbers | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Sum of Two numbers diff --git a/Sum of Two numbers b/Sum of Two numbers new file mode 100644 index 00000000..4a394004 --- /dev/null +++ b/Sum of Two numbers @@ -0,0 +1,14 @@ +#include + +int main() { + int a, b, sum; + + printf("\nEnter two no: "); + scanf("%d %d", &a, &b); + + sum = a + b; + + printf("Sum : %d", sum); + + return(0); +} From bca950a6bff140e3d252d447797e7c868ac7846b Mon Sep 17 00:00:00 2001 From: harsh56-png <53876344+harsh56-png@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:55:48 +0530 Subject: [PATCH 286/394] Multiply Two Numbers The program gives a basic scenario of how to multiply two numbers --- Multiplication of Two Numbers | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Multiplication of Two Numbers diff --git a/Multiplication of Two Numbers b/Multiplication of Two Numbers new file mode 100644 index 00000000..824fbf98 --- /dev/null +++ b/Multiplication of Two Numbers @@ -0,0 +1,10 @@ +#include +int main() +{ + int num1,num2,product; + printf("Enter two numbers:"); + scanf("%d %d",&num1,&num2); + product=num1*num2; + printf("Product of two numbers: %d",product); + return 0; +} From 6e242eb51c08bc190d0283df4e1524b6b6d63f95 Mon Sep 17 00:00:00 2001 From: Rakesh-14 <72142954+Rakesh-14@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:58:21 +0530 Subject: [PATCH 287/394] Added the Reverse no. Program Program to Reverse a given number --- Reverseno. | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Reverseno. diff --git a/Reverseno. b/Reverseno. new file mode 100644 index 00000000..2555af0a --- /dev/null +++ b/Reverseno. @@ -0,0 +1,13 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + printf("Reversed number = %d", rev); + return 0; +} From b8d121e041fe32d1ccc65230e26b01fbc7593bcd Mon Sep 17 00:00:00 2001 From: Mohit5700 <72152449+Mohit5700@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:04:41 +0530 Subject: [PATCH 288/394] Intersection point of 2 linked lists --- Intersection point of 2 linked list | 121 ++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Intersection point of 2 linked list diff --git a/Intersection point of 2 linked list b/Intersection point of 2 linked list new file mode 100644 index 00000000..000814a5 --- /dev/null +++ b/Intersection point of 2 linked list @@ -0,0 +1,121 @@ +// C program to get intersection point of two linked list +#include +#include + +/* Link list node */ +struct Node { + int data; + struct Node* next; +}; + +/* Function to get the counts of node in a linked list */ +int getCount(struct Node* head); + +/* function to get the intersection point of two linked +lists head1 and head2 where head1 has d more nodes than +head2 */ +int _getIntesectionNode(int d, struct Node* head1, struct Node* head2); + +/* function to get the intersection point of two linked +lists head1 and head2 */ +int getIntesectionNode(struct Node* head1, struct Node* head2) +{ + int c1 = getCount(head1); + int c2 = getCount(head2); + int d; + + if (c1 > c2) { + d = c1 - c2; + return _getIntesectionNode(d, head1, head2); + } + else { + d = c2 - c1; + return _getIntesectionNode(d, head2, head1); + } +} + +/* function to get the intersection point of two linked +lists head1 and head2 where head1 has d more nodes than +head2 */ +int _getIntesectionNode(int d, struct Node* head1, struct Node* head2) +{ + int i; + struct Node* current1 = head1; + struct Node* current2 = head2; + + for (i = 0; i < d; i++) { + if (current1 == NULL) { + return -1; + } + current1 = current1->next; + } + + while (current1 != NULL && current2 != NULL) { + if (current1 == current2) + return current1->data; + current1 = current1->next; + current2 = current2->next; + } + + return -1; +} + +/* Takes head pointer of the linked list and +returns the count of nodes in the list */ +int getCount(struct Node* head) +{ + struct Node* current = head; + int count = 0; + + while (current != NULL) { + count++; + current = current->next; + } + + return count; +} + +/* IGNORE THE BELOW LINES OF CODE. THESE LINES +ARE JUST TO QUICKLY TEST THE ABOVE FUNCTION */ +int main() +{ + /* + Create two linked lists + + 1st 3->6->9->15->30 + 2nd 10->15->30 + + 15 is the intersection point +*/ + + struct Node* newNode; + struct Node* head1 = (struct Node*)malloc(sizeof(struct Node)); + head1->data = 10; + + struct Node* head2 = (struct Node*)malloc(sizeof(struct Node)); + head2->data = 3; + + newNode = (struct Node*)malloc(sizeof(struct Node)); + newNode->data = 6; + head2->next = newNode; + + newNode = (struct Node*)malloc(sizeof(struct Node)); + newNode->data = 9; + head2->next->next = newNode; + + newNode = (struct Node*)malloc(sizeof(struct Node)); + newNode->data = 15; + head1->next = newNode; + head2->next->next->next = newNode; + + newNode = (struct Node*)malloc(sizeof(struct Node)); + newNode->data = 30; + head1->next->next = newNode; + + head1->next->next->next = NULL; + + printf("\n The node of intersection is %d \n", + getIntesectionNode(head1, head2)); + + getchar(); +} From 22e59a76c63d3a33c93dca02a7f3c7bb0b05b52b Mon Sep 17 00:00:00 2001 From: kvikash855 <56692597+kvikash855@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:05:20 +0530 Subject: [PATCH 289/394] Create Floyd warshall algorthim Floyd warshall algorthim using c --- Floyd warshall algorthim | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Floyd warshall algorthim diff --git a/Floyd warshall algorthim b/Floyd warshall algorthim new file mode 100644 index 00000000..d6f102e1 --- /dev/null +++ b/Floyd warshall algorthim @@ -0,0 +1,86 @@ +// C Program for Floyd Warshall Algorithm +#include + +// Number of vertices in the graph +#define V 4 + +/* Define Infinite as a large enough value. This value will be used + for vertices not connected to each other */ +#define INF 99999 + +// A function to print the solution matrix +void printSolution(int dist[][V]); + +// Solves the all-pairs shortest path problem using Floyd Warshall algorithm +void floydWarshall (int graph[][V]) +{ + /* dist[][] will be the output matrix that will finally have the shortest + distances between every pair of vertices */ + int dist[V][V], i, j, k; + + /* Initialize the solution matrix same as input graph matrix. Or + we can say the initial values of shortest distances are based + on shortest paths considering no intermediate vertex. */ + for (i = 0; i < V; i++) + for (j = 0; j < V; j++) + dist[i][j] = graph[i][j]; + + /* Add all vertices one by one to the set of intermediate vertices. + ---> Before start of an iteration, we have shortest distances between all + pairs of vertices such that the shortest distances consider only the + vertices in set {0, 1, 2, .. k-1} as intermediate vertices. + ----> After the end of an iteration, vertex no. k is added to the set of + intermediate vertices and the set becomes {0, 1, 2, .. k} */ + for (k = 0; k < V; k++) + { + // Pick all vertices as source one by one + for (i = 0; i < V; i++) + { + // Pick all vertices as destination for the + // above picked source + for (j = 0; j < V; j++) + { + // If vertex k is on the shortest path from + // i to j, then update the value of dist[i][j] + if (dist[i][k] + dist[k][j] < dist[i][j]) + dist[i][j] = dist[i][k] + dist[k][j]; + } + } + } + + // Print the shortest distance matrix + printSolution(dist); +} + +/* A utility function to print solution */ +void printSolution(int dist[][V]) +{ + printf ("The following matrix shows the shortest distances" + " between every pair of vertices \n"); + for (int i = 0; i < V; i++) + { + for (int j = 0; j < V; j++) + { + if (dist[i][j] == INF) + printf("%7s", "INF"); + else + printf ("%7d", dist[i][j]); + } + printf("\n"); + } +} + +// driver program to test above function +int main() +{ + + int graph[V][V] = { {0, 5, INF, 10}, + {INF, 0, 3, INF}, + {INF, INF, 0, 1}, + {INF, INF, INF, 0} + }; + + // Print the solution + floydWarshall(graph); + return 0; +} From 0260f585e01bc7ba08e41e4913e6195a6707e959 Mon Sep 17 00:00:00 2001 From: kvikash855 <56692597+kvikash855@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:09:26 +0530 Subject: [PATCH 290/394] Create Knapsack problem knapsack problem using c --- Knapsack problem | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Knapsack problem diff --git a/Knapsack problem b/Knapsack problem new file mode 100644 index 00000000..33bff3ae --- /dev/null +++ b/Knapsack problem @@ -0,0 +1,41 @@ +/* A Naive recursive implementation +of 0-1 Knapsack problem */ +#include + +// A utility function that returns +// maximum of two integers +int max(int a, int b) { return (a > b) ? a : b; } + +// Returns the maximum value that can be +// put in a knapsack of capacity W +int knapSack(int W, int wt[], int val[], int n) +{ + // Base Case + if (n == 0 || W == 0) + return 0; + + // If weight of the nth item is more than + // Knapsack capacity W, then this item cannot + // be included in the optimal solution + if (wt[n - 1] > W) + return knapSack(W, wt, val, n - 1); + + // Return the maximum of two cases: + // (1) nth item included + // (2) not included + else + return max( + val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1), + knapSack(W, wt, val, n - 1)); +} + +// Driver program to test above function +int main() +{ + int val[] = { 60, 100, 120 }; + int wt[] = { 10, 20, 30 }; + int W = 50; + int n = sizeof(val) / sizeof(val[0]); + printf("%d", knapSack(W, wt, val, n)); + return 0; +} From 6423ac3783a2a775802c9b15bc0298a55fd33498 Mon Sep 17 00:00:00 2001 From: Pallab Jyoti Sonowal <48851249+pallabj@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:11:42 +0530 Subject: [PATCH 291/394] created version 1 (CLI) of calculator program in C --- advanced calculator CLI | 200 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 advanced calculator CLI diff --git a/advanced calculator CLI b/advanced calculator CLI new file mode 100644 index 00000000..79d546ac --- /dev/null +++ b/advanced calculator CLI @@ -0,0 +1,200 @@ +// Calculator example using C code +#include +#include +#include +#include + +#define KEY "Enter the calculator Operation you want to do:" + +// Function prototype declaration +void addition(); +void subtraction(); +void multiplication(); +void division(); +void modulus(); +void power(); +int factorial(); +void calculator_operations(); + +// Start of Main Program +int main() +{ + int X=1; + char Calc_oprn; + + // Function call + calculator_operations(); + + while(X) + { + printf("\n"); + printf("%s : ", KEY); + + Calc_oprn=getche(); + + switch(Calc_oprn) + { + case '+': addition(); + break; + + case '-': subtraction(); + break; + + case '*': multiplication(); + break; + + case '/': division(); + break; + + case '?': modulus(); + break; + + case '!': factorial(); + break; + + case '^': power(); + break; + + case 'H': + case 'h': calculator_operations(); + break; + + case 'Q': + case 'q': exit(0); + break; + case 'c': + case 'C': system("cls"); + calculator_operations(); + break; + + default : system("cls"); + + printf("\n**********You have entered unavailable option"); + printf("***********\n"); + printf("\n*****Please Enter any one of below available "); + printf("options****\n"); + calculator_operations(); + } + } +} + +//Function Definitions + +void calculator_operations() +{ + //system("cls"); use system function to clear + //screen instead of clrscr(); + printf("\n Welcome to C calculator \n\n"); + + printf("******* Press 'Q' or 'q' to quit "); + printf("the program ********\n"); + printf("***** Press 'H' or 'h' to display "); + printf("below options *****\n\n"); + printf("Enter 'C' or 'c' to clear the screen and"); + printf(" display available option \n\n"); + + printf("Enter + symbol for Addition \n"); + printf("Enter - symbol for Subtraction \n"); + printf("Enter * symbol for Multiplication \n"); + printf("Enter / symbol for Division \n"); + printf("Enter ? symbol for Modulus\n"); + printf("Enter ^ symbol for Power \n"); + printf("Enter ! symbol for Factorial \n\n"); +} + +void addition() +{ + int n, total=0, k=0, number; + printf("\nEnter the number of elements you want to add:"); + scanf("%d",&n); + printf("Please enter %d numbers one by one: \n",n); + while(k Date: Sat, 3 Oct 2020 13:14:26 +0530 Subject: [PATCH 292/394] Create Days Conversion --- Days Conversion | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Days Conversion diff --git a/Days Conversion b/Days Conversion new file mode 100644 index 00000000..22d11b02 --- /dev/null +++ b/Days Conversion @@ -0,0 +1,19 @@ +#include + +int main() +{ + int days, years, weeks; + + printf("Enter days: "); + scanf("%d", &days); + + years = (days / 365); // Ignoring leap year + weeks = (days % 365) / 7; + days = days - ((years * 365) + (weeks * 7)); + + printf("YEARS: %d\n", years); + printf("WEEKS: %d\n", weeks); + printf("DAYS: %d", days); + + return 0; +} From 217778ede838d8a2e3a34ae72ec189098aed4b1f Mon Sep 17 00:00:00 2001 From: Bipul-coder <72294442+Bipul-coder@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:45:18 +0530 Subject: [PATCH 293/394] Leap Year check whether the given year of input is a leap year or not. --- ...given year of input is a leap year or not. | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Check whether the given year of input is a leap year or not. diff --git a/Check whether the given year of input is a leap year or not. b/Check whether the given year of input is a leap year or not. new file mode 100644 index 00000000..27c14559 --- /dev/null +++ b/Check whether the given year of input is a leap year or not. @@ -0,0 +1,22 @@ +#include + +int main() +{ + int year; + printf("Enter a year to check if it is a leap year\n"); + scanf("%d", &year); + + if ( year%400 == 0) + printf("%d is a leap year.\n", year); + + else if ( year%100 == 0) + printf("%d is not a leap year.\n", year); + + else if ( year%4 == 0 ) + printf("%d is a leap year.\n", year); + + else + printf("%d is not a leap year.\n", year); + + return 0; +} From 4c9449b90b951aa70b33928ef534e9e4256f207d Mon Sep 17 00:00:00 2001 From: Aakashtiwari007 Date: Sat, 3 Oct 2020 13:50:16 +0530 Subject: [PATCH 294/394] Create MultiplicationOfMatrix.c --- MultiplicationOfMatrix.c | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 MultiplicationOfMatrix.c diff --git a/MultiplicationOfMatrix.c b/MultiplicationOfMatrix.c new file mode 100644 index 00000000..def03f7b --- /dev/null +++ b/MultiplicationOfMatrix.c @@ -0,0 +1,82 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} From c8f31dce9f903262623917388c72b375fe0981bd Mon Sep 17 00:00:00 2001 From: Jinay Shah <61679442+jinayshah9@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:50:37 +0530 Subject: [PATCH 295/394] Diamond inscribed inside rectangle Here is the program to diamond inscribed inside rectangle . --- hollow diamond | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 hollow diamond diff --git a/hollow diamond b/hollow diamond new file mode 100644 index 00000000..fa50fdae --- /dev/null +++ b/hollow diamond @@ -0,0 +1,43 @@ +#include +int main() +{ + int i, j, n; + scanf("%d", &n); + + // first half + + for(i = 0; i < n; i++) + { + for(j = 0; j < (2 * n); j++) + { + if(i + j <= n - 1) // upper left triangle + printf("*"); + else + printf(" "); + if((i + n) <= j) // upper right triangle + printf("*"); + else + printf(" "); + } + printf("\n"); + } + + // second half + + for(i = 0; i < n; i++) + { + for(j = 0; j < (2 * n); j++) + { + if(i >= j) //bottom left triangle + printf("*"); + else + printf(" "); + if(i >= (2 * n - 1) - j) // bottom right triangle + printf("*"); + else + printf(" "); + } + printf("\n"); + } + return 0; +} From 52d3e03c48045162244268185b43b719a56b10d1 Mon Sep 17 00:00:00 2001 From: Aakashtiwari007 Date: Sat, 3 Oct 2020 13:51:39 +0530 Subject: [PATCH 296/394] Program to Add Two Matrices --- Program to Add Two Matrices | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Program to Add Two Matrices diff --git a/Program to Add Two Matrices b/Program to Add Two Matrices new file mode 100644 index 00000000..7da735bd --- /dev/null +++ b/Program to Add Two Matrices @@ -0,0 +1,27 @@ +#include +int main() { + int r, c, a[100][100], b[100][100], sum[100][100], i, j; + printf("Enter the number of rows (between 1 and 100): "); + scanf("%d", &r); + printf("Enter the number of columns (between 1 and 100): "); + scanf("%d", &c); + + printf("\nEnter elements of 1st matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &a[i][j]); + } + + printf("Enter elements of 2nd matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &b[i][j]); + } + + // adding two matrices + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + sum[i][j] = a[i][j] + b[i][j]; + } From 8136c59721e301b934b70bd784da18390c17d690 Mon Sep 17 00:00:00 2001 From: pratikson <70327865+pratikson@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:58:54 +0530 Subject: [PATCH 297/394] GreatNo. This will find highest of two no. e.g A or B --- greaternumberofAorB | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 greaternumberofAorB diff --git a/greaternumberofAorB b/greaternumberofAorB new file mode 100644 index 00000000..bc12d152 --- /dev/null +++ b/greaternumberofAorB @@ -0,0 +1,22 @@ +// C program to find the greatest of three numbers + +#include +int main() +{ +//Fill the code +int num1, num2, num3; +scanf(“%d %d %d”,&num1,&num2,&num3); +if(num1 > num2 && num1 > num3) +{ +printf(“%d is greater”,num1); +} +else if(num2 > num1 && num2 > num3) +{ +printf(“%d is greater”,num2); +} +else +{ +printf(“%d is greater”,num3); +} +return 0; +} From 6b3b8ce2a95e727d423259e79ee7bc0966a50692 Mon Sep 17 00:00:00 2001 From: gaus1309 <65288686+gaus1309@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:01:31 +0530 Subject: [PATCH 298/394] greaterno10 C Program is used to find the greatest among ten numbers. --- greaterno10 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 greaterno10 diff --git a/greaterno10 b/greaterno10 new file mode 100644 index 00000000..a8d92ee8 --- /dev/null +++ b/greaterno10 @@ -0,0 +1,20 @@ +#include + int main() { + int a[10]; + int i; + int greatest; + printf("Enter ten values:"); + //Store 10 numbers in an array + for (i = 0; i < 10; i++) { + scanf("%d", &a[i]); + } + //Assume that a[0] is greatest + greatest = a[0]; + for (i = 0; i < 10; i++) { +if (a[i] > greatest) { +greatest = a[i]; + } + } + printf(" + Greatest of ten numbers is %d", greatest + } From 1361968533946cb450309de56a9e65dd230bb499 Mon Sep 17 00:00:00 2001 From: karangarg218 <42265308+karangarg218@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:25:20 +0530 Subject: [PATCH 299/394] Created stack using C programming language A topic of data structure based on the rule LIFO . Last in first out --- stack,c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 stack,c diff --git a/stack,c b/stack,c new file mode 100644 index 00000000..d74fe973 --- /dev/null +++ b/stack,c @@ -0,0 +1,73 @@ +// C program for array implementation of stack +#include +#include +#include + +// A structure to represent a stack +struct Stack { + int top; + unsigned capacity; + int* array; +}; + +// function to create a stack of given capacity. It initializes size of +// stack as 0 +struct Stack* createStack(unsigned capacity) +{ + struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack)); + stack->capacity = capacity; + stack->top = -1; + stack->array = (int*)malloc(stack->capacity * sizeof(int)); + return stack; +} + +// Stack is full when top is equal to the last index +int isFull(struct Stack* stack) +{ + return stack->top == stack->capacity - 1; +} + +// Stack is empty when top is equal to -1 +int isEmpty(struct Stack* stack) +{ + return stack->top == -1; +} + +// Function to add an item to stack. It increases top by 1 +void push(struct Stack* stack, int item) +{ + if (isFull(stack)) + return; + stack->array[++stack->top] = item; + printf("%d pushed to stack\n", item); +} + +// Function to remove an item from stack. It decreases top by 1 +int pop(struct Stack* stack) +{ + if (isEmpty(stack)) + return INT_MIN; + return stack->array[stack->top--]; +} + +// Function to return the top from stack without removing it +int peek(struct Stack* stack) +{ + if (isEmpty(stack)) + return INT_MIN; + return stack->array[stack->top]; +} + +// Driver program to test above functions +int main() +{ + struct Stack* stack = createStack(100); + + push(stack, 10); + push(stack, 20); + push(stack, 30); + + printf("%d popped from stack\n", pop(stack)); + + return 0; +} From e5c7161f2871046e23d45c8ddbb67f64fa7fad11 Mon Sep 17 00:00:00 2001 From: ISHA MALNIR <56197904+par123745@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:28:19 +0530 Subject: [PATCH 300/394] C Program for Rat in a Maze Efficient C program to clear Backtracking Concepts --- C Program for Rat in a Maze | 93 +++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 C Program for Rat in a Maze diff --git a/C Program for Rat in a Maze b/C Program for Rat in a Maze new file mode 100644 index 00000000..0742ee22 --- /dev/null +++ b/C Program for Rat in a Maze @@ -0,0 +1,93 @@ + + +#include + +// Maze size +#define N 4 + +bool solveMazeUtil(int maze[N][N], int x, int y, int sol[N][N]); + +/* A utility function to print solution matrix sol[N][N] */ +void printSolution(int sol[N][N]) +{ + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) + printf(" %d ", sol[i][j]); + printf("\n"); + } +} + +/* A utility function to check if x, y is valid index for N*N maze */ +bool isSafe(int maze[N][N], int x, int y) +{ + // if (x, y outside maze) return false + if (x >= 0 && x < N && y >= 0 && y < N && maze[x][y] == 1) + return true; + + return false; +} + +/* This function solves the Maze problem using Backtracking. It mainly + uses solveMazeUtil() to solve the problem. It returns false if no + path is possible, otherwise return true and prints the path in the + form of 1s. Please note that there may be more than one solutions, + this function prints one of the feasible solutions.*/ +bool solveMaze(int maze[N][N]) +{ + int sol[N][N] = { { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 0 } }; + + if (solveMazeUtil(maze, 0, 0, sol) == false) { + printf("Solution doesn't exist"); + return false; + } + + printSolution(sol); + return true; +} + +/* A recursive utility function to solve Maze problem */ +bool solveMazeUtil(int maze[N][N], int x, int y, int sol[N][N]) +{ + // if (x, y is goal) return true + if (x == N - 1 && y == N - 1) { + sol[x][y] = 1; + return true; + } + + // Check if maze[x][y] is valid + if (isSafe(maze, x, y) == true) { + // mark x, y as part of solution path + sol[x][y] = 1; + + /* Move forward in x direction */ + if (solveMazeUtil(maze, x + 1, y, sol) == true) + return true; + + /* If moving in x direction doesn't give solution then + Move down in y direction */ + if (solveMazeUtil(maze, x, y + 1, sol) == true) + return true; + + /* If none of the above movements work then BACKTRACK: + unmark x, y as part of solution path */ + sol[x][y] = 0; + return false; + } + + return false; +} + +// driver program to test above function +int main() +{ + int maze[N][N] = { { 1, 0, 0, 0 }, + { 1, 1, 0, 1 }, + { 0, 1, 0, 0 }, + { 1, 1, 1, 1 } }; + + solveMaze(maze); + return 0; +} From 941db3d24727548519201f407f54c430f1d7555c Mon Sep 17 00:00:00 2001 From: MartianCoder-git <72254243+MartianCoder-git@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:37:46 +0530 Subject: [PATCH 301/394] sine_series C program to find the sine of x using the series : sin x = x - x3/3! + x5/5! - x7/7! + x9/9! ........ --- sine_series | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 sine_series diff --git a/sine_series b/sine_series new file mode 100644 index 00000000..6bf5d1dc --- /dev/null +++ b/sine_series @@ -0,0 +1,29 @@ +#include + +int main() +{ + int i, j, n, fact, sign = - 1; + float x, p, sum = 0; + + printf("Enter the value of x : "); + scanf("%f", &x); + printf("Enter the value of n : "); + scanf("%d", &n); + + for (i = 1; i <= n; i += 2) + { + p = 1; + fact = 1; + for (j = 1; j <= i; j++) + { + p = p * x; + fact = fact * j; + } + sign = - 1 * sign; + sum += sign * p / fact; + } + + printf("sin %0.2f = %f", x, sum); + + return 0; +} From 083ab62722f979d594340f58510657b7f658fd21 Mon Sep 17 00:00:00 2001 From: Sanket Patil <55378662+Sanketpatil45@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:37:48 +0530 Subject: [PATCH 302/394] Heap Sort C Program to sort an array based on heap sort algorithm. --- Heapsort.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Heapsort.c diff --git a/Heapsort.c b/Heapsort.c new file mode 100644 index 00000000..92b2317e --- /dev/null +++ b/Heapsort.c @@ -0,0 +1,58 @@ +/* + * C Program to sort an array based on heap sort algorithm(MAX heap) + */ +#include + +void main() +{ + int heap[10], no, i, j, c, root, temp; + + printf("\n Enter no of elements :"); + scanf("%d", &no); + printf("\n Enter the nos : "); + for (i = 0; i < no; i++) + scanf("%d", &heap[i]); + for (i = 1; i < no; i++) + { + c = i; + do + { + root = (c - 1) / 2; + if (heap[root] < heap[c]) /* to create MAX heap array */ + { + temp = heap[root]; + heap[root] = heap[c]; + heap[c] = temp; + } + c = root; + } while (c != 0); + } + + printf("Heap array : "); + for (i = 0; i < no; i++) + printf("%d\t ", heap[i]); + for (j = no - 1; j >= 0; j--) + { + temp = heap[0]; + heap[0] = heap[j /* swap max element with rightmost leaf element */ + heap[j] = temp; + root = 0; + do + { + c = 2 * root + 1; /* left node of root element */ + if ((heap[c] < heap[c + 1]) && c < j-1) + c++; + if (heap[root] Date: Sat, 3 Oct 2020 14:55:53 +0530 Subject: [PATCH 303/394] created a program two multiply the matrix This C program performs matrix multiplication. In matrix multiplication, we take two matrices of order m*n and p*q respectively to find a resultant matrix of the order m*q where n is equal to p . Time Complexity of this algorithm is O(n3). --- Matrix.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Matrix.c diff --git a/Matrix.c b/Matrix.c new file mode 100644 index 00000000..5cd99666 --- /dev/null +++ b/Matrix.c @@ -0,0 +1,55 @@ +#include + +int main() +{ + int m, n, p, q, c, d, k, sum = 0; + int first[10][10], second[10][10], multiply[10][10]; + + printf("Enter the number of rows and columns of first matrix\n"); + scanf("%d%d", &m, &n); + printf("Enter the elements of first matrix\n"); + + for ( c = 0 ; c < m ; c++ ) + for ( d = 0 ; d < n ; d++ ) + scanf("%d", &first[c][d]); + + printf("Enter the number of rows and columns of second matrix\n"); + scanf("%d%d", &p, &q); + + if ( n != p ) + printf("Matrices with entered orders can't be multiplied with each other.\n"); + else + { + printf("Enter the elements of second matrix\n"); + + for ( c = 0 ; c < p ; c++ ) + for ( d = 0 ; d < q ; d++ ) + scanf("%d", &second[c][d]); + + for ( c = 0 ; c < m ; c++ ) + { + for ( d = 0 ; d < q ; d++ ) + { + for ( k = 0 ; k < p ; k++ ) + { + sum = sum + first[c][k]*second[k][d]; + } + + multiply[c][d] = sum; + sum = 0; + } + } + + printf("Product of entered matrices:-\n"); + + for ( c = 0 ; c < m ; c++ ) + { + for ( d = 0 ; d < q ; d++ ) + printf("%d\t", multiply[c][d]); + + printf("\n"); + } + } + + return 0; +} From 3732864ff39e4a4bad7328d603661a96805c3430 Mon Sep 17 00:00:00 2001 From: diksha1710 <68056079+diksha1710@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:03:06 +0530 Subject: [PATCH 304/394] Create positiveInteger Program to computes x^y for positive integers x and y. --- positiveInteger | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 positiveInteger diff --git a/positiveInteger b/positiveInteger new file mode 100644 index 00000000..8e4c8798 --- /dev/null +++ b/positiveInteger @@ -0,0 +1,27 @@ +#include + +int exp(int,int); +int main() +{ + int a,b,s; + printf("Enter values for X and Y:"); + scanf("%d %d", &a,&b); + s=exp(a,b); + printf("%d",s); + return 0; +} +int exp(int x, int y){ + int res=1,a=x,b=y; + while(b!=0){ + if(b%2==0){ + a=a*a; + b=b/2; + } + else + { + res=res*a; + b=b-1; + } + } + return res; +} From 7faf5694ccdf0506bff9a0ee34206c887b8a50b1 Mon Sep 17 00:00:00 2001 From: SUMAN SAURAV <72297881+sumansaurav143@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:07:12 +0530 Subject: [PATCH 305/394] Check Leap Year Program to Check Leap Year --- Check Leap Year | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Check Leap Year diff --git a/Check Leap Year b/Check Leap Year new file mode 100644 index 00000000..c6a1b8d2 --- /dev/null +++ b/Check Leap Year @@ -0,0 +1,20 @@ +#include +int main() { + int year; + printf("Enter a year: "); + scanf("%d", &year); + if (year % 400 == 0) { + printf("%d is a leap year.", year); + } + else if (year % 100 == 0) { + printf("%d is not a leap year.", year); + } + else if (year % 4 == 0) { + printf("%d is a leap year.", year); + } + else { + printf("%d is not a leap year.", year); + } + + return 0; +} From e381bb887761ce8e3625dcba2a3ab2daba2362dc Mon Sep 17 00:00:00 2001 From: YASH3166 <70128865+YASH3166@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:17:27 +0530 Subject: [PATCH 306/394] Create Oil Spill Game. C Oil Spill Game in C. --- Oil Spill Game. C | 253 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 Oil Spill Game. C diff --git a/Oil Spill Game. C b/Oil Spill Game. C new file mode 100644 index 00000000..284a33a5 --- /dev/null +++ b/Oil Spill Game. C @@ -0,0 +1,253 @@ +Oil Spill Game in C. + +#include +#include +#include +#include +#include + +#define L 75 +#define R 77 + /* variable initialisations */ + +union REGS i,o; +int ch1,ch2; +int mx,my,vx=270,vy; +int temp,retval; +char s[20],s1[20]; +char ch; +int gd=DETECT,gm; +int x,y=400,r,c=7,score=0,lifes=4,flag=0,dlyfactor=0; + + /* main function */ +main() +{ + initialise(); + firstscreen(); + displaylifes(); + displayscore(); + welcome(); + while(1) + { + condition1(); + display_drop(); + is_keyhit(); + check_catchdrop(); + check_looselife(); + } + nosound(); +} + /* sub functions */ + + +initialise() + { + initgraph(&gd,&gm,""); + mx=getmaxx();my=getmaxy(); + setcolor(4); + x=mx/2; + + image(x,y,c); + vy=20; + } +firstscreen() + { + + button3d(100,0,430,5); + button3d(100,0,5,450); + button3d(100,450,430,5); + button3d(525,0,5,455); + + setfillstyle(1,7); + bar(270,5,275,10); + bar(320,5,325,10); + bar(370,5,375,10); + + setfillstyle(1,8); + bar(267,10,278,15); + bar(317,10,328,15); + bar(367,10,378,15); + + button3d(280,448,80,9); + setcolor(4); + outtextxy(290,450,"OIL SPIL"); + } +welcome() + { + setfillstyle(1,0); + bar(200,250,450,350); + clk_but3d(200,250,250,100); + settextstyle(0,0,2); + setcolor(4); + outtextxy(240,280," WELCOME"); + outtextxy(215,310, " TO OILSPIL"); + getch(); + setfillstyle(1,0); + bar(200,250,453,353); + return; + } + + +is_keyhit() + { + if(kbhit()) + { + i.h.ah=0; + int86(22,&i,&o); + if(o.h.ah==1) { nosound();closegraph();exit(0); } + if(o.h.ah==75) { +sound(1800);image(x,y,0);x=x-10;image(x,y,c);nosound(); } + if(o.h.ah==77) { +sound(1800);image(x,y,0);x=x+10;image(x,y,c);nosound(); } + if(o.h.ah==80) { dlyfactor+=250; } + if(o.h.ah==72) { dlyfactor-=250; } + } + } +image(int x,int y,int c) + { + int b; + setcolor(c); + rectangle(x-10,y+6,x+10,y+20); + setcolor(0); + line(x-9,y+6,x+9,y+6); + setfillstyle(1,c); + bar(x-9,y+6,x+9,y+19); + setfillstyle(1,0); + bar(x-6,y+6,x+6,y+19); + setcolor(c); + for(b=1;b<=6;b++) + line(x-10+b,y+19+b,x+10-b,y+19+b); + setfillstyle(1,c); + bar(x-1,y+19+b,x+1,y+25+b); + fillellipse(x,y+25+b+3,8,3); + } +object(int x,int y,int c) + { + setcolor(c); + setfillstyle(1,c); + fillellipse(x,y+5,4,8); + } +condition1() + { + if(flag==1||vy>410) + { + vy = 20; + temp = random(3); + if(temp==0) vx=270; + else if(temp==1) vx=320; + else if(temp==2) vx =370; + flag=0; + } + } + + +check_looselife() + { + if(lifes==0) + { + setfillstyle(1,0); + bar(200,250,450,350); + clk_but3d(200,250,250,100); + settextstyle(0,0,2); + setcolor(1); + outtextxy(240,290,"GAME OVER"); + getch(); + closegraph(); + play_again(); + exit(0); + } + } +display_drop() + { + object(vx,vy,8); + delay(3000+dlyfactor); + object(vx,vy,0); + vy+=10; + } +check_catchdrop() + { + if((x-5<=vx)&&(vx<=x+5)&&vy==410) + displayscore(); + else if(vy>410) + displaylifes(); + nosound(); + } + displaylifes() + { + settextstyle(0,0,1); + clk_but3d(0,440,90,13); + setcolor(7); + outtextxy(5,445,s1); + lifes = lifes -1; + sprintf(s1,"LIFES = %d", lifes); + setcolor(4); + outtextxy(5,445,s1); + flag=0; + } + displayscore() + { + settextstyle(0,0,1); + clk_but3d(540,440,90,13); + setcolor(7); + outtextxy(545,445,s); + score=score+1; + sprintf(s,"SCORE = %d",score); + setcolor(4); + outtextxy(545,445,s); + flag=1; + vy=20; + } + button3d(int x,int y,int l,int w) + { + setcolor(LIGHTGRAY); + setfillstyle(1,LIGHTGRAY); + + bar(x,y,x+l,y+w); + + setcolor(WHITE); + line(x,y,x+l,y); + line(x,y,x,y+w); + + setcolor(DARKGRAY); + line(x+l+1,y,x+l+1,y+w+1); + line(x,y+w+1,x+l+1,y+w+1); + } + clk_but3d(int x,int y,int l,int w) + { + setcolor(LIGHTGRAY); + setfillstyle(1,LIGHTGRAY); + + bar(x,y,x+l,y+w); + + setcolor(DARKGRAY); + line(x,y,x+l,y); + line(x,y,x,y+w); + + setcolor(WHITE); + line(x+l+1,y,x+l+1,y+w+1); + line(x,y+w+1,x+l+1,y+w+1); + } + + + letter(int x,int y,int l,int w) + { + char s[1]; + int ch=3; + setcolor(RED); + sprintf(s,"%c",ch); + outtextxy(x + l/4 + 2,y + w/5, s); + } + restore_defaults() + { + y=400;c=7;score=0;lifes=4;flag=0;dlyfactor=0; + } + play_again() + { + printf("To Play again Press 'y'"); + if(getch()=='y') + { + restore_defaults(); + main(); + } + else + } From ba9b23baa4597279ce67bdced999077482518629 Mon Sep 17 00:00:00 2001 From: Kher_Akshay7 <64765656+akshay0077@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:28:26 +0530 Subject: [PATCH 307/394] Create multiplication_table --- multiplication_table | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 multiplication_table diff --git a/multiplication_table b/multiplication_table new file mode 100644 index 00000000..7250ae24 --- /dev/null +++ b/multiplication_table @@ -0,0 +1,10 @@ +#include +int main() { + int n, i; + printf("Enter an integer: "); + scanf("%d", &n); + for (i = 1; i <= 10; ++i) { + printf("%d * %d = %d \n", n, i, n * i); + } + return 0; +} From e344798be2deccb393dbb65d8b4ff3dd3cb155f7 Mon Sep 17 00:00:00 2001 From: budhpreaygautam <72300032+budhpreaygautam@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:38:59 +0530 Subject: [PATCH 308/394] Armstrong_number Check number is Armstrong or not --- Armstrong_ number | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Armstrong_ number diff --git a/Armstrong_ number b/Armstrong_ number new file mode 100644 index 00000000..36aabc7a --- /dev/null +++ b/Armstrong_ number @@ -0,0 +1,24 @@ +#include +#include +void main() +{ +int n,t,rev=0; +clrscr(); +printf("Enter the any value to check armstrong no : "); +scanf("%d",&n); +t=n; +while(n>0) +{ +rev+rev+(n%10)*(n%10)*(n%10); +n=n/10; +} +if(rev=t) +{ +printf("\nThe no. is armstrong"); +} +else +{ +printf("\nThe no. is not armstrong"); +} +getch(); +} From 9cb912e8db995cebeba2ea35db336718db7f57b5 Mon Sep 17 00:00:00 2001 From: sonal175 <69459167+sonal175@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:49:43 +0530 Subject: [PATCH 309/394] code for treetransversal in c this is code for tree transversal in c --- treetransversal.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 treetransversal.c diff --git a/treetransversal.c b/treetransversal.c new file mode 100644 index 00000000..833b3cc6 --- /dev/null +++ b/treetransversal.c @@ -0,0 +1,142 @@ +#include +#include + +struct node { + int data; + + struct node *leftChild; + struct node *rightChild; +}; + +struct node *root = NULL; + +void insert(int data) { + struct node *tempNode = (struct node*) malloc(sizeof(struct node)); + struct node *current; + struct node *parent; + + tempNode->data = data; + tempNode->leftChild = NULL; + tempNode->rightChild = NULL; + + //if tree is empty + if(root == NULL) { + root = tempNode; + } else { + current = root; + parent = NULL; + + while(1) { + parent = current; + + //go to left of the tree + if(data < parent->data) { + current = current->leftChild; + + //insert to the left + if(current == NULL) { + parent->leftChild = tempNode; + return; + } + } //go to right of the tree + else { + current = current->rightChild; + + //insert to the right + if(current == NULL) { + parent->rightChild = tempNode; + return; + } + } + } + } +} + +struct node* search(int data) { + struct node *current = root; + printf("Visiting elements: "); + + while(current->data != data) { + if(current != NULL) + printf("%d ",current->data); + + //go to left tree + if(current->data > data) { + current = current->leftChild; + } + //else go to right tree + else { + current = current->rightChild; + } + + //not found + if(current == NULL) { + return NULL; + } + } + + return current; +} + +void pre_order_traversal(struct node* root) { + if(root != NULL) { + printf("%d ",root->data); + pre_order_traversal(root->leftChild); + pre_order_traversal(root->rightChild); + } +} + +void inorder_traversal(struct node* root) { + if(root != NULL) { + inorder_traversal(root->leftChild); + printf("%d ",root->data); + inorder_traversal(root->rightChild); + } +} + +void post_order_traversal(struct node* root) { + if(root != NULL) { + post_order_traversal(root->leftChild); + post_order_traversal(root->rightChild); + printf("%d ", root->data); + } +} + +int main() { + int i; + int array[7] = { 27, 14, 35, 10, 19, 31, 42 }; + + for(i = 0; i < 7; i++) + insert(array[i]); + + i = 31; + struct node * temp = search(i); + + if(temp != NULL) { + printf("[%d] Element found.", temp->data); + printf("\n"); + }else { + printf("[ x ] Element not found (%d).\n", i); + } + + i = 15; + temp = search(i); + + if(temp != NULL) { + printf("[%d] Element found.", temp->data); + printf("\n"); + }else { + printf("[ x ] Element not found (%d).\n", i); + } + + printf("\nPreorder traversal: "); + pre_order_traversal(root); + + printf("\nInorder traversal: "); + inorder_traversal(root); + + printf("\nPost order traversal: "); + post_order_traversal(root); + + return 0; +} From 16b4528c5ccba27870bd7d0200ecf0ed1d38ba9a Mon Sep 17 00:00:00 2001 From: sonal175 <69459167+sonal175@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:56:12 +0530 Subject: [PATCH 310/394] this is a algorithm for finding the height of a tree given algorithm is a good algorithm for finding the height of a tree --- algorithm for finding height of a binary tree | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 algorithm for finding height of a binary tree diff --git a/algorithm for finding height of a binary tree b/algorithm for finding height of a binary tree new file mode 100644 index 00000000..e0af9833 --- /dev/null +++ b/algorithm for finding height of a binary tree @@ -0,0 +1,7 @@ +FindHeight( Node root) + If root == NULL + return 0 + else + int leftH = FindHeight ( root->left ) + int rightH = FindHeight(root->right ) + return max( leftH, rightH )+1 From aea420ebc462f2b13230e86fdf9c189147b9ce3e Mon Sep 17 00:00:00 2001 From: ShivamMittal1802 <56064551+ShivamMittal1802@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:59:52 +0530 Subject: [PATCH 311/394] reverse-string program to reverse any string --- reversing of string | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 reversing of string diff --git a/reversing of string b/reversing of string new file mode 100644 index 00000000..7c6bb8fd --- /dev/null +++ b/reversing of string @@ -0,0 +1,27 @@ +#include +int main() +{ + char s[1000], r[1000]; + int begin, end, count = 0; + + printf("Input a string\n"); + gets(s); + + // Calculating string length + + while (s[count] != '\0') + count++; + + end = count - 1; + + for (begin = 0; begin < count; begin++) { + r[begin] = s[end]; + end--; + } + + r[begin] = '\0'; + + printf("%s\n", r); + + return 0; +} From f05219698764509f7e511a30b255a9d757c170cf Mon Sep 17 00:00:00 2001 From: yakshsoni <62012450+yakshsoni@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:02:01 +0530 Subject: [PATCH 312/394] Program to Reverse a String Using Recursion Below is a program to reverse a user input string using recursion in C language --- Program to Reverse a String Using Recursion | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Program to Reverse a String Using Recursion diff --git a/Program to Reverse a String Using Recursion b/Program to Reverse a String Using Recursion new file mode 100644 index 00000000..a3c66421 --- /dev/null +++ b/Program to Reverse a String Using Recursion @@ -0,0 +1,31 @@ +#include +#include + +// declaring recursive function +char* reverse(char* str); + +void main() +{ + int i, j, k; + char str[100]; + char *rev; + printf("Enter the string:\t"); + scanf("%s", str); + printf("The original string is: %s\n", str); + rev = reverse(str); + printf("The reversed string is: %s\n", rev); + getch(); +} + +// defining the function +char* reverse(char *str) +{ + static int i = 0; + static char rev[100]; + if(*str) + { + reverse(str+1); + rev[i++] = *str; + } + return rev; +} From aa72cb676b79b3891e8a4c218f1cfa5c58e2dc69 Mon Sep 17 00:00:00 2001 From: sakshiv278 <66488392+sakshiv278@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:02:14 +0530 Subject: [PATCH 313/394] duplicateelement Duplicate element in array --- duplicateelementsinarray | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 duplicateelementsinarray diff --git a/duplicateelementsinarray b/duplicateelementsinarray new file mode 100644 index 00000000..300b1476 --- /dev/null +++ b/duplicateelementsinarray @@ -0,0 +1,17 @@ +#include + +int main() +{ + + int arr[] = {1, 2, 3, 4, 5,6,7,2}; + int length = sizeof(arr)/sizeof(arr[0]); + printf("Duplicate elements in given array: \n"); + //Searches for duplicate element + for(int i = 0; i < length; i++) { + for(int j = i + 1; j < length; j++) { + if(arr[i] == arr[j]) + printf("%d\n", arr[j]); + } + } + return 0; +} From 8bce2a3f6368a84d5c4c8fcd1530170a15825408 Mon Sep 17 00:00:00 2001 From: ABHISHEK KUMAR <56838919+Abhikr-git@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:14:29 +0530 Subject: [PATCH 314/394] Map of India This program will print the map of India as the output --- mapOfIndia | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mapOfIndia diff --git a/mapOfIndia b/mapOfIndia new file mode 100644 index 00000000..cedcfc01 --- /dev/null +++ b/mapOfIndia @@ -0,0 +1,18 @@ +main() + { + int a,b,c; + int count = 1; + + for (b = c = 10; + a = "- FIGURE?, UMKC,XYZHello Folks,\ + TFy!QJu ROo TNn(ROo)SLq SLq ULo+\ + UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\ + NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\ + HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\ + T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\ + Hq!WFs XDt!"[b+++21]; ) + for(; a-- > 64 ; ) + putchar ( ++c=='Z' ? c = c/ 9:33^b&1); + + return 0; + } From c8100bb1a68d24311eda08653099e4093fcd817f Mon Sep 17 00:00:00 2001 From: utkarsh-shrivastava <42946898+utkarsh-shrivastava@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:27:29 +0530 Subject: [PATCH 315/394] Second Largest Element in Array --- Second Largest Element in Array | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Second Largest Element in Array diff --git a/Second Largest Element in Array b/Second Largest Element in Array new file mode 100644 index 00000000..0b246d14 --- /dev/null +++ b/Second Largest Element in Array @@ -0,0 +1,27 @@ +#include + +int main() { + int array[10] = {101, 11, 3, 4, 50, 69, 7, 8, 9, 0}; + int loop, largest, second; + + if(array[0] > array[1]) { + largest = array[0]; + second = array[1]; + } else { + largest = array[1]; + second = array[0]; + } + + for(loop = 2; loop < 10; loop++) { + if( largest < array[loop] ) { + second = largest; + largest = array[loop]; + } else if( second < array[loop] ) { + second = array[loop]; + } + } + + printf("Largest - %d \nSecond - %d \n", largest, second); + + return 0; +} From 867017752d6b087f61a5e126d3612d1b8196fa6c Mon Sep 17 00:00:00 2001 From: abhishekkushwah827 <63289147+abhishekkushwah827@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:31:22 +0530 Subject: [PATCH 316/394] multiplication of two matrices #matrix #multiplication --- Program to multiply two matrices | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Program to multiply two matrices diff --git a/Program to multiply two matrices b/Program to multiply two matrices new file mode 100644 index 00000000..0dc10d72 --- /dev/null +++ b/Program to multiply two matrices @@ -0,0 +1,51 @@ +#include + +using namespace std; + + + +// This function multiplies mat1[][] and mat2[][], and stores the result in res[][] +void multiply(int mat1[][N], + int mat2[][N], + int res[][N]) +{ + int i, j, k; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + { + res[i][j] = 0; + for (k = 0; k < N; k++) + res[i][j] += mat1[i][k] * + mat2[k][j]; + } + } +} + +// Driver Code +int main() +{ + int i, j; + int res[N][N]; // To store result + int mat1[N][N] = {{1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int mat2[N][N] = {{1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + multiply(mat1, mat2, res); + + cout << "Result matrix is \n"; + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + cout << res[i][j] << " "; + cout << "\n"; + } + + return 0; +} From 5a74bdc830c390b6fd2b89163fad5c24a9241ab9 Mon Sep 17 00:00:00 2001 From: Chetan Atrawalkar <66908113+ChetanAtrawalkarCA@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:36:44 +0530 Subject: [PATCH 317/394] Check vowel using switch case Program to check vowel using switch case --- program to check vowel using switch case | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 program to check vowel using switch case diff --git a/program to check vowel using switch case b/program to check vowel using switch case new file mode 100644 index 00000000..7516a44f --- /dev/null +++ b/program to check vowel using switch case @@ -0,0 +1,30 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + + char ch; + printf("Input a Character : "); + scanf("%c", &ch); + + switch(ch) + { + case 'a': + case 'A': + case 'e': + case 'E': + case 'i': + case 'I': + case 'o': + case 'O': + case 'u': + case 'U': + printf("\n\n%c is a vowel.\n\n", ch); + break; + default: + printf("%c is not a vowel.\n\n", ch); + } + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From 8c2c8500a878e1d672acd53b2042c51f8b0d1086 Mon Sep 17 00:00:00 2001 From: baibhavtripathy <68537807+baibhavtripathy@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:40:48 +0530 Subject: [PATCH 318/394] Snake Hacktoberfest 2020 --- Snake | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Snake diff --git a/Snake b/Snake new file mode 100644 index 00000000..a7ef96e1 --- /dev/null +++ b/Snake @@ -0,0 +1,150 @@ + + + + + + + + + + + From 71212025deb949818ffebcecfd2057cad5c72228 Mon Sep 17 00:00:00 2001 From: baibhavtripathy <68537807+baibhavtripathy@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:41:51 +0530 Subject: [PATCH 319/394] Tetris Hacktoberfest 2020 --- Tetris | 318 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 Tetris diff --git a/Tetris b/Tetris new file mode 100644 index 00000000..2a78fd42 --- /dev/null +++ b/Tetris @@ -0,0 +1,318 @@ + + + + + + + + + + + From 41b3e8e07077dfaf7ce21f3170e94cbb492362a2 Mon Sep 17 00:00:00 2001 From: Mihir Mahajani <66313569+Mihir2527@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:04:41 +0530 Subject: [PATCH 320/394] Rename Selection Sort Program in to Selection Sort Program in C --- Selection Sort Program in => Selection Sort Program in C | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Selection Sort Program in => Selection Sort Program in C (100%) diff --git a/Selection Sort Program in b/Selection Sort Program in C similarity index 100% rename from Selection Sort Program in rename to Selection Sort Program in C From 3a1c7cb506a8c8f1e29361f34de6a4d3c6a3891d Mon Sep 17 00:00:00 2001 From: pavanteja1999 <72302686+pavanteja1999@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:12:39 +0530 Subject: [PATCH 321/394] Snake Game Program in C for Snake Game --- Snake Game in C | 186 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 Snake Game in C diff --git a/Snake Game in C b/Snake Game in C new file mode 100644 index 00000000..7b1a1dee --- /dev/null +++ b/Snake Game in C @@ -0,0 +1,186 @@ +Snake Game in C + +#include +#include +#include +#include +#include +#include + +check(); +end(); +win(); +int m[500],n[500],con=20; +clock_t start,stop; + void main(void) +{ + +int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100; + +initgraph(&gd,&gm,"..\bgi"); + +setcolor(WHITE); +settextstyle(3,0,6); +outtextxy(200,2," SNAKE 2 "); +settextstyle(6,0,2); +outtextxy(20,80," Use Arrow Keys To Direct The Snake "); +outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake +"); +outtextxy(20,160," Pick The Beats Untill You Win The Game "); +outtextxy(20,200," Press 'Esc' Anytime To Exit "); +outtextxy(20,220," Press Any Key To Continue "); +ch=getch(); +if(ch==27) exit(0); +cleardevice(); +maxx=getmaxx(); +maxy=getmaxy(); + +randomize(); + +p=random(maxx); +int temp=p%13; +p=p-temp; +q=random(maxy); +temp=q%14; +q=q-temp; + + + + start=clock(); +int a=0,i=0,j,t; +while(1) +{ + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con+5); + circle(p,q,5); + floodfill(p,q,WHITE); + + if( kbhit() ) + { + ch=getch(); if(ch==0) ch=getch(); + if(ch==72&& a!=2) a=1; + if(ch==80&& a!=1) a=2; + if(ch==75&& a!=4) a=3; + if(ch==77&& a!=3) a=4; + } + else + { + if(ch==27 + ) break; + } + + if(i<20){ + m[i]=x; + n[i]=y; + i++; + } + + if(i>=20) + + { + for(j=con;j>=0;j--){ + m[1+j]=m[j]; + n[1+j]=n[j]; + } + m[0]=x; + n[0]=y; + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con); + circle(m[0],n[0],8); + floodfill(m[0],n[0],WHITE); + + setcolor(WHITE); + for(j=1;j=5) spd=spd-5; else spd=5; + if(con>490) win(); + p=random(maxx); temp=p%13; p=p-temp; + q=random(maxy); temp=q%14; q=q-temp; + } + if(a==1) y = y-14; if(y<0) { temp=maxy%14;y=maxy-temp;} + if(a==2) y = y+14; if(y>maxy) y=0; + if(a==3) x = x-13; if(x<0) { temp=maxx%13;x=maxx-temp;} + if(a==4) x = x+13; if(x>maxx) x=0; + if(a==0){ y = y+14 ; x=x+13; } + } + + } + + +check(){ + int a; + for(a=1;a Date: Sat, 3 Oct 2020 17:19:19 +0530 Subject: [PATCH 322/394] Create N reverse natural number --- N reverse natural number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 N reverse natural number diff --git a/N reverse natural number b/N reverse natural number new file mode 100644 index 00000000..1c76c33f --- /dev/null +++ b/N reverse natural number @@ -0,0 +1,20 @@ +#include + +int main() +{ + int i, n; + + + printf("Enter any number: "); + scanf("%d", &n); + + printf("Natural numbers from 1 to %d : \n", n); + + + for(i=n; i<=1; i--) + { + printf("%d\n", i); + } + + return 0; +} From a164a06b35f070ad65fd9eacdd365804ba824ea2 Mon Sep 17 00:00:00 2001 From: itsmeakshay08 <72302934+itsmeakshay08@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:27:35 +0530 Subject: [PATCH 323/394] Hello World Program Program to Print Hello world in C --- Hello world Program | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Hello world Program diff --git a/Hello world Program b/Hello world Program new file mode 100644 index 00000000..d6f39774 --- /dev/null +++ b/Hello world Program @@ -0,0 +1,9 @@ +#include +int main() { + // printf() displays the string inside quotation + printf("Hello, World!"); + return 0; +} + +Output +Hello, World! From 3064387ca0b405d4a2f537f07aafa0ef304a7459 Mon Sep 17 00:00:00 2001 From: Rayden-prog <59440831+Rayden-prog@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:31:43 +0530 Subject: [PATCH 324/394] Graph - BFS Program run Breadth First Search in Undirected Graph --- BFS in Graph | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 BFS in Graph diff --git a/BFS in Graph b/BFS in Graph new file mode 100644 index 00000000..e3ae319b --- /dev/null +++ b/BFS in Graph @@ -0,0 +1,95 @@ +// Program to print BFS traversal from a given +// source vertex. BFS(int s) traverses vertices +// reachable from s. +#include +#include + +using namespace std; + +// This class represents a directed graph using +// adjacency list representation +class Graph +{ + int V; // No. of vertices + + // Pointer to an array containing adjacency + // lists + list *adj; +public: + Graph(int V); // Constructor + + // function to add an edge to graph + void addEdge(int v, int w); + + // prints BFS traversal from a given source s + void BFS(int s); +}; + +Graph::Graph(int V) +{ + this->V = V; + adj = new list[V]; +} + +void Graph::addEdge(int v, int w) +{ + adj[v].push_back(w); // Add w to v’s list. +} + +void Graph::BFS(int s) +{ + // Mark all the vertices as not visited + bool *visited = new bool[V]; + for(int i = 0; i < V; i++) + visited[i] = false; + + // Create a queue for BFS + list queue; + + // Mark the current node as visited and enqueue it + visited[s] = true; + queue.push_back(s); + + // 'i' will be used to get all adjacent + // vertices of a vertex + list::iterator i; + + while(!queue.empty()) + { + // Dequeue a vertex from queue and print it + s = queue.front(); + cout << s << " "; + queue.pop_front(); + + // Get all adjacent vertices of the dequeued + // vertex s. If a adjacent has not been visited, + // then mark it visited and enqueue it + for (i = adj[s].begin(); i != adj[s].end(); ++i) + { + if (!visited[*i]) + { + visited[*i] = true; + queue.push_back(*i); + } + } + } +} + +// Driver program to test methods of graph class +int main() +{ + // Create a graph given in the above diagram + Graph g(4); + g.addEdge(0, 1); + g.addEdge(0, 2); + g.addEdge(1, 2); + g.addEdge(2, 0); + g.addEdge(2, 3); + g.addEdge(3, 3); + + cout << "Following is Breadth First Traversal " + << "(starting from vertex 2) \n"; + g.BFS(2); + + return 0; +} From ec6b1343f31d6129083f59902ee5910db640a6b6 Mon Sep 17 00:00:00 2001 From: Technicaljay <72300280+Technicaljay@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:48:23 +0530 Subject: [PATCH 325/394] =?UTF-8?q?=20next=20=E2=86=92=E2=86=90=20prev=20M?= =?UTF-8?q?atrix=20multiplication=20in=20C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matrix multiplication in C: We can add, subtract, multiply and divide 2 matrices. To do so, we are taking input from the user for row number, column number, first matrix elements and second matrix elements. Then we are performing multiplication on the matrices entered by the user. In matrix multiplication first matrix one row element is multiplied by second matrix all column elements. Let's try to understand the matrix multiplication of 2*2 and 3*3 matrices by the figure given below: --- ...2\206\220 prev Matrix multiplication in C" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "next \342\206\222\342\206\220 prev Matrix multiplication in C" diff --git "a/next \342\206\222\342\206\220 prev Matrix multiplication in C" "b/next \342\206\222\342\206\220 prev Matrix multiplication in C" new file mode 100644 index 00000000..736f5400 --- /dev/null +++ "b/next \342\206\222\342\206\220 prev Matrix multiplication in C" @@ -0,0 +1,49 @@ +#include +#include +int main(){ +int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; +system("cls"); +printf("enter the number of row="); +scanf("%d",&r); +printf("enter the number of column="); +scanf("%d",&c); +printf("enter the first matrix element=\n"); +for(i=0;i Date: Sat, 3 Oct 2020 17:53:03 +0530 Subject: [PATCH 326/394] Pattern in C * * * * * * * * * * * * * * * --- Pattern Program in c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Pattern Program in c diff --git a/Pattern Program in c b/Pattern Program in c new file mode 100644 index 00000000..04b9d849 --- /dev/null +++ b/Pattern Program in c @@ -0,0 +1,20 @@ +* +* * +* * * +* * * * +* * * * * + + +#include +int main() { + int i, j, rows; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 1; i <= rows; ++i) { + for (j = 1; j <= i; ++j) { + printf("* "); + } + printf("\n"); + } + return 0; +} From 2bd0b965c0f006973f4ac0fbbcc2e976a776c58a Mon Sep 17 00:00:00 2001 From: mukeshgupta007 <39895994+mukeshgupta007@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:55:56 +0530 Subject: [PATCH 327/394] Create MergeOverlappingSubIntervals Given a set of time intervals in any order, merge all overlapping intervals into one and output the result which should have only mutually exclusive intervals. Let the intervals be represented as pairs of integers for simplicity. For example, let the given set of intervals be {{1,3}, {2,4}, {5,7}, {6,8}}. The intervals {1,3} and {2,4} overlap with each other, so they should be merged and become {1, 4}. Similarly, {5, 7} and {6, 8} should be merged and become {5, 8}. In O(N) time-complexity --- MergeOverlappingSubIntervals | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 MergeOverlappingSubIntervals diff --git a/MergeOverlappingSubIntervals b/MergeOverlappingSubIntervals new file mode 100644 index 00000000..341f3c73 --- /dev/null +++ b/MergeOverlappingSubIntervals @@ -0,0 +1,62 @@ + +#include +using namespace std; + +// An interval has start and end limit +struct Interval +{ + int start, end; +}; + +// Compares two intervals according to their start limit. + +bool compareInterval(Interval i1, Interval i2) +{ + return (i1.start < i2.start); +} + +// The main function that takes a set of intervals, merges + +void mergeIntervals(Interval arr[], int n) +{ + if (n <= 0) + return; + + stack s; + + sort(arr, arr+n, compareInterval); + + s.push(arr[0]); + + for (int i = 1 ; i < n; i++) + { + Interval top = s.top(); + + if (top.end < arr[i].start) + s.push(arr[i]); + + else if (top.end < arr[i].end) + { + top.end = arr[i].end; + s.pop(); + s.push(top); + } + } + + cout << "\n The Merged Intervals are: "; + while (!s.empty()) + { + Interval t = s.top(); + cout << "[" << t.start << "," << t.end << "] "; + s.pop(); + } + return; +} + +int main() +{ + Interval arr[] = { {6,8}, {1,9}, {2,4}, {4,7} }; + int n = sizeof(arr)/sizeof(arr[0]); + mergeIntervals(arr, n); + return 0; +} From f35891e30ae3a3796555d7fdc27a6380f1b8d8d9 Mon Sep 17 00:00:00 2001 From: Kousigan1 <72304425+Kousigan1@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:02:39 +0530 Subject: [PATCH 328/394] Count No's of digit in Number C Program to Count Number of Digits in a Number using While Loop --- no of digits in number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 no of digits in number diff --git a/no of digits in number b/no of digits in number new file mode 100644 index 00000000..b1e4e39c --- /dev/null +++ b/no of digits in number @@ -0,0 +1,19 @@ +/* C Program to Count Number of Digits in a Number using While Loop */ +#include + +int main() +{ + int Number, Reminder, Count=0; + + printf("\n Please Enter any number\n"); + scanf("%d", &Number); + + while(Number > 0) + { + Number = Number / 10; + Count = Count + 1; + } + + printf("\n Number of Digits in a Given Number = %d", Count); + return 0; +} From 99a0dd906e5efc34e68eddaabafa2458acf99fa6 Mon Sep 17 00:00:00 2001 From: KRISHNA VAMSI NADH <60399427+VAMSINADH2000@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:06:57 +0530 Subject: [PATCH 329/394] to check Prime Or Not to check Prime Or Not --- C program for Prime Number | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 C program for Prime Number diff --git a/C program for Prime Number b/C program for Prime Number new file mode 100644 index 00000000..4fba8ae0 --- /dev/null +++ b/C program for Prime Number @@ -0,0 +1,27 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From b5e4d8a3ee97e2f58ec6af4d27896b8f910d8f35 Mon Sep 17 00:00:00 2001 From: sujo028 <48432120+sujo028@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:11:59 +0530 Subject: [PATCH 330/394] Positive Negative Zero Simple C program to find whether the entered number is Positive Negative or Zero --- Positive Negative Zero | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Positive Negative Zero diff --git a/Positive Negative Zero b/Positive Negative Zero new file mode 100644 index 00000000..3d2d12a5 --- /dev/null +++ b/Positive Negative Zero @@ -0,0 +1,15 @@ +#include + +void main() +{ + int num; + + printf("Enter a number: \n"); + scanf("%d", &num); + if (num > 0) + printf("%d is a positive number \n", num); + else if (num < 0) + printf("%d is a negative number \n", num); + else + printf("0 is neither positive nor negative"); +} From 4443017fd289bf54336b0d688c73705b1017c77b Mon Sep 17 00:00:00 2001 From: Renita Saldanha <69750583+renita05@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:23:21 +0530 Subject: [PATCH 331/394] Create C Program to Find the Size of int, float, double and char This C program helps one to find the size of int, float double and char. It takes a variable as input and gives the size of the same. --- ...o Find the Size of int, float, double and char | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 C Program to Find the Size of int, float, double and char diff --git a/C Program to Find the Size of int, float, double and char b/C Program to Find the Size of int, float, double and char new file mode 100644 index 00000000..1faedbc2 --- /dev/null +++ b/C Program to Find the Size of int, float, double and char @@ -0,0 +1,15 @@ +#include +int main() { + int intType; + float floatType; + double doubleType; + char charType; + + // sizeof evaluates the size of a variable + printf("Size of int: %ld bytes\n", sizeof(intType)); + printf("Size of float: %ld bytes\n", sizeof(floatType)); + printf("Size of double: %ld bytes\n", sizeof(doubleType)); + printf("Size of char: %ld byte\n", sizeof(charType)); + + return 0; +} From ff4d9ac362b8b8d754834f194adc68ef3378cc68 Mon Sep 17 00:00:00 2001 From: saurabhsonawane2015 <66660505+saurabhsonawane2015@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:23:36 +0530 Subject: [PATCH 332/394] Create FactFunc --- FactFunc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 FactFunc diff --git a/FactFunc b/FactFunc new file mode 100644 index 00000000..d36b8934 --- /dev/null +++ b/FactFunc @@ -0,0 +1,41 @@ +#include +#include +int isneg (int n); +int fact (int n); +int +main () +{ + int n; + printf ("Enter no.\n"); + scanf ("%d", &n); + if (isneg (n)) + { + printf ("Fact not possible\n"); + + } + else + { + printf ("The fact of no.is:%d", fact (n)); + } +} + +int +isneg (int n) +{ + if (n > 0) + return 0; + else + return 1; +} + +int +fact (int n) +{ + int i, s; + for (i = 0; i < n; i++) + { + s = n * i; + } + return s; +} + From 7acaa19941087acd46e0144d91b0567409d13a52 Mon Sep 17 00:00:00 2001 From: Adarsh Singh <54211269+adarshsin007@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:58:52 +0530 Subject: [PATCH 333/394] Readability_cs50 Solution for the Harvard cs50 pset2/readability --- Readability_cs50 | 121 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 Readability_cs50 diff --git a/Readability_cs50 b/Readability_cs50 new file mode 100644 index 00000000..f712de6d --- /dev/null +++ b/Readability_cs50 @@ -0,0 +1,121 @@ +/* + + Readability solution by Adarsh Singh + +*/ + +#include +#include +#include +#include + +int count_letters(string text); // function for counting letters +int count_words(string text); // function for counting words +int count_sent(string text); // function for counting sentences +int colemanformula(double L, double S); //Coleman-Liau index formula + + +int main(void) +{ + string text = get_string("Text: "); // user input of text + float letters = count_letters(text); // storing the number of letters + //printf("%.1f letters(s)\n",letters); + float words = count_words(text); // storing the number of words + //printf("%.1f word(s)\n",words); + float sentences = count_sent(text); // storing the number of sentences + //printf("%.1f sentence(s)\n", sentences); + + double L = (letters / words) * 100; // L is the average number of letters per 100 words in the text + double S = (sentences / words) * 100; // S is the average number of sentences per 100 words in the text. + + int grade = colemanformula(L, S); // calling function of coleman formula + + if (grade < 1) // checking grade condition + { + printf("Before Grade 1\n"); + } + else if (grade > 1 && grade <= 16) // checking grade condition + { + printf("Grade %i\n", grade); + } + else + { + printf("Grade 16+\n"); + } + + + + +} + +int count_letters(string text) // function for counting the number of letters in user input +{ + int count = 0; + + for (int i = 0, n = strlen(text); i < n; i++) + { + if (text[i] >= 'A' && text[i] <= 'Z') + { + count = count + 1; + } + else if (text[i] >= 'a' && text[i] <= 'z') + { + count = count + 1; + } + else if (text[i] == ' ') + { + count = count + 0; + } + } + + return count; + +} + +int count_words(string text) // function for counting the number of words in user input +{ + int words = 0, n = strlen(text); + + for (int i = 0; i <= n; i++) + { + + if (text[i] == ' ') + { + words = words + 1; + } + + } + + if (text[n - 1] == '.' || text[n - 1] == '!' || text[n - 1] == '?') + { + words = words + 1; + } + + return words; +} + +int count_sent(string text) // function for counting the number of sentences in user input +{ + int sent = 0, n = strlen(text); + + for (int i = 0; i <= n; i++) + { + if (text[i] == '!' || text[i] == '.' || text[i] == '?') + { + sent = sent + 1; + } + + } + return sent; +} + +int colemanformula(double L, double S) // coleman forumla for finding out the grade +{ + double index = 0; + index = (0.0588 * L) - (0.296 * S) - 15.8; + + int grade = round(index); + return grade; + +} + From e490e56df15fb4bda161d3240c423ec872a8c2b3 Mon Sep 17 00:00:00 2001 From: suroshree <49075646+suroshree@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:04:39 +0530 Subject: [PATCH 334/394] Create Winshree --- Winshree | 1 + 1 file changed, 1 insertion(+) create mode 100644 Winshree diff --git a/Winshree b/Winshree new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Winshree @@ -0,0 +1 @@ + From 7618ef8da1799ef392461214f8a2b86e2e7dfba1 Mon Sep 17 00:00:00 2001 From: Sweltron <57999648+Sweltron@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:05:12 +0530 Subject: [PATCH 335/394] Create RECURSION --- RECURSION | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 RECURSION diff --git a/RECURSION b/RECURSION new file mode 100644 index 00000000..6e28dc48 --- /dev/null +++ b/RECURSION @@ -0,0 +1,25 @@ +#include +int fact (int); +int main() +{ + int n,f; + printf("Enter the number whose factorial you want to calculate?"); + scanf("%d",&n); + f = fact(n); + printf("factorial = %d",f); +} +int fact(int n) +{ + if (n==0) + { + return 0; + } + else if ( n == 1) + { + return 1; + } + else + { + return n*fact(n-1); + } +} From e981147363f638f71ceb5f7d12ecb10ce1610827 Mon Sep 17 00:00:00 2001 From: Prakhar2100 <62941019+Prakhar2100@users.noreply.github.com> Date: Sat, 3 Oct 2020 07:03:47 -0700 Subject: [PATCH 336/394] Radix-Sort The idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort as a subroutine to sort. --- Radix-Sort | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Radix-Sort diff --git a/Radix-Sort b/Radix-Sort new file mode 100644 index 00000000..27b64848 --- /dev/null +++ b/Radix-Sort @@ -0,0 +1,57 @@ + +#include +using namespace std; + +int getMax(int arr[], int n) +{ + int mx = arr[0]; + for (int i = 1; i < n; i++) + if (arr[i] > mx) + mx = arr[i]; + return mx; +} + +void countSort(int arr[], int n, int exp) +{ + int output[n]; + int i, count[10] = { 0 }; + + for (i = 0; i < n; i++) + count[(arr[i] / exp) % 10]++; + + for (i = 1; i < 10; i++) + count[i] += count[i - 1]; + + for (i = n - 1; i >= 0; i--) { + output[count[(arr[i] / exp) % 10] - 1] = arr[i]; + count[(arr[i] / exp) % 10]--; + } + + for (i = 0; i < n; i++) + arr[i] = output[i]; +} + +void radixsort(int arr[], int n) +{ + int m = getMax(arr, n); + for (int exp = 1; m / exp > 0; exp *= 10) + countSort(arr, n, exp); +} + +void print(int arr[], int n) +{ + for (int i = 0; i < n; i++) + cout << arr[i] << " "; +} + +int main() +{ + int n; + cin>>n; + int arr[n]; + for(int i=0;i>arr[i]; + // Function Call + radixsort(arr, n); + print(arr, n); + return 0; +} From a017628354e3c3b4fe78c8e923c2b1650ce0fa62 Mon Sep 17 00:00:00 2001 From: BrijeshVP <57172793+brijeshvp@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:46:07 +0530 Subject: [PATCH 337/394] Create factorial_prog --- factorial_prog | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 factorial_prog diff --git a/factorial_prog b/factorial_prog new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/factorial_prog @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From 2e89f10f1a0067274e67aa9631c3cca87b61ddd7 Mon Sep 17 00:00:00 2001 From: silkigupta <51455775+silkigupta@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:59:09 +0530 Subject: [PATCH 338/394] Update Addfunction --- Addfunction | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Addfunction b/Addfunction index 0fbdfec3..8d3bdb44 100644 --- a/Addfunction +++ b/Addfunction @@ -1,10 +1,10 @@ void add(int,int); #include int main(){ -int a,b; +int num1,num2; printf("Enter two integers\n"); -scanf("%d %d",&a,&b); -add(a,b); +scanf("%d %d",&num1,&num2); +add(num1,num2); return 0; } void add(int x,int y){ From bc832c70e21daf2a4f3b7326b10b37d096765863 Mon Sep 17 00:00:00 2001 From: sharangdharshree <70096201+sharangdharshree@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:11:37 +0530 Subject: [PATCH 339/394] addition and subtraction --- addition and subtraction | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 addition and subtraction diff --git a/addition and subtraction b/addition and subtraction new file mode 100644 index 00000000..3b8b2d37 --- /dev/null +++ b/addition and subtraction @@ -0,0 +1,14 @@ +#include +int main() { +int a,b; + + printf("\tEnter two integers :"); + + scanf("%d%d", &a,&b); + + printf("\nSum of these two numbers are %d", a+b); + + printf("\nDiff of these two no. are %d", a-b); + +} + return0; From f6dee92936a16d9fcb914c5d1d07f44b1278f54f Mon Sep 17 00:00:00 2001 From: Shivam Kumar Sah <67648712+ShivamKumarSah@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:25:51 +0530 Subject: [PATCH 340/394] Bubble Sort using C In Bubble sort, Each element of the array is compared with its adjacent element. The algorithm processes the list in passes. A list with n elements requires n-1 passes for sorting. Consider an array A of n elements whose elements are to be sorted by using Bubble sort. The algorithm processes like following. In Pass 1, A[0] is compared with A[1], A[1] is compared with A[2], A[2] is compared with A[3] and so on. At the end of pass 1, the largest element of the list is placed at the highest index of the list. In Pass 2, A[0] is compared with A[1], A[1] is compared with A[2] and so on. At the end of Pass 2 the second largest element of the list is placed at the second highest index of the list. In pass n-1, A[0] is compared with A[1], A[1] is compared with A[2] and so on. At the end of this pass. The smallest element of the list is placed at the first index of the list. Algorithm : Step 1: Repeat Step 2 For i = 0 to N-1 Step 2: Repeat For J = i + 1 to N - I Step 3: IF A[J] > A[i] SWAP A[J] and A[i] [END OF INNER LOOP] [END OF OUTER LOOP Step 4: EXIT --- Bubble Sort using C | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Bubble Sort using C diff --git a/Bubble Sort using C b/Bubble Sort using C new file mode 100644 index 00000000..eadf78c9 --- /dev/null +++ b/Bubble Sort using C @@ -0,0 +1,23 @@ +#include +void main () +{ + int i, j,temp; + int a[10] = { 10, 9, 7, 101, 23, 44, 12, 78, 34, 23}; + for(i = 0; i<10; i++) + { + for(j = i+1; j<10; j++) + { + if(a[j] > a[i]) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + printf("Printing Sorted Element List ...\n"); + for(i = 0; i<10; i++) + { + printf("%d\n",a[i]); + } +} From 99ac477e983e6ddd382e0ba203b7975ac13936a8 Mon Sep 17 00:00:00 2001 From: keithveigas <54433635+keithveigas@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:31:22 +0530 Subject: [PATCH 341/394] small and great Program to find Largest and Smallest Element in an Array --- smallarge | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 smallarge diff --git a/smallarge b/smallarge new file mode 100644 index 00000000..91f194d0 --- /dev/null +++ b/smallarge @@ -0,0 +1,46 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + int a[50], size, i, big, small; + + printf("\nEnter the size of the array: "); + scanf("%d", &size); + + printf("\n\nEnter the %d elements of the array: \n\n", size); + for(i = 0; i < size; i++) + scanf("%d", &a[i]); + + big = a[0]; // initializing + /* + from 2nd element to the last element + find the bigger element than big and + update the value of big + */ + for(i = 1; i < size; i++) + { + if(big < a[i]) // if larger value is encountered + { + big = a[i]; // update the value of big + } + } + printf("\n\nThe largest element is: %d", big); + + small = a[0]; // initializing + /* + from 2nd element to the last element + find the smaller element than small and + update the value of small + */ + for(i = 1; i < size; i++) + { + if(small>a[i]) // if smaller value is encountered + { + small = a[i]; // update the value of small + } + } + printf("\n\nThe smallest element is: %d", small); + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From 6b50438d0a6d082df4ce4f5d1632f4d6ccffcb71 Mon Sep 17 00:00:00 2001 From: himanshu-371 <72307908+himanshu-371@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:38:24 +0530 Subject: [PATCH 342/394] multiply two no. Program to Multiply two numbers in c program. --- multiply two no. | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 multiply two no. diff --git a/multiply two no. b/multiply two no. new file mode 100644 index 00000000..28de781a --- /dev/null +++ b/multiply two no. @@ -0,0 +1,13 @@ +#include +#include +void main() +{ +int one, two, multiply; +printf("Enter first number - "); +scanf("%d",&one); +printf("Enter second number - "); +scanf("%d",&two); +multiply = one * two; +printf("The multiplication of numbers %d and %d is %d",one,two,multiply); +getch(); +} From 679fa4c4cf39e1276ec5ff04ab18d8c221010b89 Mon Sep 17 00:00:00 2001 From: kartiknoob <72310448+kartiknoob@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:40:02 +0530 Subject: [PATCH 343/394] addingtwonumber code to add two number in C --- additionoftwonumber | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 additionoftwonumber diff --git a/additionoftwonumber b/additionoftwonumber new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/additionoftwonumber @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} From ee127770ac327877ada99690de98b128ba9b7145 Mon Sep 17 00:00:00 2001 From: Hrithik12345678 <68548341+Hrithik12345678@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:55:47 +0530 Subject: [PATCH 344/394] Merge and quick Sort Sorting a list using merge and quick sort algorithm --- merge and quick sort | 212 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 merge and quick sort diff --git a/merge and quick sort b/merge and quick sort new file mode 100644 index 00000000..1625ed1e --- /dev/null +++ b/merge and quick sort @@ -0,0 +1,212 @@ +/* +Name: Hrithik Singh +*/ + + + +#include +#include +#define MAX 30 + +// Merges two subarrays of arr[]. +// First subarray is arr[l..m] +// Second subarray is arr[m+1..r] +int merge(int arr[], int l, int m, int r) +{ + int i, j, k; + int n1 = m - l + 1; + int n2 = r - m; + + /* create temp arrays */ + int L[n1], R[n2]; + + /* Copy data to temp arrays L[] and R[] */ + for (i = 0; i < n1; i++) + L[i] = arr[l + i]; + for (j = 0; j < n2; j++) + R[j] = arr[m + 1 + j]; + + /* Merge the temp arrays back into arr[l..r]*/ + i = 0; // Initial index of first subarray + j = 0; // Initial index of second subarray + k = l; // Initial index of merged subarray + while (i < n1 && j < n2) { + if (L[i] <= R[j]) { + arr[k] = L[i]; + i++; + } + else { + arr[k] = R[j]; + j++; + } + k++; + } + + /* Copy the remaining elements of L[], if there + are any */ + while (i < n1) { + arr[k] = L[i]; + i++; + k++; + } + + /* Copy the remaining elements of R[], if there + are any */ + while (j < n2) { + arr[k] = R[j]; + j++; + k++; + } +} + +/* l is for left index and r is right index of the + sub-array of arr to be sorted */ +void mergeSort(int arr[], int l, int r) +{ + if (l < r) { + // Same as (l+r)/2, but avoids overflow for + // large l and h + int m = l + (r - l) / 2; + + // Sort first and second halves + mergeSort(arr, l, m); + mergeSort(arr, m + 1, r); + + merge(arr, l, m, r); + } +} + + + +void swap(int* a, int* b) +{ + int t = *a; + *a = *b; + *b = t; +} + +/* This function takes last element as pivot, places + the pivot element at its correct position in sorted + array, and places all smaller (smaller than pivot) + to left of pivot and all greater elements to right + of pivot */ +int partition (int arr[], int low, int high) +{ + int pivot = arr[high]; // pivot + int i = (low - 1); // Index of smaller element + + for (int j = low; j <= high- 1; j++) + { + // If current element is smaller than the pivot + if (arr[j] < pivot) + { + i++; // increment index of smaller element + swap(&arr[i], &arr[j]); + } + } + swap(&arr[i + 1], &arr[high]); + return (i + 1); +} + +/* The main function that implements QuickSort + arr[] --> Array to be sorted, + low --> Starting index, + high --> Ending index */ +void quickSort(int arr[], int low, int high) +{ + if (low < high) + { + /* pi is partitioning index, arr[p] is now + at right place */ + int pi = partition(arr, low, high); + + // Separately sort elements before + // partition and after partition + quickSort(arr, low, pi - 1); + quickSort(arr, pi + 1, high); + } +} + + +/* UTILITY FUNCTIONS */ +/* Function to print an array */ +void printArray(int A[], int size) +{ + int i; + for (i = 0; i < size; i++) + printf("%d ", A[i]); + printf("\n"); +} +//fuction for merge sort without recursion +int mergeSortwithout(int arr[],int size){ + int i=2,j=0; + while(isize){ + right=size-1; + } + int middle=(left + right )/2; + merge(arr,left,middle, right); + j=j+1; + } + i=i*2; + if(i>=size){ + i=i/2; + merge(arr,0,size-1,(i-1)); + i=size; + } + } +} +/* Driver program to test above functions */ +int main(){ + int n; + int choice; + printf("Enter the no. of elements in the list\n"); + scanf("%d",&n); + printf("Enter the elements\n"); + int arr[n]; + for(int i=0;i Date: Sat, 3 Oct 2020 21:41:15 +0530 Subject: [PATCH 345/394] classes its is a basic program of c++ --- classes | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 classes diff --git a/classes b/classes new file mode 100644 index 00000000..fd837724 --- /dev/null +++ b/classes @@ -0,0 +1,36 @@ +#include +using namespace std; + +class employee +{ + private: + int a , b , c; + + public: + int d , e; + void setdata(int a1, int b1, int c1); //Declaration + void getdata(){ + cout<<"THe value of a is "< This will throw error as a is private + lucky.d= 35; + lucky.e=45; + lucky.setdata(1,2,4); + lucky.getdata(); + return 0; +} From efa973c2cbb80605ef05b36665423278efaeef7a Mon Sep 17 00:00:00 2001 From: Aiman-bt <72312040+Aiman-bt@users.noreply.github.com> Date: Sat, 3 Oct 2020 21:43:38 +0530 Subject: [PATCH 346/394] Perfect Number Program to find a Perfect Number using C. --- Perfect Number | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Perfect Number diff --git a/Perfect Number b/Perfect Number new file mode 100644 index 00000000..bc422b0f --- /dev/null +++ b/Perfect Number @@ -0,0 +1,22 @@ +#include + +int main() +{ + int number, rem, sum = 0, i; + + printf("Enter a Number\n"); + scanf("%d", &number); + for (i = 1; i <= (number - 1); i++) + { + rem = number % i; + if (rem == 0) + { + sum = sum + i; + } + } + if (sum == number) + printf("Entered Number is perfect number"); + else + printf("Entered Number is not a perfect number"); + return 0; +} From b16f629300ffd273c180444bfe819f9294d1d619 Mon Sep 17 00:00:00 2001 From: lakshyadeepgogoi <72311817+lakshyadeepgogoi@users.noreply.github.com> Date: Sat, 3 Oct 2020 21:46:09 +0530 Subject: [PATCH 347/394] its is mendotary --- Arithmatic Operations | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Arithmatic Operations b/Arithmatic Operations index d70e9993..2a5ec274 100644 --- a/Arithmatic Operations +++ b/Arithmatic Operations @@ -1,4 +1,6 @@ +#include #include + int main() { int a,b; From 7de01c51ab571342d58230fd626afb19bc40965b Mon Sep 17 00:00:00 2001 From: shaguntyagi28 <47532085+shaguntyagi28@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:11:21 +0530 Subject: [PATCH 348/394] Create Window Sliding Technique Code of Window Sliding Technique in cpp --- Window Sliding Technique | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Window Sliding Technique diff --git a/Window Sliding Technique b/Window Sliding Technique new file mode 100644 index 00000000..53dd6dfa --- /dev/null +++ b/Window Sliding Technique @@ -0,0 +1,22 @@ +#include +using namespace std; +int maxSum(int arr[], int n, int k) +{ + int max_sum = INT_MIN; + for (int i = 0; i < n - k + 1; i++) { + int current_sum = 0; + for (int j = 0; j < k; j++) + current_sum = current_sum + arr[i + j]; + max_sum = max(current_sum, max_sum); + } + + return max_sum; +} +int main() +{ + int arr[] = { 1, 4, 2, 10, 2, 3, 1, 0, 20 }; + int k = 4; + int n = sizeof(arr) / sizeof(arr[0]); + cout << maxSum(arr, n, k); + return 0; +} From e30b23930dfe3b4883db62cde7f483621975d220 Mon Sep 17 00:00:00 2001 From: Geetika Keim Date: Sat, 3 Oct 2020 22:14:04 +0530 Subject: [PATCH 349/394] Pascal's Triangle Program to create a Pascal's Triangle --- Pascal's Triangle | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Pascal's Triangle diff --git a/Pascal's Triangle b/Pascal's Triangle new file mode 100644 index 00000000..29809b20 --- /dev/null +++ b/Pascal's Triangle @@ -0,0 +1,19 @@ +#include +int main() { + int rows, coef = 1, space, i, j; + printf("Enter the number of rows: "); + scanf("%d", &rows); + for (i = 0; i < rows; i++) { + for (space = 1; space <= rows - i; space++) + printf(" "); + for (j = 0; j <= i; j++) { + if (j == 0 || i == 0) + coef = 1; + else + coef = coef * (i - j + 1) / j; + printf("%4d", coef); + } + printf("\n"); + } + return 0; +} From f3c0893007eb2752d5463b0181334563aa7207a4 Mon Sep 17 00:00:00 2001 From: agarwaladitya1019 <56962767+agarwaladitya1019@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:23:04 +0530 Subject: [PATCH 350/394] template templates for cp --- coding template | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 coding template diff --git a/coding template b/coding template new file mode 100644 index 00000000..1a98ed76 --- /dev/null +++ b/coding template @@ -0,0 +1,52 @@ +#include +using namespace std; +const int N=10000000; +//................................... +#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); +#define ll long long int +#define ss second +#define ff first +#define pb push_back +#define pll pair +#define F(i,n) for(ll i=0;i +#define t_case ll test;cin>>test;while(test--) +#define all(a) a.begin(),a.end() +//................................... +bool cmp(ll x,ll y) {return x>y;} +ll min3(ll x,ll y,ll z) {return min(x,min(y,z));} +ll max3(ll x,ll y,ll z) {return max(x,max(y,z));} +ll powrec(ll a,ll n){if(n==0) return 1;ll res=powrec(a,n/2);if(n%2)return res*res*a;else return res*res;} +ll powloop(ll a,ll n){ll res=1;while(n>0){if(n&1)res=res*a;a=a*a;n>>=1;}return res;} +ll powmod(ll a,ll n,ll m){a%=m;ll res=1;while(n>0){if(n&1)res=res*a%m;a=a*a%m;n>>=1;}return res;} +//................................... +int main() +{ + + + t_case + { + ll n,x,p,k; + cin>>n>>x>>p>>k; + ll a[n]; + F(i,n) + { + cin>>a[i]; + } + sort(a,a+n); + ll c=0,flag=0; + F(i,300) + { + if(a[p-1]==x) + { + flag=1; break; + } + c++; + a[k-1]=x; + sort(a,a+n); + } + if(flag==1) cout< Date: Sat, 3 Oct 2020 22:23:29 +0530 Subject: [PATCH 351/394] Create IpAddress.c --- IpAddress.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 IpAddress.c diff --git a/IpAddress.c b/IpAddress.c new file mode 100644 index 00000000..89f4ade9 --- /dev/null +++ b/IpAddress.c @@ -0,0 +1,57 @@ +#include +#include + +/* +Function : extractIpAddress +Arguments : +1) sourceString - String pointer that contains ip address +2) ipAddress - Target variable short type array pointer that will store ip address octets +*/ +void extractIpAddress(unsigned char *sourceString,short *ipAddress) +{ + unsigned short len=0; + unsigned char oct[4]={0},cnt=0,cnt1=0,i,buf[5]; + + len=strlen(sourceString); + for(i=0;i=0 && ipAddress[0]<=127) + printf("Class A Ip Address.\n"); + if(ipAddress[0]>127 && ipAddress[0]<191) + printf("Class B Ip Address.\n"); + if(ipAddress[0]>191 && ipAddress[0]<224) + printf("Class C Ip Address.\n"); + if(ipAddress[0]>224 && ipAddress[0]<=239) + printf("Class D Ip Address.\n"); + if(ipAddress[0]>239) + printf("Class E Ip Address.\n"); + + return 0; +} From 4df0e4979d3bea43c03fed5fef2c4b7a2d04a8c0 Mon Sep 17 00:00:00 2001 From: Vishal Biji <52275202+vishalbiji@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:25:10 +0530 Subject: [PATCH 352/394] Create zombieprocess.c --- zombieprocess.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 zombieprocess.c diff --git a/zombieprocess.c b/zombieprocess.c new file mode 100644 index 00000000..4b04b014 --- /dev/null +++ b/zombieprocess.c @@ -0,0 +1,26 @@ +#include +#include +#include + +int main() +{ + // fork() creates child process identical to parent + int pid = fork(); + + // if pid is greater than 0 than it is parent process + // if pid is 0 then it is child process + // if pid is -ve , it means fork() failed to create child process + + // Parent process + if (pid > 0) + sleep(20); + + // Child process + else + { + exit(0); + } + + return 0; + +} From 97b73a50b36420fcea9bda8bf7f4811963f9b1f3 Mon Sep 17 00:00:00 2001 From: Vishal Biji <52275202+vishalbiji@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:26:11 +0530 Subject: [PATCH 353/394] Create orphanprocess.c --- orphanprocess.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 orphanprocess.c diff --git a/orphanprocess.c b/orphanprocess.c new file mode 100644 index 00000000..fa5b0f0b --- /dev/null +++ b/orphanprocess.c @@ -0,0 +1,40 @@ +#include +#include +#include + +int main() +{ + // fork() Create a child process + + int pid = fork(); + if (pid > 0) + { + //getpid() returns process id + // while getppid() will return parent process id + printf("Parent process\n"); + printf("ID : %d\n\n",getpid()); + } + else if (pid == 0) + { + printf("Child process\n"); + // getpid() will return process id of child process + printf("ID: %d\n",getpid()); + // getppid() will return parent process id of child process + printf("Parent -ID: %d\n\n",getppid()); + + sleep(10); + + // At this time parent process has finished. + // So if u will check parent process id + // it will show different process id + printf("\nChild process \n"); + printf("ID: %d\n",getpid()); + printf("Parent -ID: %d\n",getppid()); + } + else + { + printf("Failed to create child process"); + } + + return 0; +} From 5f4b50f7fbe34e9d473d10f0cf150dff62a58992 Mon Sep 17 00:00:00 2001 From: NinjaMandy <72304874+NinjaMandy@users.noreply.github.com> Date: Sat, 3 Oct 2020 22:27:11 +0530 Subject: [PATCH 354/394] numberSwap program to swap two numbers --- numberSwap | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 numberSwap diff --git a/numberSwap b/numberSwap new file mode 100644 index 00000000..1843c0cc --- /dev/null +++ b/numberSwap @@ -0,0 +1,18 @@ +//Forswaping two numbers. +#include + +int main() +{ + int x, y; + printf("Enter Value of x "); + scanf("%d", &x); + printf("\nEnter Value of y "); + scanf("%d", &y); + + int temp = x; + x = y; + y = temp; + + printf("\nAfter Swapping: x = %d, y = %d", x, y); + return 0; +} From b6a6d4066bea6fc806f10a921e67cc7667c382a6 Mon Sep 17 00:00:00 2001 From: Devesh Sharma <59760503+Devesh-code@users.noreply.github.com> Date: Sat, 3 Oct 2020 23:35:45 +0530 Subject: [PATCH 355/394] Fibonacci Series in c Program of Fibonacci series in c language --- Fibonacci Series in c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacci Series in c diff --git a/Fibonacci Series in c b/Fibonacci Series in c new file mode 100644 index 00000000..3b95d0c7 --- /dev/null +++ b/Fibonacci Series in c @@ -0,0 +1,16 @@ +#include +int main() +{ + int n1=0,n2=1,n3,i,number; + printf("Enter the number of elements:"); + scanf("%d",&number); + printf("\n%d %d",n1,n2);//printing 0 and 1 + for(i=2;i Date: Sun, 4 Oct 2020 00:05:49 +0530 Subject: [PATCH 356/394] LRU Cache Program to store the least recently used (LRU) cache upto a given input capacity --- LRU_Cache.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 LRU_Cache.cpp diff --git a/LRU_Cache.cpp b/LRU_Cache.cpp new file mode 100644 index 00000000..069fb23b --- /dev/null +++ b/LRU_Cache.cpp @@ -0,0 +1,35 @@ +class LRUCache { +private: + int cap; + list keys; + unordered_map::iterator>> cache; +public: + LRUCache(int capacity) { + cap = capacity; + } + + int get(int key) { + if(cache.find(key) != cache.end()){ + keys.erase(cache[key].second); + keys.push_front(key); + cache[key].second = keys.begin(); + return cache[key].first; + } + return -1; + } + + void put(int key, int value) { + if(cache.find(key) != cache.end()){ + keys.erase(cache[key].second); + keys.push_front(key); + cache[key] = {value, keys.begin()}; + }else{ + if(keys.size() == cap){ + cache.erase(keys.back()); + keys.pop_back(); + } + keys.push_front(key); + cache[key] = {value, keys.begin()}; + } + } +}; From 24e512b8a78b7ea5feb40cd115e774cc09b1b46c Mon Sep 17 00:00:00 2001 From: balveerkumar8299 <72316767+balveerkumar8299@users.noreply.github.com> Date: Sun, 4 Oct 2020 00:05:50 +0530 Subject: [PATCH 357/394] GCD of two number Program to find GCD of two integer --- GCD of 2 number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 GCD of 2 number diff --git a/GCD of 2 number b/GCD of 2 number new file mode 100644 index 00000000..dc76a125 --- /dev/null +++ b/GCD of 2 number @@ -0,0 +1,19 @@ +#include +int main() +{ + int n1, n2; + + printf("Enter two positive integers: "); + scanf("%d %d",&n1,&n2); + + while(n1!=n2) + { + if(n1 > n2) + n1 -= n2; + else + n2 -= n1; + } + printf("GCD = %d",n1); + + return 0; +} From 023784cf2dc53caa9699a335f66b2efc37e25097 Mon Sep 17 00:00:00 2001 From: Ankushaj <72180181+Ankushaj@users.noreply.github.com> Date: Sun, 4 Oct 2020 01:00:22 +0545 Subject: [PATCH 358/394] Create Simple calculator This is a simple calculator program in c for adding/subtracting/multiplying/dividing two numbers --- Simple calculator | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Simple calculator diff --git a/Simple calculator b/Simple calculator new file mode 100644 index 00000000..a8bd462a --- /dev/null +++ b/Simple calculator @@ -0,0 +1,29 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} From 71d6290524f3c339dcf3089a8051212029a338b9 Mon Sep 17 00:00:00 2001 From: HarshangVirani <52438740+HarshangVirani@users.noreply.github.com> Date: Sun, 4 Oct 2020 01:01:31 +0530 Subject: [PATCH 359/394] Tower of Hanoi in c Code of tower of Hanoi in c language. --- Tower of Hanoi | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Tower of Hanoi diff --git a/Tower of Hanoi b/Tower of Hanoi new file mode 100644 index 00000000..cf5eae98 --- /dev/null +++ b/Tower of Hanoi @@ -0,0 +1,36 @@ +#include + + +// C recursive function to solve tower of hanoi puzzle + +void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) +{ + + if (n == 1) + + { + + printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod); + + return; + + } + + towerOfHanoi(n-1, from_rod, aux_rod, to_rod); + + printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod); + + towerOfHanoi(n-1, aux_rod, to_rod, from_rod); +} + + + +int main() +{ + + int n = 4; // Number of disks + + towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods + + return 0; +} From 70e00a4f94e4326db8202f8ed3e8056a4b681af5 Mon Sep 17 00:00:00 2001 From: gaurav <68292573+gvv2137@users.noreply.github.com> Date: Sun, 4 Oct 2020 03:56:35 +0530 Subject: [PATCH 360/394] pattern1 --- pattern1.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pattern1.c diff --git a/pattern1.c b/pattern1.c new file mode 100644 index 00000000..5dad2aa3 --- /dev/null +++ b/pattern1.c @@ -0,0 +1,27 @@ +#include +#include +int main() +{ +int n, x, y, k; +printf("Enter the number of rows to show number pattern: "); +scanf("%d",&n); +for(x =1; x <= n; x++) +{ +for(y =1; y <= n; y++) +{ +if(y <= x) +printf("%d",y); +else +printf(" "); +} +for(y = n; y >= 1;y--) +{ +if(y <= x) +printf("%d",y); +else +printf(" "); +} +printf("\n"); +} +return 0; +} From b4c775490d460304c0e15f096fbbc1c33db5e31d Mon Sep 17 00:00:00 2001 From: sankha2812 <72124074+sankha2812@users.noreply.github.com> Date: Sun, 4 Oct 2020 04:39:16 +0530 Subject: [PATCH 361/394] bubble sort --- bubble sort in C | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bubble sort in C diff --git a/bubble sort in C b/bubble sort in C new file mode 100644 index 00000000..bee530d0 --- /dev/null +++ b/bubble sort in C @@ -0,0 +1,41 @@ + +#include + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +// A function to implement bubble sort +void bubbleSort(int arr[], int n) +{ +int i, j; +for (i = 0; i < n-1; i++) + + // Last i elements are already in place + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +/* Function to print an array */ +void printArray(int arr[], int size) +{ + int i; + for (i=0; i < size; i++) + printf("%d ", arr[i]); + printf("\n"); +} + + +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + printf("Sorted array: \n"); + printArray(arr, n); + return 0; +} From 0130e17676e5af8eaee95975e2226e6efb783c1c Mon Sep 17 00:00:00 2001 From: RAJ KALASH TIWARI <72326535+rjkalash@users.noreply.github.com> Date: Sun, 4 Oct 2020 08:05:39 +0530 Subject: [PATCH 362/394] String reverse This is a C language program to reverse the strings --- String reverse | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 String reverse diff --git a/String reverse b/String reverse new file mode 100644 index 00000000..8902cb47 --- /dev/null +++ b/String reverse @@ -0,0 +1,20 @@ +// Created by rjkalash + +#include +#include +int main() +{ + char mess[80], stress[80]; + int i,j,len; + printf("Enter any string:"); + scanf("%s",&mess); + j=0; + len=strlen(mess); + for (i=len-1;i>=0;i--) + { + stress[j++]=mess[i]; + } + stress[j]='\0'; + printf ("the reversed string is =%s",stress); + return 0; + } From 64e20557483a39d2955b89c07ae473c2ebabd94b Mon Sep 17 00:00:00 2001 From: merinbenny <47379260+merinbenny@users.noreply.github.com> Date: Sun, 4 Oct 2020 08:35:56 +0530 Subject: [PATCH 363/394] armstrong program to find armstrong number --- armstrong | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 armstrong diff --git a/armstrong b/armstrong new file mode 100644 index 00000000..ed266025 --- /dev/null +++ b/armstrong @@ -0,0 +1,18 @@ +#include +void main() +{ + int num,armstrong=0,reminder,n; + printf("enter the number"); + scanf("%d",&num); + n=num; + while(n>0) + { + reminder=n%10; + armstrong=armstrong +(reminder*reminder*reminder); + n=n/10; + } + if(num==armstrong) + printf("%d is armstrong number",num); + else + printf("%d is not armstrong number",num); +} From f5ae18cd57a05f13ed7b1076bb09fbce71258655 Mon Sep 17 00:00:00 2001 From: merinbenny <47379260+merinbenny@users.noreply.github.com> Date: Sun, 4 Oct 2020 08:43:04 +0530 Subject: [PATCH 364/394] palindrom C program to find palindrom --- palindrom | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 palindrom diff --git a/palindrom b/palindrom new file mode 100644 index 00000000..cc065251 --- /dev/null +++ b/palindrom @@ -0,0 +1,18 @@ +#include +void main() +{ + int num,n,reverce=0,reminder; + printf("enter the number"); + scanf("%d",&num); + n=num; + while(n>0) + { + reminder=n%10; + reverce=(reverce*10)+reminder; + n=n/10; + } + if(num==reverce) + printf("palindrom"); + else + printf("not palindrome"); +} From 4893f23147b42359a8a8b749f1dc4091d86a1e1e Mon Sep 17 00:00:00 2001 From: Siddharth Gautam <68075023+siddh2@users.noreply.github.com> Date: Sun, 4 Oct 2020 09:14:27 +0530 Subject: [PATCH 365/394] FahrenheitToCentigrade Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees. --- FahrenheitToCentigrade | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 FahrenheitToCentigrade diff --git a/FahrenheitToCentigrade b/FahrenheitToCentigrade new file mode 100644 index 00000000..2b35b6ca --- /dev/null +++ b/FahrenheitToCentigrade @@ -0,0 +1,10 @@ +/*Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.*/ +#include +int main() +{ + int c,f; + printf("Enter the value in Fahrenheit "); + scanf("%d",&f); + c=(f-32)*.5556; ;/*(50°F - 32) x .5556 = 10°C*/ + printf("%d",c); +} From 0934a1b3e862f16475e34c4e4754bd7c9cca5360 Mon Sep 17 00:00:00 2001 From: pradyumn sharma <54592810+P-cpu@users.noreply.github.com> Date: Sun, 4 Oct 2020 10:33:58 +0530 Subject: [PATCH 366/394] Program for merge sorting by c Merge sort --- Merge sort | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Merge sort diff --git a/Merge sort b/Merge sort new file mode 100644 index 00000000..a01eb008 --- /dev/null +++ b/Merge sort @@ -0,0 +1,176 @@ +/* C program for Merge Sort */ +#include +#include + + +// Merges two subarrays of arr[]. +// First subarray is arr[l..m] +// Second subarray is arr[m+1..r] + +void merge(int arr[], int l, int m, int r) +{ + + int i, j, k; + + int n1 = m - l + 1; + + int n2 = r - m; + + + + /* create temp arrays */ + + int L[n1], R[n2]; + + + + /* Copy data to temp arrays L[] and R[] */ + + for (i = 0; i < n1; i++) + + L[i] = arr[l + i]; + + for (j = 0; j < n2; j++) + + R[j] = arr[m + 1 + j]; + + + + /* Merge the temp arrays back into arr[l..r]*/ + + i = 0; // Initial index of first subarray + + j = 0; // Initial index of second subarray + + k = l; // Initial index of merged subarray + + while (i < n1 && j < n2) { + + if (L[i] <= R[j]) { + + arr[k] = L[i]; + + i++; + + } + + else { + + arr[k] = R[j]; + + j++; + + } + + k++; + + } + + + + /* Copy the remaining elements of L[], if there + + are any */ + + while (i < n1) { + + arr[k] = L[i]; + + i++; + + k++; + + } + + + + /* Copy the remaining elements of R[], if there + + are any */ + + while (j < n2) { + + arr[k] = R[j]; + + j++; + + k++; + + } +} + + +/* l is for left index and r is right index of the + + sub-array of arr to be sorted */ + +void mergeSort(int arr[], int l, int r) +{ + + if (l < r) { + + // Same as (l+r)/2, but avoids overflow for + + // large l and h + + int m = l + (r - l) / 2; + + + + // Sort first and second halves + + mergeSort(arr, l, m); + + mergeSort(arr, m + 1, r); + + + + merge(arr, l, m, r); + + } +} + + +/* UTILITY FUNCTIONS */ +/* Function to print an array */ + +void printArray(int A[], int size) +{ + + int i; + + for (i = 0; i < size; i++) + + printf("%d ", A[i]); + + printf("\n"); +} + + +/* Driver program to test above functions */ + +int main() +{ + + int arr[] = { 12, 11, 13, 5, 6, 7 }; + + int arr_size = sizeof(arr) / sizeof(arr[0]); + + + + printf("Given array is \n"); + + printArray(arr, arr_size); + + + + mergeSort(arr, 0, arr_size - 1); + + + + printf("\nSorted array is \n"); + + printArray(arr, arr_size); + + return 0; +} From 9b7e65cfff0c6911e6e9b5528ca4525870ac68ce Mon Sep 17 00:00:00 2001 From: shiva439 <72330337+shiva439@users.noreply.github.com> Date: Sun, 4 Oct 2020 10:52:27 +0530 Subject: [PATCH 367/394] Create Display occurrence of word in given string. Creating to display occurrence of word in given string. --- Display occurrence of word in given string. | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Display occurrence of word in given string. diff --git a/Display occurrence of word in given string. b/Display occurrence of word in given string. new file mode 100644 index 00000000..7eff1cf9 --- /dev/null +++ b/Display occurrence of word in given string. @@ -0,0 +1,28 @@ +#include +#include +main() +{ + int i,len,sublen,count=0; + char str[100],substr[20],tempstr[20]; + printf("Enter String\n"); + gets(str); + printf("Enter substring to find Occurances\n"); + gets(substr); + len=strlen(str); + sublen=strlen(substr); + if(len>=sublen) + { + for(i=0;i Date: Sun, 4 Oct 2020 10:58:35 +0530 Subject: [PATCH 368/394] Create Remove repeated words in string. Learn Removing repeated elements of array elements --- Remove repeated words in string. | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Remove repeated words in string. diff --git a/Remove repeated words in string. b/Remove repeated words in string. new file mode 100644 index 00000000..304072e5 --- /dev/null +++ b/Remove repeated words in string. @@ -0,0 +1,51 @@ +#include +#include +main() +{ + int i=0,j=0,k=0,a,minIndex=0,maxIndex=0,max=0,min=0; + char str1[100]={0},substr[100][100]={0},c; + printf("Enter a sentence\n"); + gets(str1); + while(str1[k]!='\0')//for splitting sentence + { + j=0; + while(str1[k]!=' '&&str1[k]!='\0') + { + substr[i][j]=str1[k]; + k++; + j++; + } + substr[i][j]='\0'; + i++; + if(str1[k]!='\0') + { + k++; + } + } + int len=i; + //Removing repeated words same as removing repeated elements in arrays + for(i=0;i Date: Sun, 4 Oct 2020 11:00:56 +0530 Subject: [PATCH 369/394] Create First small letter in string Finding the first small letter in string. --- First small letter in string | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 First small letter in string diff --git a/First small letter in string b/First small letter in string new file mode 100644 index 00000000..aac1a531 --- /dev/null +++ b/First small letter in string @@ -0,0 +1,20 @@ +#include +#include +main() +{ + int i,flag=0; + char str[100]; + printf("Enter String to get First Small Letter of String\n"); + gets(str); + for(i=0;i'a' && str[i]<'z') + { + printf("The First Small Letter is %c\n",str[i]); + flag=1; + break; + } + } + if(flag!=1) + printf("There is no small letter\n"); +} From 202d18681260f29a9e2a10330d38322cda44d60b Mon Sep 17 00:00:00 2001 From: shiva439 <72330337+shiva439@users.noreply.github.com> Date: Sun, 4 Oct 2020 11:02:47 +0530 Subject: [PATCH 370/394] Create Remove common alphabets from 2nd string Removing common alphabets from 2nd string. --- Remove common alphabets from 2nd string | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Remove common alphabets from 2nd string diff --git a/Remove common alphabets from 2nd string b/Remove common alphabets from 2nd string new file mode 100644 index 00000000..ecd2ebca --- /dev/null +++ b/Remove common alphabets from 2nd string @@ -0,0 +1,32 @@ +#include +#include +main() +{ +int i=0,flag=0,len1,len2,j,k=0; +char str1[100],str2[100],temp[100]={0}; +printf("Enter a string 1\n"); +gets(str1); +printf("Enter a string 2\n"); +gets(str2); +len1=strlen(str1); +len2=strlen(str2); + + for(i=0;i Date: Sun, 4 Oct 2020 11:18:35 +0530 Subject: [PATCH 371/394] Create BST_Level-Order_Traversal.cpp --- BST_Level-Order_Traversal.cpp | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 BST_Level-Order_Traversal.cpp diff --git a/BST_Level-Order_Traversal.cpp b/BST_Level-Order_Traversal.cpp new file mode 100644 index 00000000..b8792eba --- /dev/null +++ b/BST_Level-Order_Traversal.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include + +using namespace std; +class Node{ + public: + int data; + Node *left,*right; + Node(int d){ + data=d; + left=right=NULL; + } +}; +class Solution{ + public: + Node* insert(Node* root, int data){ + if(root==NULL){ + return new Node(data); + } + else{ + Node* cur; + if(data<=root->data){ + cur=insert(root->left,data); + root->left=cur; + } + else{ + cur=insert(root->right,data); + root->right=cur; + } + return root; + } + } + + void levelOrder(Node * root){ + //Write your code here + if (root == NULL) + return; + queue q; + q.push(root); + while(!q.empty()){ + Node* current = q.front(); + cout<< current->data << " "; + if(current->left != NULL) + q.push(current->left); + + if(current->right !=NULL) + q.push(current->right); + + q.pop(); + } + } +};//End of Solution +int main(){ + Solution myTree; + Node* root=NULL; + int T,data; + cin>>T; + while(T-->0){ + cin>>data; + root= myTree.insert(root,data); + } + myTree.levelOrder(root); + return 0; +} From 47f128ce975fc3935407f7f9eaa072454fac8b63 Mon Sep 17 00:00:00 2001 From: mohitgora55 <51796016+mohitgora55@users.noreply.github.com> Date: Sun, 4 Oct 2020 11:20:55 +0530 Subject: [PATCH 372/394] Create RegEx_Patterns_and_Intro_to_Databases.cpp --- RegEx_Patterns_and_Intro_to_Databases.cpp | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 RegEx_Patterns_and_Intro_to_Databases.cpp diff --git a/RegEx_Patterns_and_Intro_to_Databases.cpp b/RegEx_Patterns_and_Intro_to_Databases.cpp new file mode 100644 index 00000000..e29ba389 --- /dev/null +++ b/RegEx_Patterns_and_Intro_to_Databases.cpp @@ -0,0 +1,27 @@ +#include +#include + +using namespace std; + + +int main(){ + int N; + cin >> N; + list names; + for(int a0 = 0; a0 < N; a0++){ + string firstName; + string emailID; + cin >> firstName >> emailID; + if (regex_match (emailID, regex(".+@gmail.com") )){ + names.push_back(firstName); + } + } + names.sort(); + while (!names.empty()) + { + cout << names.front()< Date: Sun, 4 Oct 2020 11:31:14 +0530 Subject: [PATCH 373/394] Squareroot Find the square root of any number ? --- Squareroot | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Squareroot diff --git a/Squareroot b/Squareroot new file mode 100644 index 00000000..032b5041 --- /dev/null +++ b/Squareroot @@ -0,0 +1,13 @@ +#include +#include +#include +void main() +{ + float x,y; + clrscr(); + printf("Enter the number \n"); + scanf("%f",&x); + y-sqrt(x); + printf("Square root of %f \n",x,y); + getch(); +} From c0394b0f62e98dbe9df4361686bb2c7e93c32415 Mon Sep 17 00:00:00 2001 From: ayshubham <71246748+ayshubham@users.noreply.github.com> Date: Sun, 4 Oct 2020 11:32:49 +0530 Subject: [PATCH 374/394] calculator --- p for calculator | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 p for calculator diff --git a/p for calculator b/p for calculator new file mode 100644 index 00000000..a8bd462a --- /dev/null +++ b/p for calculator @@ -0,0 +1,29 @@ +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +} From 44d0c2d5bfd5a23d3751a24183cf6d025904936b Mon Sep 17 00:00:00 2001 From: Kunal Bhardwaj <64344636+kunalbhardwaj2922@users.noreply.github.com> Date: Sun, 4 Oct 2020 11:32:52 +0530 Subject: [PATCH 375/394] subtract subtraction of two no. --- subtract | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 subtract diff --git a/subtract b/subtract new file mode 100644 index 00000000..135a5f94 --- /dev/null +++ b/subtract @@ -0,0 +1,20 @@ +#include + +int main() +{ + int a,b,sub; + + //Read value of a + printf("Enter the first no.: "); + scanf("%d",&a); + + //Read value of b + printf("Enter the second no.: "); + scanf("%d",&b); + + //formula of subtraction + sub= a-b; + printf("subtract is = %d\n", sub); + + return 0; +} From 4bc9ae79174d9f812c89e564bd6862dcf9ea3d13 Mon Sep 17 00:00:00 2001 From: amansharma193 <72331702+amansharma193@users.noreply.github.com> Date: Sun, 4 Oct 2020 11:38:25 +0530 Subject: [PATCH 376/394] Sum program to calculate sum of two numbers in c --- Sum | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Sum diff --git a/Sum b/Sum new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/Sum @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +} From 8152299593234da004da0179dec257389471b936 Mon Sep 17 00:00:00 2001 From: ShrutiPandey27 <69622082+ShrutiPandey27@users.noreply.github.com> Date: Sun, 4 Oct 2020 12:21:12 +0530 Subject: [PATCH 377/394] Create linked_list_deletion.c I have done program for deletion of a node from linked list in C language --- linked_list_deletion.c | 164 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 linked_list_deletion.c diff --git a/linked_list_deletion.c b/linked_list_deletion.c new file mode 100644 index 00000000..afe19f36 --- /dev/null +++ b/linked_list_deletion.c @@ -0,0 +1,164 @@ +Deletion of first node of singly linked list3 +Free the memory occupied by the first node. +Deletion of first node of singly linked list4 +Program to delete first node of Singly Linked List +/** + * C program to delete first node from Singly Linked List + */ + +#include +#include + + +/* Structure of a node */ +struct node { + int data; // Data + struct node *next; // Address +}*head; + + +void createList(int n); +void deleteFirstNode(); +void displayList(); + + + +int main() +{ + int n, choice; + + /* + * Create a singly linked list of n nodes + */ + printf("Enter the total number of nodes: "); + scanf("%d", &n); + createList(n); + + printf("\nData in the list \n"); + displayList(); + + printf("\nPress 1 to delete first node: "); + scanf("%d", &choice); + + /* Delete first node from list */ + if(choice == 1) + deleteFirstNode(); + + printf("\nData in the list \n"); + displayList(); + + return 0; +} + + +/* + * Create a list of n nodes + */ +void createList(int n) +{ + struct node *newNode, *temp; + int data, i; + + head = (struct node *)malloc(sizeof(struct node)); + + /* + * If unable to allocate memory for head node + */ + if(head == NULL) + { + printf("Unable to allocate memory."); + } + else + { + /* + * In data of node from the user + */ + printf("Enter the data of node 1: "); + scanf("%d", &data); + + head->data = data; // Link the data field with data + head->next = NULL; // Link the address field to NULL + + temp = head; + + /* + * Create n nodes and adds to linked list + */ + for(i=2; i<=n; i++) + { + newNode = (struct node *)malloc(sizeof(struct node)); + + /* If memory is not allocated for newNode */ + if(newNode == NULL) + { + printf("Unable to allocate memory."); + break; + } + else + { + printf("Enter the data of node %d: ", i); + scanf("%d", &data); + + newNode->data = data; // Link the data field of newNode with data + newNode->next = NULL; // Link the address field of newNode with NULL + + temp->next = newNode; // Link previous node i.e. temp to the newNode + temp = temp->next; + } + } + + printf("SINGLY LINKED LIST CREATED SUCCESSFULLY\n"); + } +} + + +/* + * Deletes the first node of the linked list + */ +void deleteFirstNode() +{ + struct node *toDelete; + + if(head == NULL) + { + printf("List is already empty."); + } + else + { + toDelete = head; + head = head->next; + + printf("\nData deleted = %d\n", toDelete->data); + + /* Clears the memory occupied by first node*/ + free(toDelete); + + printf("SUCCESSFULLY DELETED FIRST NODE FROM LIST\n"); + } +} + + +/* + * Displays the entire list + */ +void displayList() +{ + struct node *temp; + + /* + * If the list is empty i.e. head = NULL + */ + if(head == NULL) + { + printf("List is empty."); + } + else + { + temp = head; + while(temp != NULL) + { + printf("Data = %d\n", temp->data); // Print data of current node + temp = temp->next; // Move to next node + } + } +} From 891eb157baead6c0029349494e051e76a1de2c87 Mon Sep 17 00:00:00 2001 From: BlackThor555 <71896096+BlackThor555@users.noreply.github.com> Date: Sun, 4 Oct 2020 12:56:45 +0530 Subject: [PATCH 378/394] Addition of 2 no Addition of 2 numbers --- addition no | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 addition no diff --git a/addition no b/addition no new file mode 100644 index 00000000..6fe498d2 --- /dev/null +++ b/addition no @@ -0,0 +1,3 @@ +int main() { int x, y, z; +printf("Enter two numbers to add\n"); scanf("%d%d", &x, &y); +printf("Sum of the numbers = %d\n", z); From 8228c612aa03a786941e60028d62c0443769346b Mon Sep 17 00:00:00 2001 From: Avnishtiwari111 <61021125+Avnishtiwari111@users.noreply.github.com> Date: Sun, 4 Oct 2020 13:10:05 +0530 Subject: [PATCH 379/394] Create to find prime number prime number --- to find prime number | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 to find prime number diff --git a/to find prime number b/to find prime number new file mode 100644 index 00000000..4fba8ae0 --- /dev/null +++ b/to find prime number @@ -0,0 +1,27 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + + for (i = 2; i <= n / 2; ++i) { + + // condition for non-prime + if (n % i == 0) { + flag = 1; + break; + } + } + + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From 5f5f8f6e7b40892df661c88a386b29516d5a81bd Mon Sep 17 00:00:00 2001 From: Avnishtiwari111 <61021125+Avnishtiwari111@users.noreply.github.com> Date: Sun, 4 Oct 2020 13:12:12 +0530 Subject: [PATCH 380/394] Create to find fibonacci series fibo series --- to find fibonacci series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 to find fibonacci series diff --git a/to find fibonacci series b/to find fibonacci series new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/to find fibonacci series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 2c507b58b2cdcd2731a1b03e6c8e62a30da1ab18 Mon Sep 17 00:00:00 2001 From: Pritomk <66419135+Pritomk@users.noreply.github.com> Date: Sun, 4 Oct 2020 13:13:31 +0530 Subject: [PATCH 381/394] datatypes types of datatypes in c programming language --- datatypes | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 datatypes diff --git a/datatypes b/datatypes new file mode 100644 index 00000000..53e78bf9 --- /dev/null +++ b/datatypes @@ -0,0 +1,25 @@ +#include +int main() +{ + int a = 1; + char b ='G'; + double c = 3.14; + printf("Hello World!\n"); + + + printf("Hello! I am a character. My value is %c and " + "my size is %lu byte.\n", b,sizeof(char)); + + + printf("Hello! I am an integer. My value is %d and " + "my size is %lu bytes.\n", a,sizeof(int)); + + + printf("Hello! I am a double floating point variable." + " My value is %lf and my size is %lu bytes.\n",c,sizeof(double)); + + + printf("Bye! See you soon. :)\n"); + + return 0; +} From e4e8366af96b7f3e8929c8f1b0392911704746fd Mon Sep 17 00:00:00 2001 From: Rohitkumar158 <69768295+Rohitkumar158@users.noreply.github.com> Date: Sun, 4 Oct 2020 13:54:30 +0530 Subject: [PATCH 382/394] cubeno Program to Calculate Cube of a Number --- cubeno | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 cubeno diff --git a/cubeno b/cubeno new file mode 100644 index 00000000..41e0a437 --- /dev/null +++ b/cubeno @@ -0,0 +1,17 @@ +/* C Program to find Cube of a Number */ + +#include + +int main() +{ + int number, cube; + + printf(" \n Please Enter any integer Value : "); + scanf("%d", &number); + + cube = number * number * number; + + printf("\n Cube of a given number %d is = %d", number, cube); + + return 0; +} From 423884dbaa4d985be5f21b3e1516a2ad475982cb Mon Sep 17 00:00:00 2001 From: unknown-hac <72150063+unknown-hac@users.noreply.github.com> Date: Sun, 4 Oct 2020 14:04:37 +0530 Subject: [PATCH 383/394] primr_or_not Program to find whether a number is prime or not. --- prime_or_not | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 prime_or_not diff --git a/prime_or_not b/prime_or_not new file mode 100644 index 00000000..97eb4703 --- /dev/null +++ b/prime_or_not @@ -0,0 +1,33 @@ +#include + +int main(){ + int i,n,prime=1; + printf("Enter number"); + scanf("%d",&n); + + if(n==1){ + printf("1 is not a prime number"); + } + + else if(n==2){ + printf("2 is not a prime number"); + } + + else{ + for (i=2; i Date: Sun, 4 Oct 2020 14:31:53 +0530 Subject: [PATCH 384/394] Fibonacci Series Program of Fibonacci Series --- Program of Fibonacci Series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program of Fibonacci Series diff --git a/Program of Fibonacci Series b/Program of Fibonacci Series new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/Program of Fibonacci Series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 30168b640b62ec88197114350a265724904a364a Mon Sep 17 00:00:00 2001 From: Vaibhav Mawari <66474921+Vaibh04@users.noreply.github.com> Date: Sun, 4 Oct 2020 14:56:10 +0530 Subject: [PATCH 385/394] Max of 3 Program to find the greatest of 3. --- Maxof3 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Maxof3 diff --git a/Maxof3 b/Maxof3 new file mode 100644 index 00000000..de3636be --- /dev/null +++ b/Maxof3 @@ -0,0 +1,22 @@ +#include +int main() +{ +int a,b,c,max; +cout<<"Enter 3 numbers: "<>a>>b>>c; +cout<<"The max between a,b and c is: " +if(a>b) +{ +max=a; +} +if(b>a) +{ +max=b; +} +if(c>max) +{ +max=c; +} +cout< Date: Sun, 4 Oct 2020 14:59:58 +0530 Subject: [PATCH 386/394] count char number and alphabet program to count total number of alphabets, digits and special characters in a string. --- ...totalno_of_alphabet_digit_and_special_char | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 count_totalno_of_alphabet_digit_and_special_char diff --git a/count_totalno_of_alphabet_digit_and_special_char b/count_totalno_of_alphabet_digit_and_special_char new file mode 100644 index 00000000..06578b9d --- /dev/null +++ b/count_totalno_of_alphabet_digit_and_special_char @@ -0,0 +1,43 @@ +#include +#include +#include + + +#define str_size 100 //Declare the maximum size of the string + +void main() +{ + char str[str_size]; + int alp, digit, splch, i; + alp = digit = splch = i = 0; + + + printf("\n\nCount total number of alphabets, digits and special characters :\n"); + printf("--------------------------------------------------------------------\n"); + printf("Input the string : "); + fgets(str, sizeof str, stdin); + + /* Checks each character of string*/ + + while(str[i]!='\0') + { + if((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')) + { + alp++; + } + else if(str[i]>='0' && str[i]<='9') + { + digit++; + } + else + { + splch++; + } + + i++; + } + + printf("Number of Alphabets in the string is : %d\n", alp); + printf("Number of Digits in the string is : %d\n", digit); + printf("Number of Special characters in the string is : %d\n\n", splch); +} From 1b44bce0b1966dd9431317a13c9e1a4d34790771 Mon Sep 17 00:00:00 2001 From: Tiger16199620 <32063490+Tiger16199620@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:07:12 +0530 Subject: [PATCH 387/394] standard deviation Program to Calculate Standard Deviation in c --- standard deviation | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 standard deviation diff --git a/standard deviation b/standard deviation new file mode 100644 index 00000000..73cf1ed9 --- /dev/null +++ b/standard deviation @@ -0,0 +1,24 @@ +#include +#include +float calculateSD(float data[]); +int main() { + int i; + float data[10]; + printf("Enter 10 elements: "); + for (i = 0; i < 10; ++i) + scanf("%f", &data[i]); + printf("\nStandard Deviation = %.6f", calculateSD(data)); + return 0; +} + +float calculateSD(float data[]) { + float sum = 0.0, mean, SD = 0.0; + int i; + for (i = 0; i < 10; ++i) { + sum += data[i]; + } + mean = sum / 10; + for (i = 0; i < 10; ++i) + SD += pow(data[i] - mean, 2); + return sqrt(SD / 10); +} From 25ba940d20b268788cf4d95397e29343fa8a70f0 Mon Sep 17 00:00:00 2001 From: RITIK AGRWAL <45240336+RITIKAGRWAL@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:13:20 +0530 Subject: [PATCH 388/394] checkpalindrome check palindrome using while loop in C --- checkpalindrome | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 checkpalindrome diff --git a/checkpalindrome b/checkpalindrome new file mode 100644 index 00000000..683bdd86 --- /dev/null +++ b/checkpalindrome @@ -0,0 +1,28 @@ +#include +int main() +{ + int num, reverse_num=0, remainder,temp; + printf("Enter an integer: "); + scanf("%d", &num); + + /* Here we are generating a new number (reverse_num) + * by reversing the digits of original input number + */ + temp=num; + while(temp!=0) + { + remainder=temp%10; + reverse_num=reverse_num*10+remainder; + temp/=10; + } + + /* If the original input number (num) is equal to + * to its reverse (reverse_num) then its palindrome + * else it is not. + */ + if(reverse_num==num) + printf("%d is a palindrome number",num); + else + printf("%d is not a palindrome number",num); + return 0; +} From 990447e1757f12f391c002aa43a856ce45d43fae Mon Sep 17 00:00:00 2001 From: RITIK AGRWAL <45240336+RITIKAGRWAL@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:17:04 +0530 Subject: [PATCH 389/394] checkPalindrome check palindrome using while loop --- checkPalindrome | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 checkPalindrome diff --git a/checkPalindrome b/checkPalindrome new file mode 100644 index 00000000..683bdd86 --- /dev/null +++ b/checkPalindrome @@ -0,0 +1,28 @@ +#include +int main() +{ + int num, reverse_num=0, remainder,temp; + printf("Enter an integer: "); + scanf("%d", &num); + + /* Here we are generating a new number (reverse_num) + * by reversing the digits of original input number + */ + temp=num; + while(temp!=0) + { + remainder=temp%10; + reverse_num=reverse_num*10+remainder; + temp/=10; + } + + /* If the original input number (num) is equal to + * to its reverse (reverse_num) then its palindrome + * else it is not. + */ + if(reverse_num==num) + printf("%d is a palindrome number",num); + else + printf("%d is not a palindrome number",num); + return 0; +} From 0a5ecd2cd254026c290ed6363fbfb4b8cd78d831 Mon Sep 17 00:00:00 2001 From: soni81 <44508431+soni81@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:37:14 +0530 Subject: [PATCH 390/394] Update Addition --- Addition | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Addition b/Addition index 18f9f81d..a87392cb 100644 --- a/Addition +++ b/Addition @@ -6,7 +6,7 @@ int main() { printf("Enter two integers: "); scanf("%d %d", &number1, &number2); - // calculating sum + // calculating sum efficiently sum = number1 + number2; printf("%d + %d = %d", number1, number2, sum); From 2d99a92eae69b24d8bdbaf3611c6b31167eceb98 Mon Sep 17 00:00:00 2001 From: Koushikkumr4u <65237550+Koushikkumr4u@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:38:04 +0530 Subject: [PATCH 391/394] even or odd number C Program to check if number is even or odd. --- even or odd number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 even or odd number diff --git a/even or odd number b/even or odd number new file mode 100644 index 00000000..8a29813a --- /dev/null +++ b/even or odd number @@ -0,0 +1,20 @@ +/* Program to check whether the input integer number + * is even or odd using the modulus operator (%) + */ +#include +int main() +{ + // This variable is to store the input number + int num; + + printf("Enter an integer: "); + scanf("%d",&num); + + // Modulus (%) returns remainder + if ( num%2 == 0 ) + printf("%d is an even number", num); + else + printf("%d is an odd number", num); + + return 0; +} From 0bacbb357aab4a339ebe79fe3d0e2293ee96f10c Mon Sep 17 00:00:00 2001 From: GEETU <35969449+geetu-sharma@users.noreply.github.com> Date: Sun, 4 Oct 2020 16:11:30 +0530 Subject: [PATCH 392/394] Create binStack.c --- binStack.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 binStack.c diff --git a/binStack.c b/binStack.c new file mode 100644 index 00000000..7e9a7e28 --- /dev/null +++ b/binStack.c @@ -0,0 +1,36 @@ +#include "stdio.h" +#include "stdlib.h" +struct xx +{ + int data; + struct xx *link; +}; +struct xx *sp=0,*q; +main() +{ + int n; + printf("Enter a decimal number :"); + scanf("%d",&n); + while(n>0) + { + if(n==0) + { + sp=(struct xx *)malloc(sizeof(struct xx)); + sp->data=n%2; + sp->link=0; + } + else + { + q=(struct xx *)malloc(sizeof(struct xx)); + q->link=sp; + sp=q; + sp->data=n%2; + } + n=n/2; + } + while(sp!=0) + { + printf("%d ",sp->data); + sp=sp->link; + } +} From 888e370e7bf9b1ed35f84263cab507203ab52b32 Mon Sep 17 00:00:00 2001 From: prateek21a <72228377+prateek21a@users.noreply.github.com> Date: Sun, 4 Oct 2020 16:18:40 +0530 Subject: [PATCH 393/394] Adding numbers Program of adding two number in c --- Program of adding two number in c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program of adding two number in c diff --git a/Program of adding two number in c b/Program of adding two number in c new file mode 100644 index 00000000..c7a914fb --- /dev/null +++ b/Program of adding two number in c @@ -0,0 +1,14 @@ +#include +int main() +{ + int x, y, z; + + printf("Enter two numbers to add\n"); + scanf("%d%d", &x, &y); + + z = x + y; + + printf("Sum of the numbers = %d\n", z); + + return 0; +} From babbaeeb65ff8b1e3c4d77192b4d52e5497f53e0 Mon Sep 17 00:00:00 2001 From: gaurav <68292573+gvv2137@users.noreply.github.com> Date: Sun, 4 Oct 2020 16:27:43 +0530 Subject: [PATCH 394/394] Add_number --- Add_to_numb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Add_to_numb diff --git a/Add_to_numb b/Add_to_numb new file mode 100644 index 00000000..18f9f81d --- /dev/null +++ b/Add_to_numb @@ -0,0 +1,14 @@ +#include +int main() { + + int number1, number2, sum; + + printf("Enter two integers: "); + scanf("%d %d", &number1, &number2); + + // calculating sum + sum = number1 + number2; + + printf("%d + %d = %d", number1, number2, sum); + return 0; +}