Welcome to Millillion Tech

Millillion Tech is not a only blog, it is a landmark of technological knowledge.

Be first in self-enrichment!

Visit our blog and enrich yourself and be all in all of your self-development.

?া?া? ?? ??্?া? ?ে?ে ?া??ে ?া?া? ?? ?্???া? ??ু?

................................................................................................................................................................................................................................

?ু?্?ী?ি ??ি?া? ??ু?, ???া?ে ?ঁ??ে ??ু?

................................................................................................................................................................................................................................

??া?ে? ?? ?ো?্? ?ে??ি?ে ???ু ?া??া?ু?

................................................................................................................................................................................................................................

Translate

Wednesday, May 27, 2015

C Programming, using linked list creating multi nodes



#include<stdio.h>
#include<conio.h>

struct test_struct
{
    int val;
    struct test_struct *next;
};
struct test_struct *head=NULL;
struct test_struct *curr=NULL;

struct test_struct* create_list(int val)
{
    struct test_struct *ptr=(struct test_struct*) malloc(sizeof(struct test_struct));
    if(ptr==NULL)
    {
        printf("Node creating failed\n");
        return;
    }
    ptr->val=val;
    ptr->next=NULL;
    head=curr=ptr;
    return ptr;

}

struct test_struct* add_to_list(int val)
{
    if(head==NULL)
    {
        return(create_list(val));
    }
    struct test_struct *ptr=( struct test_struct*) malloc(sizeof(struct test_struct));
    if(ptr==NULL)
    {
        printf("node creation failed");
        return;
    }
    ptr->val=val;
    ptr->next=NULL;
    curr->next=ptr;
    curr=ptr;
    return ptr;
}
void print_list()
{
    struct test_struct *ptr=head;
    while(ptr->next !=NULL){
    printf("%d->", ptr->val);
    ptr=ptr->next;
    }

    if(ptr->next==NULL)
        printf("%d",ptr->val);
}

int main()
{
    int val,i,n;

    printf("How many node you want to create? ");
    scanf("%d", &n);

    for(i=0;i<n;i++){
    scanf("%d", &val);
    add_to_list(val);
    }

    print_list();
    return 0;
}


Output:


Download source code

C programming, using linked list creating a node






#include<stdio.h>
#include<conio.h>

struct test_struct
{
    int val;
    struct test_struct *next;
};
struct test_struct *head=NULL;
struct test_struct *curr=NULL;

struct test_struct* create_list(int val)
{
    struct test_struct *ptr=(struct test_struct*) malloc(sizeof(struct test_struct));
    if(ptr==NULL)
    {
        printf("Node creating failed\n");
        return;
    }
    ptr->val=val;
    ptr->next=NULL;
    head=curr=ptr;
    return ptr;

}

struct test_struct* add_to_list(int val)
{
    if(head==NULL)
    {
        return(create_list(val));
    }
    struct test_struct *ptr=( struct test_struct*) malloc(sizeof(struct test_struct));
    if(ptr==NULL)
    {
        printf("node creation failed");
        return;
    }
    ptr->val=val;
    ptr->next=NULL;
    curr->next=ptr;
    curr=ptr;
    return ptr;
}

int main()
{
    struct test_struct *a;
    int val;

    scanf("%d", &val);
    a=add_to_list(val);

    while (a->next != NULL){

        printf("%d", a->val);
        a->next = a->next->next;
    }

        printf("%d", a->val);
        return 0;


}

Download source code

Monday, May 25, 2015

Using structure, input some students' Name, Id and CGPA and sort them by Name, Id and CGPA respectively.




#include<stdio.h>
#include<string.h>
#define SIZE 5

struct diu_cse
{
    char name[20];
    int id;
    float cgpa;
};

struct diu_cse student[SIZE];

void input(struct diu_cse student[])
{
    int i;
    printf("***********Input************\n");
    for(i=0;i<SIZE;i++){
        scanf("%s%d%f", student[i].name, &student[i].id, &student[i].cgpa);
    }
}

void output(struct diu_cse student[])
{
    int i;
    for(i=0;i<SIZE;i++){
        printf("%10s    %5d    %.2f\n", student[i].name, student[i].id, student[i].cgpa);

    }
}

void sort_name_student(struct diu_cse student[])
{
    int i,j;
    for(i=0;i<SIZE-1;i++){
        for(j=i+1;j<SIZE;j++){
            if(strcmp(student[i].name , student[j].name)>0){
                struct diu_cse temp;

                strcpy(temp.name , student[i].name);
                temp.id = student[i].id;
                temp.cgpa = student[i].cgpa;

                strcpy(student[i].name , student[j].name);
                student[i].id = student[j].id;
                student[i].cgpa = student[j].cgpa;

                strcpy(student[j].name , temp.name);
                student[j].id = temp.id;
                student[j].cgpa = temp.cgpa;
            }
        }
    }
}

void sort_cgpa_student(struct diu_cse student[])
{
    int i,j;
    for(i=0;i<SIZE-1;i++){
        for(j=i+1;j<SIZE;j++){
            if(student[i].cgpa < student[j].cgpa){
                struct diu_cse temp;

                strcpy(temp.name , student[i].name);
                temp.id = student[i].id;
                temp.cgpa = student[i].cgpa;

                strcpy(student[i].name , student[j].name);
                student[i].id = student[j].id;
                student[i].cgpa = student[j].cgpa;

                strcpy(student[j].name , temp.name);
                student[j].id = temp.id;
                student[j].cgpa = temp.cgpa;
            }
        }
    }
}

void sort_id_student(struct diu_cse student[])
{
    int i,j;
    for(i=0;i<SIZE-1;i++){
        for(j=i+1;j<SIZE;j++){
            if(student[i].id > student[j].id){
                struct diu_cse temp;

                strcpy(temp.name , student[i].name);
                temp.id = student[i].id;
                temp.cgpa = student[i].cgpa;

                strcpy(student[i].name , student[j].name);
                student[i].id = student[j].id;
                student[i].cgpa = student[j].cgpa;

                strcpy(student[j].name , temp.name);
                student[j].id = temp.id;
                student[j].cgpa = temp.cgpa;
            }
        }
    }
}

int main()
{
    input(student);

    sort_name_student(student);
    printf("*********** Sort By Name ************\n");
    output(student);

    sort_id_student(student);
    printf("*********** Sort By Id ************\n");
    output(student);

    sort_cgpa_student(student);
    printf("*********** Sort By CGPA ************\n");
    output(student);

}

Output:


Download source code

Friday, May 22, 2015

Using C, Input a string and check that it is palindrome or not.

#include <stdio.h>
#include <string.h>

void main()
{

    char str[25], rev_str[25] = {'\0'};

    int i, len = 0, flag = 0;

    printf("Enter a string: ");

    gets(str);

    for (i = 0; str[i] != '\0'; i++){
        len++;
    }

    for (i = len - 1; i >= 0 ; i--){
        rev_str[len - i - 1] = str[i];
    }

    for (flag = 1, i = 0; i < len ; i++){
        if (rev_str[i] != str[i])
            flag = 0;
    }

    if (flag == 1)
       printf ("%s is a palindrome \n", str);

    else
       printf("%s is not a palindrome \n", str);

}


Download source code

C programming code for Prime number.


#include<stdio.h>

int main()
{
   int n, i = 3, count, c;

   printf("Enter the number of prime numbers required\n");
   scanf("%d",&n);

   if ( n >= 1 )
   {
      printf("First %d prime numbers are :\n",n);
      printf("2\n");
   }

   for ( count = 2 ; count <= n ;  )
   {
      for ( c = 2 ; c <= i - 1 ; c++ )
      {
         if ( i%c == 0 )
            break;
      }
      if ( c == i )
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }

   return 0;
}


Download source code

Wednesday, May 20, 2015

C programming code for Fibonacci Series

#include<stdio.h>

int main()
{
   int n, first = 0, second = 1, next, c;

   printf("Enter the number of terms\n");
   scanf("%d",&n);

   printf("First %d terms of Fibonacci series are :-\n",n);

   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }

   return 0;
}


Download Source code

C Programming Buble Sorting

#include<stdio.h>
#include<conio.h>

int main( )
{
     int a[100];
     int i, j, temp, n ;
     printf("How many numbers you want to sort : \n");
     scanf("%d",&n);
     printf("Enter %d numbers\n", n);
     for(j=0; j<n; j++)
     scanf("%d",&a[j]);

     for(j=0;j<n-1;j++)
     {
          for(i=0; i<n; i++)
          {
               if(a[i]>a[i+1])
               {
                     temp=a[i];
                     a[i]=a[i+1];
                     a[i+1]=temp;
               }
          }
     }

     printf ( "\n\nSorted:\n") ;

     for ( i = 0 ; i <n ; i++ )
     printf ( "%d\t", a[i] ) ;
     getch();
 }

একটি C Programming Code লিখ যা একটি Array তে ৫টি Integer ইনপুট নিবে। এখন ওগুলোর Average, Maximum, Minimum বের কর, Reverse Order এ সাজাও এবং ছোট থেকে বড় ক্রমে Sort কর।

#include<stdio.h>
#define SIZE 5

void main()
{
    int arr[SIZE], max=0, min=arr[0], i, j, k, l, temp=0;
    float avrg, sum=0;

    printf("Enter 5 integers: ");
    for(i=0;i<5;i++){
        scanf("%d", &arr[i]);
        sum = sum+arr[i];
        if(arr[i]>max)
            max=arr[i];

        if(arr[i]<min)
            min=arr[i];
    }

    avrg=sum/5;

    printf("Sum of 5 integers = %.2f\n", sum);
    printf("Average of 5 integers = %.2f\n", avrg);
    printf("Maximum: %d\n", max);
    printf("Minimum: %d\n", min);

    printf("Reverse of 5 integers: ");
    for(j=SIZE-1;j>=0;j--){
        printf("%d ", arr[j]);
    }

    printf("\n");

    for(l=0;l<SIZE;l++){
        for(k=0;k<SIZE-1;k++){
            if(arr[k]>arr[k+1]){
                temp=arr[k];
                arr[k]=arr[k+1];
                arr[k+1]=temp;
            }
        }
    }

    printf("Sorted: ");
    for(k=0;k<SIZE;k++){
        printf("%d ", arr[k]);
    }
}



Source code download here






shohag