Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
amantiwari8861 committed Sep 19, 2023
1 parent 4a8e094 commit 00e5d46
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 76 deletions.
22 changes: 2 additions & 20 deletions 05-Loops_&_Nested_loops/Nested Loop/ExercSoln/Q2.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
<<<<<<< HEAD
#include<stdio.h>
int main()
{

for (int row = 0; row < 5; row++)
{
for(int col=0;col<=row;col++)
{
printf("*");
}
printf("\n");
}

return 0;
}
=======
#include<stdio.h>
int main()
{

for (int row = 1; row <= 5; row++)
for (int row = 0; row < 5; row++)
{
for(int col=1;col<=row;col++)
for(int col=0;col<=row;col++)
{
printf("*");
}
Expand All @@ -30,4 +13,3 @@ int main()

return 0;
}
>>>>>>> eaa42a88730f025ddb6412a578957c2e832dfae6
30 changes: 30 additions & 0 deletions 05-Loops_&_Nested_loops/Nested Loop/ExercSoln/Q9New.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>
int main()
{

for (int row = 1; row <= 7; row++)
{
for (int col = 1; col <= 10 ; col++)
{
if (row==1 || row==7)
{
printf("*");
}
else
{
if (col==1 || col==10)
{
printf("*");
}
else
{
printf(" ");
}
}
}
printf("\n");
}


return 0;
}
4 changes: 2 additions & 2 deletions 05-Loops_&_Nested_loops/Nested Loop/ExercSoln/pattern1.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include<stdio.h>
// #include<windows.h>
#include<windows.h>
int main()
{

for (int row = 0; row < 5; row++)
{
for (int col = 0; col <8 ; col++)
{
// Sleep(500);
printf("*");
Sleep(500);
}
printf("\n");
}
Expand Down
31 changes: 20 additions & 11 deletions 05-Loops_&_Nested_loops/Nested Loop/Nested1.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<stdio.h>
// #include<windows.h>
#include<unistd.h>
#include<windows.h>
// #include<unistd.h>
int main()
{

Expand All @@ -9,22 +9,31 @@ int main()
// printf(" Chapter %d \n",i);
// for (int j = 1; j <= 4; j++)
// {
// printf("\tPara %d ",j);
// // Sleep(100);
// printf("\tSection %d ",j);
// // Sleep(1000);
// }
// printf("\n");
// }


for (int i = 1; i <= 4; i++)
// for (int i = 1; i <= 4; i++)
// {
// for (int j = 1; j <= 5; j++)
// {
// printf("i=%d j=%d ",i,j);
// Sleep(1000);
// }
// printf("\n");
// }

for (int i = 0; i < 4; i++)
{
for (int j = 1; j <= 5; j++)
for (int j = 5; j > 0; j--)
{
printf("i=%d j=%d ",i,j);
Sleep(1000);
printf("i=%d j=%d ",i,j);
}
printf("\n");
}
printf("\n");
}

return 0;
}
32 changes: 16 additions & 16 deletions 05-Loops_&_Nested_loops/Nested Loop/NestedLoopsExercise.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ ABCDE
123454321

15.
*
* *
* * *
* * * *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * *
* * * *
* * * *
* * * *
*
* *
* * *
* * * *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * *
* * * *
* * * *
* * * *

https://www.faceprep.in/c/pattern-programs-in-c/
22 changes: 22 additions & 0 deletions 05-Loops_&_Nested_loops/Nested Loop/programs/Q14.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
int main()
{
for (int row = 0; row < 5; row++)
{
for (int sp = 5-1; sp > row; sp--)
{
printf(" ");
}
for (int j = 0; j <=row; j++)
{
printf("%d",j+1);
}
for (int k = row; k > 0; k--)
{
printf("%d",k);
}
printf("\n");
}

return 0;
}
46 changes: 46 additions & 0 deletions 05-Loops_&_Nested_loops/Nested Loop/programs/Q15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<stdio.h>
#include<windows.h>
int main()
{
int space=7;
for (int row = 1; row <= 16; row++)
{
for (int col = 1; col <= 8; col++)
{
if (col<=space)
{
printf(" ");
// Sleep(500);
}
else
{
if(row<=12)
printf("\x1b[32m* \x1b[0m");
else
printf("\x1b[33m* \x1b[0m");
}
}
// Sleep(2000);
if (row<12)
{
if (row%4==0)
{
space++;
}
else
{
space--;
}
}
else
{
space=4;
}
printf("\n");
}




return 0;
}
9 changes: 5 additions & 4 deletions 05-Loops_&_Nested_loops/Nested Loop/programs/pattern1.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <stdio.h>

#include<windows.h>
int main()
{
for (int i = 0; i < 3; i++)
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
for (int j = 0; j < 8; j++)
{
printf("@");
printf("*");
Sleep(1000);
}
printf("\n");
}
Expand Down
2 changes: 1 addition & 1 deletion 08-Function/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main()
{
int num1,num2;
printf("enter 2 numbers \n");
scanf("%d %d",&num1,&num2);//10 20
scanf("%d%d",&num1,&num2);//10 20
printf("the value before swapping in main num1=%d and num2=%d \n",num1,num2);//10 20
swap(num1,num2);//call by value
printf("the value after swapping in main num1=%d and num2=%d \n",num1,num2); //20 10 ?
Expand Down
Binary file removed 13-Pointers/charptr
Binary file not shown.
Binary file removed 13-Pointers/charptr3
Binary file not shown.
20 changes: 10 additions & 10 deletions 13-Pointers/pointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ int main()
// Pointer: it is a variable whose value is the address of another variable
// syntax: datatype *pointername;
int *ptr; //pointer stores the address of another variable
// //this pointer can store the address of int datatype variable
// // char *ptr2;
// // //this pointer can store the address of int datatype variable
// // // char *ptr2;
ptr=&num;
// * represents the value at address
// // * represents the value at address
printf("the value in pointer ptr is %d \n",ptr); //6684188
printf("the value at address in pointer ptr is %d \n",*ptr);//50
*ptr=99;
printf("the value of num after changing =%d \n",num);
// *ptr=99;
// printf("the value of num after changing =%d \n",num);

// printf("the address of ptr pointer is %d \n",&ptr);//6684168

// int *ptr3=NULL; // null pointer
// int **dptr;
// dptr=&ptr;//6684168
// printf("the value in double pointer is %d \n",dptr);//6684168
// printf("the value at address dptr %d \n",*dptr);//6684188
// printf("the value at address of variable in dptr %d \n",**dptr);//50
int **dptr;
dptr=&ptr;//6684168
printf("the value in double pointer is %d \n",dptr);//6684168
printf("the value at address dptr %d \n",*dptr);//6684188
printf("the value at address of variable in dptr %d \n",**dptr);//50

return 0;
}
Binary file removed 13-Pointers/swapFxn
Binary file not shown.
5 changes: 2 additions & 3 deletions 13-Pointers/swapFxn.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ int main()
printf("enter 2 numbers \n");
scanf("%d %d",&num1,&num2);//10 20
printf("the value before swapping in main num1=%d and num2=%d \n",num1,num2);//10 20
swap(&num1,&num2);//call by reference
// swap(&num1,&num2);//call by reference or pass by reference (reference = address)
printf("the value after swapping in main num1=%d and num2=%d \n",num1,num2); //20 10
return 0;
}
//reference = address
}
5 changes: 3 additions & 2 deletions 14-File_handling/Program/structureReadWrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main()
{
FILE *of;
// of = fopen("test.txt", "w");
of = fopen("test.bin", "ab");
of = fopen("test.dat", "ab");
if (of == NULL)
{
fprintf(stderr,"\nError:unable to open the file\n");
Expand All @@ -25,6 +25,7 @@ int main()
fwrite(&inp1, sizeof(struct Course),1,of);
fwrite(&inp2, sizeof(struct Course),1,of);
fwrite(&inp3, sizeof(struct Course),1,of);

if (fwrite != 0)
printf("Contents to file written successfully !\n");
else
Expand All @@ -35,7 +36,7 @@ int main()
FILE *inf;
struct Course inp;
// inf = fopen("test.txt", "r");
inf = fopen("test.bin", "rb");
inf = fopen("test.dat", "rb");

if (inf == NULL)
{
Expand Down
Binary file removed 14-File_handling/Program/test.bin
Binary file not shown.
Binary file added 14-File_handling/Program/test.dat
Binary file not shown.
2 changes: 1 addition & 1 deletion 14-File_handling/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
int main()
{
FILE *fptr; //why we need file handling ?
fptr=fopen("C:\\Users\\Aman_Tiwari\\Desktop\\Client.java","r");//OPEN FILE IN READING MODE
fptr=fopen("C:\\Users\\admin\\Desktop\\Data.csv","r");//OPEN FILE IN READING MODE
if(fptr==NULL)
{
printf("Error! unable to open file");
Expand Down
22 changes: 16 additions & 6 deletions 14-File_handling/write.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#include<stdio.h>
#include<windows.h>
int main()
{
char sentence[100];
// char sentence[100];
FILE *fptr;
fptr=fopen("C:/Users/Aman_Tiwari/Desktop/priyanshu.txt","a");
printf("enter the sentence:\n");
fgets(sentence,100,stdin);
fprintf(fptr,"the sentence is :\t%s",sentence);
fclose(fptr);
// fptr=fopen("C:/Users/admin/Desktop/Aman.txt","w");
// fptr=fopen("C:/Users/admin/Desktop/Aman.txt","a");
// printf("enter the sentence:\n");
// fgets(sentence,100,stdin);
// fprintf(fptr,"the sentence is :\t%s",sentence);
// fclose(fptr);
// system("mkdir \"C:/Users/admin/Desktop/Ravi\"");
// system("code .");
system("rmdir /s \"C:/Users/admin/Desktop/Ravi\"");
// fptr=fopen("C:/Users/admin/Desktop/Ravi/Aman.txt","w");
// fclose(fptr);
// remove("C:/Users/admin/Desktop/Aman.txt");
// rename("C:/Users/admin/Desktop/Aman.txt","C:/Users/admin/Desktop/eklavya.txt");

return 0;
}
17 changes: 17 additions & 0 deletions extra/Q101.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int main()
{
for (int i = 1; i <= 5; i++)
{
for (int space = 1; space <i; space++)
{
printf(" ");
}
for (int star = 5; star >= i; star--)
{
printf("*");
}
printf("\n");
}
return 0;
}

0 comments on commit 00e5d46

Please sign in to comment.