Sunday 30 May 2021

Intent in Kotlin Android Studio

 Hi larnkoders in this post you are going to learn  about, How to make pass to new activity with information or simply go to new activity on android studio. This is code is written in Kotlin Programming language.

Let suppose there will be MainActivity.kt and to you want to go to AnotherActivity.kt then\

do this like 

if there is button clicklistener like

button.setOnClickListener{

val intent  = Intent(this,AnotherActivity::class.java)

startActivity(intent)

}

The main code is about simply passing to new activity from MainActivity.kt to AnotherActivity.kt

if there is any issues with above code just comment out, for further support

Good News Larnkoders, we are lauching new on Playstore

Hi larnkkoder we going to launch our new Larnkode App on Google PlayStore by the end of June, in this app you are going to get latest information about Programming Languages like Python, Java, Flutter and etc.,

This is a very sweet news to our larnkoders and it is free app with lot of features.

Thursday 24 August 2017

Calculator Program using Switch statement in C

Q.Basic Calculator Program Using C Language ?

Ans:

#include <stdio.h>
#include <conio.h>
int main() {
int n,num1,num2,total;
printf("Basic Calculator Program Using C\n\a");
printf("Enter the number 1 for Addition \n");
printf("Enter the number 2 for Subtraction \n");
printf("Enter the number 3 for Multiplication \n");
printf("Enter the number 4 for Division \n");
printf("Please Enter the Number:\n");
scanf("%d",&n);
printf("Enter the First Number:\n");
scanf("%d",&num1);
printf("Enter the Second Number:\n");
scanf("%d",&num2);
switch (n){
case 1:
total=num1+num2;
printf("%d is your value",total);
break;
case 2:
total=num1-num2;
printf("%d is your value",total);
break;
case 3:
total=num1*num2;
printf("%d is your value",total);
break;
case 4:
total=num1/num2;
printf("%d is your value",total);
break;
}

return 0;
}
Result :-

Basic Calculator Program Using 
Enter the number 1 for Addition
Enter the number 2 for Subtraction
Enter the number 3 for Multiplication
Enter the number 4 for Division
Please Enter the Number:
1
Enter the First Number:
140
Enter the Second Number:
3
143 is your value

Graphical Representation :-

Calculator Program using Switch statement in C


Tuesday 22 August 2017

String Triangle using C Language

Q. Write a program to display the string INDIA in the following fashion:

I
IN
IND
INDI
INDIA
INDIA
INDI
IND
IN
I

Ans.

/*program to display the string as given fashion*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int x,y;
 static char str[]="INDIA";
 for(x=0; x<5; x++)
 {
    y=x+1;
    printf("%-5.*s\n",y,str);
 }
 for(x=4; x>=0; x--)
 {
    y=x+1;
    printf("%-5.*s\n",y,str);
 }
 getch();
 return 0;
}

Output:-

I
IN
IND
INDI
INDIA
INDIA
INDI
IND
IN
I
Graphical Representation :-

String Triangle  using C Language

Friday 18 August 2017

Palindrome Function using C Language

Q. Write a C program to check whether a string is palindrome or not using function.

Ans.

/*Program to check whether a string is palindrome or not using function*/
#include<stdio.h>
#include<conio.h>
char string_palin(char str[]);
int main()
{
 char ch[30];
 printf("Enter string : ");
 gets(ch);
 if(string_palin(ch))
    printf("Entered string Palindrome");
 else
    printf("Entered string not Palindrome");
 return 0;
}

/*function for palindrome*/
char string_palin(char str[])
{
 int i,j;
 for(i=0; str[i]!=NULL; i++);
 for(j=0,i--; j<=i; )
 {
   if(str[i]==str[j])
   {
      i--;
      j++;
   }
  else
      break;
 }
 if(j>i)
    return(1);
 else
    return(0);
}


/*****************Output****************

Enter string : SHAREMARKET
Entered string not Palindrome

Enter string : MALAYALAM 
Entered string Palindrome
****************************************/
Graphical Representation :-

Image of Palindrome


Image of Palindrome

**If you  have any problems with above code please leave in Comment Section and check this website daily for more information and thank you.**

Thursday 17 August 2017

Bubble Sorting Explanation and Simple Program

Q. Write a program to accept 10 numbers from user and sort list using Bubble sorting method.

Ans.
Logic of bubble sorting as follows:


In bubble sorting steps:
1. Start from left hand side
2. Compare first two numbers
3. If first_number > second_number than swap both number position. And if first_number < second_number than these compare next two numbers i.e. second_number and third_number.
4. Step-3 process repeat until there are no more numbers left to compared.
5. Bubble sorting completed.

An example on bubble sort.
To understand logic of Bubble Sorting, lets take random numbers:

6  3  7  1  4  5  2

First iteration
6  3  7  1  4  5  2

3  6  7  1  4  5  2

3  6  7  1  4  5  2

3  6  1  7  4  5  2

3  6  1  4  7  5  2

3  6  1  4  5  7  2

3  6  1  4  5  2  7

Second iteration
3  6  1  4  5  2  7

3  6  1  4  5  2  7

3  1  6  4  5  2  7
3  1  4  6  5  2  7

3  1  4  5  6  2  7

3  1  4  5  2  6  7

Third iteration
3  1  4  5  2  6  7

1  3  4  5  2  6  7

1  3  4  5  2  6  7

1  3  4  5  2  6  7

1  3  4  2  5  6  7

Four iteration
1  3  4  2  5  6  7

1  3  4  2  5  6  7

1  3  4  2  5  6  7

1  3  2  4  5  6  7

Five iteration
1  3  2  4  5  6  7

1  3  2  4  5  6  7

1  2  3  4  5  6  7

Six iteration
1  2  3  4  5  6  7

1  2  3  4  5  6  7

Seven iteration
1  2  3  4  5  6  7

/*A Simple example program to Explain bubble sorting*/
#include<stdio.h>
#include<conio.h>
#define SIZE 7
int main()
{
 int i,j,temp;
 int arr[ SIZE ];
 for(i=0; i<SIZE; i++)
 {
  printf("Enter Number : ");
  scanf("%d",&arr[i]);
 }
 for(i=0; i<SIZE ; i++)
 {
   for(j=0; j<(SIZE-1)-i; j++)
   {
     if( arr[j] < arr[j+1] )
     {
        temp=arr[j];
        arr[j]=arr[j+1];
        arr[j+1]=temp;
     }
   }
   printf("%d\t",arr[j]);
 }
 getch();
 return 0;
}

Output:-
Enter number : 6
Enter number : 3
Enter number : 7
Enter number : 1
Enter number : 4
Enter number : 5
Enter number :  2
1  2  3  4  5  6  7 

Graphical Representation :-



Sunday 13 August 2017

Program for Selection Sorting

Q. Write a C program to to sort a list of elements using selection sort method.

Ans.

/*program to demonstration of selection method*/
#include<stdio.h>
#include<conio.h>
#define SIZE 10
int main()
{
 int i,j,min,temp;
 int arr[SIZE];
 for(i=0; i<SIZE; i++)
 {
  printf("Enter element : ");
  scanf("%d",&arr[i]);
 }
 for(i=0; i<SIZE; i++)
 {
   min=i;
   for(j=i+1; j<SIZE; j++)
     if(arr[j]<arr[min])
        min=j;
     temp=arr[i];
     arr[i]=arr[min];
     arr[min]=temp;
 }
 printf("After selection sort the elements:\n");
 for(i=0; i<SIZE; i++)
    printf("%d\t",arr[i]);
 getch();
 return 0;
}

Output:-

Enter element : 21
Enter element : 3
Enter element : 45
Enter element : 87
Enter element : 72
Enter element : 14
Enter element : 54
Enter element : 75
Enter element : 44
Enter element : 5

After selection sort the elements :

3  5  14  21  44  45  54  72  75  87 

Graphical Representation  :

Program for Selection Sorting

Intent in Kotlin Android Studio

 Hi larnkoders in this post you are going to learn  about, How to make pass to new activity with information or simply go to new activity on...