Posts

Showing posts with the label c language

how to create basic linklist in c++

how to create basic linklist in c++-->
code->#include<iostream> usingnamespace std; struct node{
int data; node* next; node(int data){ //constructor this->data=data; next=NULL; } }; node * creatlinklist(){ //we crate function for linklist int data; node * head=NULL; cin>>data; if(data!=-1){
head=new node(data); } else{ return head; } node* tail=NULL; tail=head; cin>>data; while(data!=-1){
node *temp=NULL; temp=new node(data); tail->next=temp; tail=temp; cin>>data; }
return head; }
void print(node* head){ //print fucntion while(head){ cout<<head->data<<"-->"; head=head->next; } return; }
int main(){ node* head=creatlinklist(); //function calling print(head); return0; }


Programming in c

Image

c language question print the series of all prime no till N

Q-1 print  the series of all prime no till N
#include <stdio.h> int main() { int prime(int); int a; scanf("%d",&a); while(a>=2) { prime(a); a--; } return 0; } int prime(int x) { int i=2; for(i=2;i<=x-1;i++) { if(x%i==0) { return 0; } } if(x==2) { printf("%d",x); return 0; } if(i==x) { printf(" %d",x); return 0; } }