Skip to content

Commit

Permalink
added more programs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcoder01 committed Oct 17, 2022
1 parent 5296464 commit 2332e5e
Show file tree
Hide file tree
Showing 12 changed files with 512 additions and 0 deletions.
96 changes: 96 additions & 0 deletions 2darray.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include<stdio.h>
#include<string.h>
char name[10][20] ={"Ananya","Bikramjit","Chityoraj","Dharmesh","Elen","Fatama","Ganasan","Harischandra","Intrajit","Jagdip"};
char roll[10][6] ={"CS101","CS102","CS103","CS104","CS105","CS106","CS107","CS108","CS109","CS110"};
int Marks[10][3] = {
{ 65,75,90},
{ 70,55,73},
{ 55,54,85},
{ 63,65,92},
{ 60,30,65},
{ 72,84,50},
{ 86,76,30},
{ 73,89,67},
{ 91,73,75},
{ 45,35,83},
};
char sub[3][10]={"English","Math","Science"};
int pos(char arr[])//function to get position of the Subject
{
int i;
for(i=0;i<3;i++)
{
if(strcmp(arr,sub[i])==0)//using string function
return i;
}
}
void details(char rollno[])//function to print details using rollnumber
{
int i;
for(i=0;i<10;i++)
{
if(strcmp(rollno,roll[i])==0)
{
printf("Marks in english is %d , Marks in math is %d , Marks in Science is %d \n",Marks[i][0],Marks[i][1],Marks[i][2]);
break;
}
}
return;
}
void less40(char subj[])//function to find details of students securing less than 40
{
int i,flag=0;
int n=pos(subj);
for(i=0;i<10;i++)
{
if(Marks[i][n]<40)
{
flag=1;
printf("Name and Roll no of student with total less than 40 in %s are %s and %s\n",sub[n],name[i],roll[i]);
}
}
if(flag==0)
{
printf("None have total less than 40 in %s\n",sub[n]);
}
return;
}
void avgg(char subject[])//function to compute average of a given subject
{
float avg;
int sum=0,i,count=0;
int k=pos(subject);
for(i=0;i<10;i++)
{
sum=sum+Marks[i][k];
}
avg=(float)sum/10;
printf("The average of %s is %.2f\n",sub[k],avg);
for(i=0;i<10;i++)
{
if(Marks[i][k]<avg)
{
count++;
}
}
printf("No of students securing less than average in %s subject is %d",sub[k],count);
return;
}
int main()
{
char rollno[10];
char subj[10];
char subject[10];
printf("Enter roll number of Students to get Marks\n");
scanf("%s",rollno);
details(rollno);
printf("\n");
printf("Enter Subject names to get details of students who got less than 40\n");
scanf("%s",subj);
less40(subj);
printf("\n");
printf("Enter Subject names to get average and no of students securing less than avg\n");
scanf("%s",subject);
avgg(subject);
return 0;
}
67 changes: 67 additions & 0 deletions AIRFARE.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Write a program that reads different city-names that the traveler is moving; starting from the source to
// distinction and compute the total cost of his travel.
// Example
// How many cities the traveler will move: 5
// Enter the cities: City1 – Kolkata
// City2 – Kanpur
// City3 – Goa
// City4 – Pune
// City5 – Delhi
// The total cost of travel is 9720
#include<stdio.h>
#include<string.h>
//int strcmp(const char* x, const char* y);
int findcityindex(char* c, char list[6][10]);
void citycopy(char *x, char *y);
int main(){
int costtable[6][6] = {
{0,3525,2850,3000,2900,1500},
{3525,0,3700,4000,3800,2500},
{2850,3700,0,1800,870,2200},
{3000,4000,1800,0,1025,2700},
{2900,3800,870,1025,0,3500},
{1500,2500,2200,2700,3500,0}
};


char citynames[6][10]={ "Delhi","Kolkata","Pune","Mumbai","Goa","Kanpur"};
char current_city[10], next_city[10];
int x,i,total=0;
printf("Enter the number of city travelled \n");
scanf("%d",&x);
printf("Enter city 1 \n");
scanf("%s",&current_city);
for(i=0;i<x-1;i++)
{
printf("Enter city %d \n",(i+2));
scanf("%s",&next_city);
int x=findcityindex(current_city,citynames);
int y=findcityindex(next_city,citynames);
total=total+costtable[x][y];
citycopy(next_city,current_city);
}
printf("Total is: %d",total);

return 0;

}


void citycopy(char *des, char *sou)//copying destination to source
{
strcpy(sou,des);
}
/*int strcmp(const char* x, const char* y){
this block is not required for execution
}
*/
int findcityindex(char* c, char list[6][10]){
int i;


for(i=0;i<6;i++)
{
if(strcmp(c,list[i])==0) return i;
}
return -1;
}
23 changes: 23 additions & 0 deletions Array_of_structures_using_fflush_keyword.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>
struct employee
{
char a;
} x[3];
int main()
{
int i;
printf("Enter 3 characters \n");
for (i = 0; i <3; i++)
{
scanf("%c", &x[i].a);
fflush(stdin);
}
printf("3 chars are \n");
for (i = 0; i < 3; i++)
{
printf("%c", x[i].a);
}

return 0;
}
65 changes: 65 additions & 0 deletions arrayunique.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <stdio.h>
int count=0;
#define MAX_SIZE 100 // Maximum array size
int a[MAX_SIZE];
void duplicate(int arr[],int size)
{
int i,j;
for(i=0; i<size; i++) // 10 20 10 20 21
{
for(j=i+1; j<size; j++)
{
/* If duplicate found then increment count by */
if(arr[i] == arr[j]&&arr[i]!=0)
{
a[count]=arr[i];
count++;
arr[i]=0;
arr[j]=0;
break;
}

}
}
printf("\nTotal number of duplicate elements found in array = %d \n", count);
printf("duplicate elements are: ");
for(int i=0;i<count;i++)
{
printf("%d, ",a[i]);
}
printf("\n");
return;
}
void unique(int arr[],int size)
{
printf("Total no of unique elements are %d\n",(size-(2*count)));
printf("The unique elements are: ");
for(int i=0;i<size;i++) //10 21 10 20 20 20 10
{
if(arr[i]!=0)
{
printf("%d, ",arr[i]);
}
}
}

int main()
{
int arr[MAX_SIZE];
int i, j, size;

/* Input size of array */
printf("Enter size of the array : ");
scanf("%d", &size);

/* Input elements in array */
printf("Enter elements in array : ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
duplicate(arr,size);
unique(arr,size);

return 0;
}
32 changes: 32 additions & 0 deletions assgn_36.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <stdio.h>
int main()
{
int x,i,t;
printf("Enter length of array\n");
scanf("%d",&x);
int arr[x];
printf("Enter elements of array\n");
for(i=0;i<x;i++)
{
printf("Enter %d th element :",i);
scanf("%d",&arr[i]);
}
printf("array elements are \n");
for(i=0;i<x;i++)
{
printf("%d",arr[i]);
}
for(i=0;i<(x/2);i++)
{
t=arr[i];
arr[i]=arr[x-i-1];
arr[x-i-1]=t;
}
printf("array elements in reverse fashion \n");
for(i=0;i<x;i++)
{
printf("%d",arr[i]);
}
return 0;
}
////////////////////////////////////////////////////
54 changes: 54 additions & 0 deletions bitwise.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
//Complete the following function.


void calculate_the_maximum(int n, int k)
{
int i,j,add=0,orr=0,xorr=0;
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i&j)<k&&add<(i&j))
{
add=i&j;
}
}
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i|j)<k&&orr<(i|j))
{
orr=i|j;
}
}
}
for(i=1;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if((i^j)<k&&xorr<(i^j))
{
xorr=i^j;
}
}
}
printf("%d\n",add);
printf("%d\n",orr);
printf("%d\n",xorr);

}

int main()
{
int n, k;

scanf("%d %d", &n, &k);
calculate_the_maximum(n, k);
return 0;
}
17 changes: 17 additions & 0 deletions freeefficiently.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
int *ptr;
int i;
ptr=(int*)malloc(1*sizeof(int));
printf("Enter the value of integers \n");
for(i=0;i<5;i++)
{
scanf("%d",&ptr[0]);
fflush(stdin);
printf("The value at %d is %d \n",i,ptr[0]);
free(ptr);
}
return 0;
}
17 changes: 17 additions & 0 deletions freeptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
int* ptr,i;
ptr=(int*)malloc(3*sizeof(int));//malloc
// for(i=0;i<10;i++)
// {
// printf("Enter value of array at %d number \n",i);
// scanf("%d",&ptr[0]);
// fflush(stdin);
// printf("%d",ptr[0]);
// free(ptr);
// }

// return 0;
// }
Loading

0 comments on commit 2332e5e

Please sign in to comment.