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 001/164] 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 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 002/164] 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 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 003/164] 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 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 004/164] 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 005/164] 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 006/164] 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 007/164] 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 008/164] 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 009/164] 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 010/164] 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 011/164] 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 012/164] 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 013/164] 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 014/164] 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 015/164] 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 016/164] 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 017/164] 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 018/164] 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 019/164] 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 020/164] 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 021/164] 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 022/164] 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 023/164] 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 024/164] 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 025/164] 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 026/164] 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 027/164] 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 028/164] 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 029/164] 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 030/164] 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 031/164] 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 032/164] 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 033/164] 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 034/164] 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 035/164] 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 036/164] 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 037/164] 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 038/164] 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 039/164] 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 040/164] 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 041/164] 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 042/164] 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 043/164] 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 044/164] 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 045/164] 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 046/164] 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 047/164] 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 048/164] 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 049/164] 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 050/164] 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 051/164] 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 052/164] 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 053/164] 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 054/164] 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 055/164] 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 056/164] 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 057/164] 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 058/164] 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 059/164] 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 060/164] 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 061/164] 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 062/164] 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 063/164] 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 064/164] 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 065/164] 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 066/164] 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 067/164] 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 068/164] 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 069/164] 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 070/164] 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 071/164] 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 072/164] 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 073/164] 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 074/164] 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 075/164] 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 076/164] 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 077/164] 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 078/164] 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 079/164] 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 080/164] 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 081/164] 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 082/164] 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 083/164] 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 084/164] 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 085/164] 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 086/164] 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 087/164] 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 088/164] 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 089/164] 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 090/164] 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 091/164] 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 092/164] 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 093/164] 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 094/164] 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 095/164] =?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 096/164] 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 097/164] 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 098/164] 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 099/164] 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 100/164] 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 101/164] 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 102/164] 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 103/164] 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 104/164] 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 105/164] 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 106/164] 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 107/164] 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 108/164] 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 109/164] 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 110/164] 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 111/164] 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 112/164] 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 113/164] 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 114/164] 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 115/164] 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 116/164] 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 117/164] 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 118/164] 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 119/164] 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 120/164] 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 121/164] 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 122/164] 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 123/164] 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 124/164] 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 125/164] 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 126/164] 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 127/164] 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 128/164] 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 129/164] 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 130/164] 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 131/164] 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 132/164] 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 133/164] 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 134/164] 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 135/164] 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 136/164] 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 137/164] 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 138/164] 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 139/164] 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 140/164] 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 141/164] 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 142/164] 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 143/164] 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 144/164] 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 145/164] 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 146/164] 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 147/164] 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 148/164] 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 149/164] 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 150/164] 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 151/164] 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 152/164] 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 153/164] 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 154/164] 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 155/164] 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 156/164] 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 157/164] 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 158/164] 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 159/164] 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 160/164] 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 161/164] 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 162/164] 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 163/164] 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 164/164] 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; +}