Вы находитесь на странице: 1из 12

FIBONACCI SERIES

.#include<stdio.h>

int main()
{
unsigned int i=0,j=0,sum=1,num;
  printf("nEnter the limit for the series ");
  scanf("%d",&num);
  while(sum<num)
   {
   printf("%d ",sum);
    i=j;
   j=sum;

   sum=i+j;
   }
  getch();  
}

INPUT:

Enter the limit for the series:4

Output:

0112

PRIME NUMBER

void main ()

int no,i=2;
clrscr ();

printf ("Enter Number: ");

scanf ("%d",&no);

while (i<=no)

if (no%i==0)

break;

i++;

if (i==no)

printf ("Number is Prime");

else

printf ("Number is not Prime");

getch ();

Output:

 
ARRANGE THE ELEMENTS IN ARRAY IN DESSENDING ORDER.

main()
{
int a[100],i,n,j,search,temp;
printf("\n how many no's in array");
scanf("%d",&n);
printf("\n enter %d elements in array",n);
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
{
for(j=i+1;j
{
if(a[i]
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("%4d",a[i]);
}
getch();
}

Input:

How many no in array:5

76

87
34

12

98

Output:

98

87

76

34

12

PROGRAM TO ARRANGE THE ELEMENTS IN ARRAY IN ASSENDING


ORDER

#include "stdio.h"
#include "conio.h"
main()
{
int a[100],i,n,j,search,temp;
printf("\n how many no's in array");
scanf("%d",&n);
printf("\n enter %d elements in array",n);
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
{
for(j=i+1;j
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
printf("%4d",a[i]);
}
getch();
}

Input:

How many no in array:5

76

87

34

12

98

Output:

12

34
76

87

98

Program to find whether a number is odd or even


#include
int main()
{
int number ;
printf("Enter a whole number\n");
scanf("%d",&number);
if(number % 2 == 0)
printf("number is even.\n");
else
printf("number is odd.\n");

return 0;
}
WAP TO FIND OUT YEAR IS LEAP OR NOT

void main ()

int a;

clrscr ();

printf ("Enter the Year: ");


scanf("%d",&a);

if (a%4==0)

printf ("\nYear is Leap");

else

printf("\nYear is not Leap");

getch ();

}
Output:

Write a program to find the length of a string without using strlen


function in c?
#include<conio.h>
#include<stdio.h>
void main()
{
char a[20];
int i;
clrscr();
Printf(“enter the string”);
gets(a);
i=0;
while(a[i]!='\0')
i++; //counts no of chars till encountering null char
printf(sring length=%d,i);
getch();
}
Input:
Enter the string:Information Technology
OUTPUT: string length=21

Write a C program to reverse the string without using strrev() function?

#include<stdio.h>
#include<string.h>
main()
{
char str[50] revstr[50];
int i=0 j=0;
printf(“ Enter the string to be reversed :”);
scanf( s str);
for(i=strlen(str)-1;i>=0;i--)
{
revstr[j]=str[i];
j++;
}
revstr[j]='\0';
printf( Input String : s str);
printf( \nOutput String : s revstr);
getch();

Input:

Enter the string to be reversed : btech

Output:

Output String=hcetb

call by value
main()
{
int x=50, y=70;
interchange(x,y);
printf(“x=%d y=%d”,x,y);
}

interchange(x1,y1)
int x1,y1;
{
int z1;
z1=x1;
x1=y1;
y1=z1;
printf(“x1=%d y1=%d”,x1,y1);
}

output:

x1=70 y1=50
x=50 y=70
call by reference

main()
{
int x=50, y=70;
interchange(&x,&y);
printf(“x=%d y=%d”,x,y);
}

interchange(x1,y1)
int *x1,*y1;
{
int z1;
z1=*x1;
*x1=*y1;
*y1=z1;
printf(“*x=%d *y=%d”,x1,y1);
}
output:

*x=70 *y=50
x=70 y=50

The sum of digits of a number


#include <stdio.h>
 
int main()
{
int n = 12345;
int sum = 0;
 
while (n != 0) {
int c = n%10;
sum += c;
n /= 10;
}
 printf("The sum is %d\n", sum);
return 0;
Output:
n=12345
the sum is =15

write program for palindrome


#include<stdio.h>
#include<conio.h>
void main()
{
int n,s=0,m;
clrscr();
printf("enter any no");
scanf("%d",&n);
m=n;
while(n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
if(m==n)
printf("the no is palindrome");
else
printf("no is not palindrome");
getch();
}
Output:
Enter any no:151
The no is palindrome
Enter any no:151
The no is not palindrome

PROGRAM FOR GIVEN STRING IS PALINDROME OR NOT


#include<stdio.h>
#include<string.h>
#define size 26
void main()
{
char strsrc[size];
char strtmp[size];
clrscr();
printf("\n Enter String:= ");
gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not
palindrome",strsrc);
getch();
}

Output:
Enter the string:Malayalam
Entered string is palindrome
 

Вам также может понравиться