Sie sind auf Seite 1von 3

Prime Program:

#include<stdio.h>
void main()
{
int count=0,a;
printf("Enter Number\n");
scanf("%d",&a);
for(int i=1;i<=10;i++)
{
if(i==1||i==a)
{
}
else if(a%i==0)
{
count++;
}
else
{}
}
if(count>=1)
printf("Not a Prime\n");
else
printf("Prime\n");
}
Output:
dinesh@dinesh-HP-15-Notebook-PC:~/C Pgms$ ./a.out
Enter Number
5
Prime

Linked List:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};

void printlist(struct node *n)


{
while(n!=NULL)
{
printf("%d\n",n->data);
n=n->next;
}
}
void main()
{
struct node *first=NULL;
struct node *second=NULL;
struct node *third=NULL;
first=(struct node *)malloc(sizeof(struct node));
second=(struct node *)malloc(sizeof(struct node));
third=(struct node *)malloc(sizeof(struct node));
first->data=1;
first->next=second;
second->data=2;
second->next=third;
third->data=3;
third->next=NULL;
printlist(first);
}
Output:
dinesh@dinesh-HP-15-Notebook-PC:~/C Pgms$ ./a.out
1
2
3

Linked List – ADD:


include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
void push(struct node** head_ref, int new_data)
{
/* 1. allocate node */
struct node* new_node = (struct node*) malloc(sizeof(struct node));

/* 2. put in the data */

new_node->data = new_data;

/* 3. Make next of new node as head */


new_node->next = (*head_ref);

/* 4. move the head to point to the new node */


(*head_ref) = new_node;
}
void printlist(struct node *n)
{
while(n!=NULL&&n->data!=0)
{
printf("%d\n",n->data);
n=n->next;
}
}
void main()
{
struct node *head=NULL;
head=(struct node *)malloc(sizeof(struct node));
push(&head,10);
push(&head,20);
push(&head,30);
printlist(head);
}
Output:
dinesh@dinesh-HP-15-Notebook-PC:~/C Pgms$ ./a.out
30
20
10

Das könnte Ihnen auch gefallen