0% found this document useful (0 votes)
55 views

1 Fibonacci

The document contains 9 C program code examples demonstrating different programming concepts: 1. A Fibonacci series program 2. Array sorting and printing functions 3. String concatenation 4. Palindrome checking 5. Matrix determinant calculation 6. Array of pointers 7. Printing numbers as words using arrays 8. Calculating series values using functions 9. Swapping two variables using pointers
Copyright
© Attribution Non-Commercial (BY-NC)
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)
55 views

1 Fibonacci

The document contains 9 C program code examples demonstrating different programming concepts: 1. A Fibonacci series program 2. Array sorting and printing functions 3. String concatenation 4. Palindrome checking 5. Matrix determinant calculation 6. Array of pointers 7. Printing numbers as words using arrays 8. Calculating series values using functions 9. Swapping two variables using pointers
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 19

1.

FIBONACCI
#include<stdio.h>
#include<conio.h>
int fib(int);
void main()
{
int a,i;
clrscr();
printf("enterthe limit\n");
scanf("%d%",&a);
printf("\nfibonacci series is =\n");
for(i=1;i<=a;i++)
printf("%d",fib(i));
getch();
}

int fib(int a)
{
if (a==1)
return(0);
else if(a<3)
return(1);
else
return(fib(a-1)+fib(a-2));

2.MATRIX MULTIPLICATION
#include<stdio.h>
#include<conio.h>

void read(int n,int a[])


{

int i;
printf("enter the elements of the array\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}

void print(int n,int a[])


{
int j;
printf("\nsorted array\n");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
getch();
}

void sort(int n,int a[])


{

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

void main()
{
int a[40],n;
clrscr();
printf("enter the number elements to be entered\n");
scanf("%d",&n);
read(n,a);
sort(n,a);
print(n,a);
}

3.CONCATENATION
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>

void main()
{
int i,j,len1,len2;
char a[40],b[10];
clrscr();
printf("enter the string1(max.20 char.)\n");
scanf("%s",&a);
printf("enter the string2(max.10 char.)\n");
scanf("%s",&b);
len1=strlen(a);
len2=strlen(b);
for(i=len1,j=0;(i<len1+len2)&&(j<len2);i++,j++)
{
a[i]=b[j];
}
printf("concatinated string is\n");
for(i=0;i<len1+len2;i++)
printf("%c",a[i]);
getch();
}

4.PALINDROME
#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{char a[20],b[20];clrscr();
printf("enter the string");
scanf("%s",&a);

strcpy(b,a);
strrev(b);
if (strcmp(a,b)==0)
printf("\n %s is a pallindrome",a);
else printf("\n %s is not a pallindrome",a);
getch();
return 0;
}

5.DETERMINANT OF A MATRIX
#include<stdio.h>
#include<conio.h>

void main()
{
int a[3][3],det=0,i,j;
clrscr();
printf("enter the elementsof 3 X 3 matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
det=a[0][0]*(a[1][1]*a[2][2]-a[2][1]*a[1][2])-a[0][1]*(a[1][0]*a[2][2]a[2][0]*a[1][2])+a[0][2]*(a[1][0]*a[2][1]-a[2][0]*a[1][1]);
printf("determinent=%d",det);
getch();

6.ARRAY OF POINTERS
#include<stdio.h>
#include<conio.h>

void read(int n,int a[])


{
int i;
printf("enter the elements of the array\n");
for(i=0;i<n;i++)
{

scanf("%d",&a[i]);
}
}

void print(int n,int a[])


{
int j;
printf("\nsorted array\n");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
getch();
}

void sort(int n,int a[])


{
int temp,i,j;
for(i=0;i<n;i++)
{
for(j=0;j<(n-1);j++)

{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}

void main()
{
int a[40],n;
clrscr();
printf("enter the number elements to be entered\n");
scanf("%d",&n);
read(n,a);
sort(n,a);
print(n,a);
}

7. PRINT NUMBER IN WORDS USING ARRAY


#include<stdio.h>
#include<conio.h>
void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven","
twelve"," thirteen"," fourteen","fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","seventy"," eighty"," ninety"};

void main()
{

long n;
clrscr();
printf("Enter any 5 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}

void pw(long n,char ch[])


{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}

8.SERIES
#include<stdio.h>
#include<conio.h>
#include<math.h>

int fac(int a)
{
if(a==1)

return 1;
else
return a*fac(a-1);
}

double func(int x,int n)


{
int i,j;
double val=0;
for(i=1,j=0;i<=n;i+=2,j++)
val+=(double)(pow(-1,j)*pow(x,i))/(fac(i));
return val;
}

void main()
{
int x,n;
double val;

clrscr();
printf("enter the values of x and n (n should be an odd positive integer)\n");
scanf("%d%d",&x,&n);
val=func(x,n);
printf("value= %lf",val);

getch();
}

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

void main()
{
int a,b;

void swap(int*,int*);
clrscr();
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
printf("a=%d\nb=%d",a,b);
swap(&a,&b);
printf("\nnew values\na=%d\nb=%d",a,b);
getch();
}

void swap(int*p,int*q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
}

You might also like