Skip to main content

Posts

Code Chef snackdown qualifier 1-B Solution

1.Problem:  SNCKYEAR Solution list = [2010,2015,2016,2017,2019] T = int(input()) list_2 = [] for i in range(0,T):     list_2.append(int(input())) for item in list_2:     if item in list:         print("HOSTED")     else:         print("NOT HOSTED") This Code is written in python 3.6      2.Problem:  CHFAR  Solution T = int(input()) result =[] while(T>0):     data_input = input()     list_1=list(data_input.split())     list_1 = [int(i) for i in list_1]     K = list_1[1]     data_input_2 = input()     list_2 = list(data_input_2.split())     list_2 = [int(i) for i in list_2]     count = 0     for item in list_2:         if item!=1:             count = count+1     if count...
Recent posts

Write a program in C to do Vertical Merging of 2 square matrix.

Let's Begin Basic requirement to understand this program: 1. Matrix 2. Nested looping Code:------- #include<stdio.h> main() { int a[3][3],b[3][3]; int i,j,d[3][6]; printf("enter the elements of 1st matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" element [%d][%d]: ",i+1,j+1); scanf("%d",&a[i][j]); } } printf("enter the elements of 2nd matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf(" element [%d][%d]: ",i+1,j+1); scanf("%d",&b[i][j]); } } int k,l; for(k=0;k<3;k++) { for(l=0;l<3;l++) { for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(a[k][l]==b[i][j]) { b[i][j]=0; } } } } } printf("vertical merge \n"); for(i=0;i<3;i++) {for(j=0;j<3;j++) { d[i][j]=a[i][j]; } } for(i=0;i<3;i++) {for(j=3;j<6;j++) { d[i][j]=b[i][j-3]; } }...

Use Of Call By Reference in C Programming

Function: Types: 1. Call By Value 2. Call By Reference Basic Requirement to learn this code: 1.Function 2.Use of pointer in function 3.Swapping of two number Example:1: (Call By Reference) #include<stdio.h> void swap(int*, int*); main() { int a,b; a=5;b=10; swap(&a,&b); printf("after swapping a=%d,b=%d",a,b); } void swap(int *x,int *y) { int t; t=*x; *x=*y; *y=t; } Note: All Codes are written in DEV-C++.

Use of Switch in C Programming

NOTE: All Codes are written and tested in DEV C++ Switch: Basic Requirement to learn this code: 1.Switch Case Example:1: #include<stdio.h> main() { int choice; printf("input ur choice man \n1.Add\n2.Display Count Upto \n3.Today Qoutes\n"); scanf("%d",&choice); switch(choice) { case 1: int a,b,sum; printf("\nenter two no. to add:"); scanf("%d%d",&a,&b); sum=a+b; printf("sum=%d",sum); break; case 2: int i,n; printf("\nenter a number upto which u want to print the numbers from one"); scanf("%d",&n); for(i=1;i<=n;i++) printf("\n%3d",i); break; case 3: printf("\nHonesty is the best policy\n HAVE a good day Sir!!!"); break; default: printf("Invalid Input"); }}

Write a program in C to find first and second largest Number from the inputted 1-D Array!

NOTE: Code was written in DEV C++ Basic requirement to learn this code 1.Array 2.Swap #include<stdio.h> main() { int i,n,fbig,sbig; printf("\nenter the length of array"); scanf("%d",&n); int a[n]; printf("input %d elements of array",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } fbig=a[0]; sbig=a[1]; int temp; if(sbig > fbig) { temp=fbig; fbig=sbig; sbig=temp; } for(i=2;i<n;i++) { if(a[i]>fbig && a[i]>sbig) { sbig=fbig; fbig=a[i]; } else if(fbig>a[i] && a[i]>sbig) sbig=a[i]; } printf("Here your 1st greatest no is %d and secondary greatest no. is %d",fbig,sbig); }