#include<stdio.h>
#include<conio.h>
void swaping(int *,int *);
main()
{
int a,b;
//clrscr();
printf("Enter value of A and B");
scanf("%d %d",&a,&b);
swaping(&a,&b);
printf("After swapping value of A and B is %d and %d",a,b);
//getch();
}
void swaping(int *x,int *y)
{
int temp=0;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<conio.h>
void ncr(int ,int );
int fact(int);
main()
{
int n,r;
//clrscr();
printf("Enter value of N and R");
scanf("%d %d",&n,&r);
ncr(n,r);
//getch();
}
void ncr(int x,int y)
{
float ans;
ans=fact(x)/(fact(y)*fact(x-y));
printf("%dC%d is %f",x,y,ans);
}
int fact(int p)
{
int f=1,i;
for(i=1;i<=p;i++)
{
f=f*i;
}
return f;
}
#include<stdio.h>
int Fibonacci(int);
main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
#include<stdio.h>
#include<conio.h>
void maxmin(int [] ,int );
main()
{
int n,a[20],i;
//clrscr();
printf("Enter value size of Array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
maxmin(a,n);
//getch();
}
void maxmin(int x[],int n)
{
int i,max,min;
max=x[0];
min=x[0];
for(i=0;i<n;i++)
{
if(max<x[i])
{
max=x[i];
}
if(min>x[i])
{
min =x[i];
}
}
printf("Minimum and Maximum number in given array is %d and %d",max,min);
}
#include<stdio.h>
#include<conio.h>
int fibo(int);
int strlen(char []);
void strrev(char []);
main()
{
char s[20],s2[20];
//clrscr();
printf("Enter any string ");
gets(s);
strrev(s);
//getch();
}
int strlen(char p[])
{
int i,length=0;
for(i=0;p[i] != '\0';i++)
{
length++;
}
return length;
}
void strrev(char s[])
{
int length,i,j;
char revstr[20]="";
length=strlen(s);
j=0;
for(i=length-1;i>=0;i--)
{
revstr[i]=s[j];
j++;
}
printf("Reverse of %s is %s",s,revstr);
}
#include <stdio.h>
int sum (int a);
int main()
{
int num, result;
printf("Enter the number: ");
scanf("%d", &num);
result = sum(num);
printf("Sum of digits in %d is %d\n", num, result);
return 0;
}
int sum (int num)
{
int x;
if (num == 0)
{
x=0;
return x;
}
else
{
x=num % 10 + sum (num / 10);
return x;
}
}
#include<conio.h>
void swaping(int *,int *);
main()
{
int a,b;
//clrscr();
printf("Enter value of A and B");
scanf("%d %d",&a,&b);
swaping(&a,&b);
printf("After swapping value of A and B is %d and %d",a,b);
//getch();
}
void swaping(int *x,int *y)
{
int temp=0;
temp=*x;
*x=*y;
*y=temp;
}
#include<stdio.h>
#include<conio.h>
void ncr(int ,int );
int fact(int);
main()
{
int n,r;
//clrscr();
printf("Enter value of N and R");
scanf("%d %d",&n,&r);
ncr(n,r);
//getch();
}
void ncr(int x,int y)
{
float ans;
ans=fact(x)/(fact(y)*fact(x-y));
printf("%dC%d is %f",x,y,ans);
}
int fact(int p)
{
int f=1,i;
for(i=1;i<=p;i++)
{
f=f*i;
}
return f;
}
#include<stdio.h>
int Fibonacci(int);
main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
#include<stdio.h>
#include<conio.h>
void maxmin(int [] ,int );
main()
{
int n,a[20],i;
//clrscr();
printf("Enter value size of Array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
maxmin(a,n);
//getch();
}
void maxmin(int x[],int n)
{
int i,max,min;
max=x[0];
min=x[0];
for(i=0;i<n;i++)
{
if(max<x[i])
{
max=x[i];
}
if(min>x[i])
{
min =x[i];
}
}
printf("Minimum and Maximum number in given array is %d and %d",max,min);
}
#include<stdio.h>
#include<conio.h>
int fibo(int);
int strlen(char []);
void strrev(char []);
main()
{
char s[20],s2[20];
//clrscr();
printf("Enter any string ");
gets(s);
strrev(s);
//getch();
}
int strlen(char p[])
{
int i,length=0;
for(i=0;p[i] != '\0';i++)
{
length++;
}
return length;
}
void strrev(char s[])
{
int length,i,j;
char revstr[20]="";
length=strlen(s);
j=0;
for(i=length-1;i>=0;i--)
{
revstr[i]=s[j];
j++;
}
printf("Reverse of %s is %s",s,revstr);
}
#include <stdio.h>
int sum (int a);
int main()
{
int num, result;
printf("Enter the number: ");
scanf("%d", &num);
result = sum(num);
printf("Sum of digits in %d is %d\n", num, result);
return 0;
}
int sum (int num)
{
int x;
if (num == 0)
{
x=0;
return x;
}
else
{
x=num % 10 + sum (num / 10);
return x;
}
}