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, June 24, 2015

Using linked list, write a C program, that will input some students' Id, Name, Department and CGPA respectively and print them.

millillion tech


#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define SIZE 20


struct diu_cse
{
    int id;
    char name[SIZE];
    char department[SIZE];
    float cgpa;
    struct diu_cse *next;
};
struct diu_cse *head=NULL;
struct diu_cse *curr=NULL;

struct diu_cse* create_list(int id, char name[],char department[], float cgpa)
{
    struct diu_cse *ptr=(struct diu_cse*) malloc(sizeof(struct diu_cse));
    if(ptr==NULL)
    {
        printf("Node creation failed\n");
        return;
    }
    ptr->id = id;
    strcpy(ptr->name, name);
    strcpy(ptr->department, department);
    ptr->cgpa = cgpa;
    ptr->next=NULL;
    head=curr=ptr;
    return ptr;

}

struct diu_cse* add_to_list(int id, char name[], char department[], float cgpa)
{
    if(head==NULL)
    {
        return(create_list(id, name, department, cgpa));
    }
    struct diu_cse *ptr=( struct diu_cse*) malloc(sizeof(struct diu_cse));
    if(ptr==NULL)
    {
        printf("Node creation failed");
        return;
    }
    ptr->id = id;
    strcpy(ptr->name, name);
    strcpy(ptr->department, department);
    ptr->cgpa = cgpa;
    ptr->next=NULL;
    curr->next=ptr;
    curr=ptr;
    return ptr;
}
void print_list()
{
    struct diu_cse *ptr=head;
    while(ptr->next != NULL){
    printf("--------------------Printing List--------------------\n\n");
    printf(" %d  %s  %s  %.2f -> ", ptr->id, ptr->name, ptr->department, ptr->cgpa);
    ptr=ptr->next;
    }

    if(ptr->next == NULL)
        printf(" %d  %s  %s  %.2f ", ptr->id, ptr->name, ptr->department, ptr->cgpa);
        printf("\n\n");
}

int main()
{
    int id,i,n;
    char name[SIZE], department[SIZE];
    float cgpa;

    printf("How many node you want to create? ");
    scanf("%d", &n);
    printf("\nEnter the Id, Name, Department and CGPA of students\n");

    for(i=0;i<n;i++){
    scanf("%d", &id);
    fflush(stdin);
    gets(name);
    gets(department);
    scanf("%f", &cgpa);
    add_to_list(id, name, department, cgpa);
    }

    print_list();
    return 0;
}


millilliontech

Download source file

Thursday, June 11, 2015

Queues implementation( add, remove, peek) in C programming

millilliontech



#include <stdio.h>
#define MAX 50


int queue_array[MAX];
int rear = -1;
int front = -1;
void main()
{
    int choice;
    while (1)
    {
        printf("1.Insert element to queue \n");
        printf("2.Delete element from queue \n");
        printf("3.Display all elements of queue \n");
        printf("4.Quit \n");
        printf("Enter your choice : ");
        scanf("%d", &choice);
        switch (choice) {
        case 1:
            insert();
            break;
        case 2:
            delete();
            break;
        case 3:
            display();
            break;
        case 4:
            exit(1);
        default:
            printf("Wrong choice \n");
        } /*End of switch*/
    } /*End of while*/
} /*End of*/

insert()
{
    int add_item;
    if (rear == MAX -1)
        printf("Queue Overflow \n");
    else {
        if (front == -1) /*If queue is initially empty */
            front = 0;
            printf("Inset the element in queue : ");
            scanf("%d", &add_item);
            rear = rear + 1;
            queue_array[rear] = add_item;
        }
}

void delete()
{
    if (front == -1 || front > rear)
    {
        printf("Queue Underflow \n");
        return ;
    }
    else {
        printf("Element deleted from queue is : %d\n", queue_array[front]);
        front = front + 1;
        }
}

display()
{
    int i;
    if (front == -1)
        printf("Queue is empty \n");
    else {
        printf("Queue is : \n");
        for (i= front; i<= rear; i++)
            printf("%d ", queue_array[i]);
            printf("\n");
        }
}

millilliontech


Download source code

Sunday, June 7, 2015

Stack implementation( Push, Pop, Display) in C programming.

millilliontech



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5

struct stack {
    int s[size];
    int top;
    } st;

int stfull()
{
    if (st.top>= size -1)
        return 1;
    else
        return 0;
}
push(int item)
{
    st.top++;
    st.s[st.top] = item;
}
int stempty()
{
    if (st.top== -1)
    return 1;
    else
    return 0;
}
int pop()
{
    int item;
    item = st.s[st.top];
    st.top--;
    return (item);
}

display()
{
    int i;
    if (stempty())
    printf("\nStack Is Empty!");
    else {
    for (i= st.top; i>= 0; i--)
    printf("\n%d", st.s[i]);
    }
}
int main()
{
    int item, choice;
    char ans;
    st.top= -1;

    printf("\n\tImplementation Of Stack\n");
    do {
        printf("\nMain Menu");
        printf("\n1.Push \n2.Pop \n3.Display \n4.exit");
        printf("\nEnter Your Choice ");
        scanf("%d", &choice);
    switch (choice) {
    case 1:
        printf("\nEnter The item to be pushed   ");
        scanf("%d", &item);
        if (stfull())
            printf("\nStack is Full!");
        else
            push(item);
        break;

    case 2:
        if (stempty())
            printf("\nEmpty stack! Underflow!!");
        else {
            item = pop();
            printf("\nThe popped element is %d", item);
        }
        break;

    case 3:
        display();
        break;
    case 4:
        exit(0);
    }
    printf("\nDo You want To Continue?  ");
    ans= getche();
    }
    while (ans == 'Y' || ans == 'y');
    return 0;
}

Output:
millilliontech

Download source code

Thursday, June 4, 2015

C Programming- linked list, creating nodes, inserting "after", inserting "before", searching(Traversing) and deletion



#include<stdio.h>
#include<stdlib.h>
#include<stdbool.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)
{
    printf("\nCreating list with headnode as %d\n",val);
    struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
    if(NULL == ptr){
        printf("\n Node creation failed \n");
        return NULL;
    }
    ptr->val = val;
    ptr->next = NULL;

    head = curr = ptr;
    return ptr;
}

struct test_struct* add_to_list(int val, bool add_to_list_first)
{
    if(NULL == head)
        return (create_list(val));

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

    if(add_to_list_first){
        ptr->next = head;
        head = ptr;
    }
    else{
        curr->next = ptr;
        curr = ptr;
    }
    return ptr;
}

struct test_struct* search_in_list(int val, struct test_struct **prev)
{
    struct test_struct *ptr = head;
    struct test_struct *tmp = NULL;
    bool found = false;

    while(ptr != NULL){
        if(ptr->val == val){
            found = true;
            break;
        }
        else{
            tmp = ptr;
            ptr = ptr->next;
        }
    }

    if(true == found){
        if(prev)
            *prev = tmp;
        return ptr;
    }
    else
        return NULL;
}

int delete_from_list(int val)
{
    struct test_struct *prev = NULL;
    struct test_struct *del = NULL;

    del = search_in_list(val, &prev);

    if(del == NULL)
        return -1;

    else{
        if(prev != NULL)
            prev->next = del->next;

        else if(del == head)
            head = del->next;
    }

    free(del);
    del = NULL;

    return 0;
}

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);

    return;
}

int main()
{
    int ret = 0, n, n_first, i, i_first, key_ser, key_del;
    struct test_struct *ptr = NULL;

    printf("\nHow many values you want to add to the list?:  ");
    scanf("%d", &n);
    int count[n];
    for(i=0 ; i<n ; i++){
        scanf("%d", &count[n]);
        add_to_list(count[n], false);
    }
    printf("\n\n********* Creating nodes with %d values *********\n\n", n);
    print_list();

    printf("\n\nHow many values you want to add to the list from first?:  ");
    scanf("%d", &n_first);
    int count_first[n_first];
    for(i_first=0 ; i_first<n_first ; i_first++){
        scanf("%d", &count_first[n_first]);
        add_to_list(count_first[n_first], true);
    }
    printf("\n\n********* Adding %d values from first *********\n\n", n_first

);
    print_list();

    printf("\n\nEnter the value you want to search:  ");
    scanf("%d", &key_ser);

    ptr = search_in_list(key_ser, NULL);
    if(NULL == ptr)
        printf("\n\nSearching failed, %d is not found in the list\n\n",key_ser);

    else{
        printf("\n\n%d is found in the list\n\n", key_ser);
        printf("\n\n***************** The list *******************\n\n");
    }
    print_list();

    printf("\n\nEnter the value you want to delete:  ");
    scanf("%d", &key_del);

    ret = delete_from_list(key_del);
    if(ret != 0){
        printf("\n\nDeleting failed, %d is not found in the list\n\n",key_del);
        printf("\n\n****************** The list ********************\n\n");
    }
    else{
        printf("\n\n%d is deleted \n\n",key_del);
        printf("\n\n************** After deleting %d ***************\n\n", key_del);
    }

    print_list();

    getch();
    return 0;

}








Download source code

C programming code for leap year.



#include<stdio.h>

void main()
{
    int year;

    printf("Enter a year:  ");
    scanf("%d", &year);

    if((year%4 == 0) && (year%100 != 0) ||(year%400 == 0))
        printf("%d is a leap year", year);

    else
        printf("%d is not a leap year", year);

    return 0;
}

Download source code

Write a C program that will input some students' obtained marks and count the number of A+, A, A-, B+.....



#include<stdio.h>

int main()
{
    int n;
    printf("Number of students: ");
    scanf("%d", &n);


    int arr[n],i,j, check=0;
    printf("Enter obtained marks of the students: ");
    for(i=0;i<n; i++){
        scanf("%d",&arr[i]);
    }

    for(i=0;i<n; i++){
        if(arr[i]>=80 && arr[i]<=100)
        check++;
    }
    printf("Number of A+ = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=75 && arr[i]<80)
        check++;
    }
    printf("Number of A  = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=70 && arr[i]<75)
        check++;
    }
    printf("Number of A- = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=65 && arr[i]<70)
        check++;
    }
    printf("Number of B+ = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=60 && arr[i]<65)
        check++;
    }
    printf("Number of B  = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=55 && arr[i]<60)
        check++;
    }
    printf("Number of B- = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=50 && arr[i]<55)
        check++;
    }
    printf("Number of C+ = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=45 && arr[i]<50)
        check++;
    }
    printf("Number of C  = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]>=40 && arr[i]<45)
        check++;
    }
    printf("Number of D  = %d \n",check);

    check=0;

    for(i=0;i<n; i++){
        if(arr[i]<40)
        check++;
    }
    printf("Number of F  = %d \n",check);


}


Download source code

Write a C program that will convert temperature from celcius to fahrenheit and fahrenheit to celcius. Input values from user.



#include<stdio.h>
#include<math.h>
void main()

{
    char user;
    float clcs, farn, celcius, fahrenheit;

    printf("For celsius to fahrenheit press 'a' ");
    printf("\nFor fahrenheit to celsius press 'b' \n");

    scanf("%c", &user);


    switch(user){
        case 'a':
        {
            printf("\nEnter temperature in celcius: ");
            scanf("%f", &clcs);

            fahrenheit=clcs*1.8+32;
            printf("Temperature in fahrenheit: %.2f", fahrenheit);
            break;

        }


        case 'b':
        {
            printf("\nEnter temperature in fahrenheit: ");
            scanf("%f", &farn);

            celcius=(farn-32)/1.8;
            printf("Temperature in celcius: %.2f\n", celcius);
            break;

        }


        default:
            break;

        }

}


Download source code

Write a C program that calculate the average of three integers. Input the values from user.



#include<stdio.h>

void main()

{
    float a,b,c,avrg;

    printf("A?  ");
    scanf("%f", &a);
    printf("B?  ");
    scanf("%f", &b);
    printf("C?  ");
    scanf("%f", &c);

    avrg= (a+b+c)/3;

    printf("%f", avrg);

}


Download source code

Write a C programm that will calculate the area of triangle, rectangle and circle. Input the choice and values from user.



#include<stdio.h>

void main()
{
    char user;
    float area,l,b,h,w,r,pi=3.1416;

    printf("To calculate the area of\n\nA triangle press 'a'\nA rectangle press 'b'\nA circle press 'c'\n\nInput here:");
    scanf("%c", &user);

    switch(user){

        case 'a':{
            printf("Base: ");
            scanf("%f", &b);
            printf("Height: ");
            scanf("%f", &h);

            area=0.5*b*h;
            printf("Area of the triangle is %.2f square unit", area);
            break;
        }

        case 'b':{
            printf("Length: ");
            scanf("%f", &l);
            printf("Width: ");
            scanf("%f", &w);

            area=l*w;
            printf("Area of the rectangle is %.2f square unit", area);
            break;
        }

        case 'c':{
            printf("Radius: ");
            scanf("%f", &r);

            area=pi*r*r;
            printf("Area of the circle is %.2f square unit", area);
            break;
        }

        default:
            break;

    }
}

Download source code

Write a C program thar will enter a line of text, store in an array and then display it backwards.



#include<stdio.h>

void main()
{
    char line[80];
    int i, l=0;

    printf("Write a line: \n ");

    gets(line);

    l= strlen(line);

    for(i=l;i>=0; --i){
        printf("%c", line[i]);
    }
}



Download source code