Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views12 pages

C

Uploaded by

Kukum Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

C

Uploaded by

Kukum Chouhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1)WAP for arr.

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[50],n;
printf("Enter the array size= \n");
scanf("%d",&n);
printf("Enter the element= \n");
for (int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
return 0;
}
2)Add two arryas.
#include<stdio.h>
#include<conio.h>
int main()
{
int a[50],b[50],c[50],n,i,j,k;
printf("Enter the size of array= \n");
scanf("%d",&n);
printf("Enter the element for array a= \n");
for (int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element for array b= \n");
for (int i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("sum of two array c= \n");
for(int i=0;i<n;i++)
{
c[i]=a[i]+b[i];
}
for(int i=0;i<n;i++)
{
printf("%d",c[i]);
}
}
3)String.
#include<stdio.h>
#include<string.h>
int main()
{
int i;
char n[50];
printf("enter the string=\n");
scanf("%s",&n);
int x = strlen(n);
printf("%d\n",x);

for(i=0;i<=x;i++)
{
printf("%c\n",n[i]);
}
return 0;
}
4)Factorial.
#include<stdio.h>
int main()
{
int i,a=1,n;
printf("Enter a no.= \n");
scanf ("%d",&n);

for (int i=n;i>0;i--)


{
a=a*i;
}

printf("Factorial is: %d",a);


return 0;
}
5)Fibonaci.
#include<stdio.h>
#include<conio.h>
int main()
{
int n1=0,n2=1,n3,i,n;

printf("Enter a no. of element= \n");

scanf ("%d",&n);
printf("%d %d", n1,n2);

for (int i=2;i<n;i++)


{
n3=n1+n2;
printf("%d",n3);
n1=n2;
n2=n3;
}
return 0;
}
6)Prime.
7)Palindrom.
#include<stdio.h>
#include<conio.h>
int main()
{
char str[50];
int i,length,n;
printf("Enter a string = \n");
scanf ("%s",str);
for (i=0;i<lenght;i++)
{
if (str[i]!= str[length-i-1])
break;
}
if (n=0)
{
print ("string is a palindrom")
}
else{
print ("string is not a palindrom")

}
return 0;
}

8) WAP to merge elements of two arrays.


#include <stdio.h>
int main()
{
int n1,n2,n3;
int a[100], b[100], c[100];
printf("Enter the size of first array: ");
scanf("%d",&n1);
printf("Enter the array elements: ");
for(int i = 0; i < n1; i++)
scanf("%d", &a[i]);
printf("Enter the size of second array: ");
scanf("%d",&n2);
printf("Enter the array elements: ");
for(int i = 0; i < n2; i++)
scanf("%d", &b[i]);
n3 = n1 + n2;
for(int i = 0; i < n1; i++)
c[i] = a[i];
for(int i = 0; i < n2; i++)
c[i + n1] = b[i];
printf("The merged array: ");
for(int i = 0; i < n3; i++)
printf("%d ", c[i]);
return 0;
}

9) #include<stdio.h>
void main(){
int arr1[100],arr2[100],merge[100],l,n,m,low,high,temp;
printf("Enter the no. of elements in array 1: ");
scanf("%d",&l);
printf("Enter the elements: ");
for(int i=0;i<l;i++){
scanf("%d",&arr1[i]);
}
printf("Enter the no. of elements in array 2: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(int i=0;i<n;i++){
scanf("%d",&arr2[i]);
}
low=0,high=n-1;
while(low<high){
temp=arr2[low];
arr2[low]=arr2[high];
arr2[high]=temp;
low++;
high--;
}
for(int i=l;i<(l+n);i++){
arr1[i]=arr2[i-l];
}
for(int i=0;i<(l+n);i++){
printf("%d ",arr1[i]);
}
}

10) #include<stdio.h>

int sum(int arr[],int n){


int s=0;
for(int i=0;i<n;i++){
s+=arr[i];
}
return s;
}
int main(){
int arr[100],n,add;
printf("Enter the no. of elements: ");
scanf("%d",&n);
printf("Enter the elements: ");
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
add=sum(arr,n);
printf("Sum of array is: %d",add);
}
3. write a program to implement linear search using linked list.

#include <stdio.h>

#include <stdlib.h>

struct node

int num;

struct node *nextptr;

stnode, *ennode;

int FindElement(int);

void main()

int n,i,FindElem,FindPlc;

stnode.nextptr=NULL;

ennode=&stnode;

printf(" enter number of nodes in linked list : ");

scanf("%d", &n);

printf("\n");

for(i=0;i< n;i++)

ennode->nextptr=(struct node *)malloc(sizeof(struct node));

printf(" enter elements: %d : ",i+1);

scanf("%d",&ennode->num);

ennode=ennode->nextptr;

ennode->nextptr=NULL;

printf("\n elements entered are:\n");

ennode=&stnode;
while(ennode->nextptr!=NULL)

printf(" elements = %d\n",ennode->num);

ennode=ennode->nextptr;

printf("\n");

printf(" Input number to be searched : ");

scanf("%d",&FindElem);

FindPlc=FindElement(FindElem);

if(FindPlc<=n)

printf("found at node %d \n\n",FindPlc);

else

printf("does not exists in linked list.\n\n");

int FindElement(int FindElem)

int ctr=1;

ennode=&stnode;

while(ennode->nextptr!=NULL)

if(ennode->num==FindElem)

break;

else

ctr++;

ennode=ennode->nextptr;

return ctr;

You might also like