Welcome To Uday Satya Blog

INDEX of These 70 PROGRAMS




1 Program To Print Welcome To C Language
2 Program To Calculate Sum of Two Numbers
3 Program To Calculate Sum of Three Numbers
4 Program To Calculate Product of Two Numbers
5 Program To Calculate the Entered Value
6 Program To Calculate Average of Two Numbers
7 Program To Calculate Simple Intrest
8 Program To Calculate Area of Triangle
9 Program To Calculate Circumference of Circle
10 Program To Calculate Surface Area of Cylinder
11 Program To Calculate Volume of Cylinder
12 Program To Impliment Various Arithmetic Operations at a Time
13 Program To Calculate Sum of First "n" Natural Numbers
14 Program To Calculate Sum of Squares of First "n" Natural Numbers
15 Program To Calculate Sum of Cubes of First "n" Natural Numbers
16 Program To Convert Farenheit Degrees to Centigrade Degrees
17 Program To Calculate Roots of Quadratic Equation
18 Program To Swap Two Numbers Using Third Variable
19 Program To Swap Two Numbers Without Using Third Variable
20 Program To Print Numbers 1 - 5 Using ++i
21 Program To Print Numbers 5 - 10 Using i++
22 Program To Print Numbers 10 - 5 Using --i
23 Program To Print Numbers 5 - 1 Using i--
24 Program To Calculate Sum of Digits of Number

Using If - else :

25 Program To Check a Number is Positive or not
26 Program To Find The Greatest of Two Numbers
27 Program To Find The Greatest of Three Numbers
28 Program To Check a Year is Leap Year or not
29 Program To Check a Number is Perfect Square or not
30 Program To Check a Number is an Even or odd
31 Program To Calculate Gross Salary of Employee

Using While :

32 Program To Print Numbers From 1 - 10
33 Program To Find Sum of Digits of Number
34 Program To Check If Number is Armstrong or not
35 Program To Check If Number is Pallindrome or not
36 Program To Find Sum of n Natural Numbers
37 Program To Print Fibonacci Series
38 Program To Find Factorial of Number

Using do - While :

39 Program To Print Multiplication Table of Given Number
40 Program To Print Even Numbers upto a Given Number

Using for :

41 Program To Print Multiplication Table of Given Number
42 Program To Calculate Factorial of Given Number
43 Program To Print n Numbers of a Fibonacci Series
44 Program To Check If Number is Prime or not
45 Program To check If Number is Perfect or not

Using Switch :

46 Program To Implement Various Arithmetic Operators

Arrays :

47 Program To Find Sum of Elements of A 1 D Array
48 Program To Sort An Array in Ascending Order
49 Program To Find Sum of Two Matrices
50 Program To Find Product of Two Matrices
51 Program To Find Transpose of A Matrix

Strings :

52 Program To Find Length of A String
53 Program To Concatenate Two Strings
54 Program To Check If A String is A Palindrome or not
55 Program To Copy One String To Another

Using Funtions :

56 Program To Find Sum of First 'n' Natural Numbers Using Functions
57 Program To Find Sum of Elements in An Array Using Functions
58 Program To Find Transpose of A Matrix Using Functions
59 Program To Find Length of A String

Using Recursions :

60 Program To Find Factorial of A Number Using Recursion
61 Program To Find Sum of 'n' Numbers Using Recursion
62 Program To Find Sum of Digits of A Number Using Recursion

Using Pointers :

63 Program To Swap Two Numbers Using Pointers
64 Program To Find Sum of Elements of A 1D Array Using Pointers
65 Program To Find Transpose of A Matrix Using Pointers
66 Program To Copy One String To Another
67 Program To Calculate Marks Using Structures

Files :

68 Program To Read A File and Display its Contents
69 Program To Copy Contents of One File to Another
70 Program To Merge Two Files and Display its Contents


68 - 70 PROGRAMS



/* *************************************************
                  68 . To Read A FILE and Display its Contents
   ************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("test.c","r");
if(fp==NULL)
{
puts("Cannot Open File");
exit(0);
}
else
{
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
else
printf("%c",ch);
}
fclose(fp);
getch();
}

OUTPUT

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    clrscr();
    printf("\n Welcome to C Language ");
    getch();
    }

/* *************************************************
                  69 . To Copy Contents of 1 FILE to Another
   ************************************************** */

#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main
{
FILE *fs,*ft;
char ch;
clrscr();
fp=fopen("test.c","r");
if(fs==NULL)
{
puts("Cannot Open File");
exit(0);
}
ft=fopen("copy.c","r+");
if(ft==NULL)
{
puts("Cannot Open File");
exit(0);
}
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
{
fputc(ch,ft);
printf("%c",ch);
}
}
fclose(fs);
fclose(ft);
getch();
}

OUTPUT

#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
   void main()
    {
    clrscr();
    printf("\n Welcome to C Language ");
    getch();
    }
/* *************************************************
                  70 . To Merge  Two FILES in to Single File
   ************************************************** */

#include<*stdio.h>
#include<*conio.h>
#include<*string.h>
#include<*stdlib.h>
void main()
{
FILE *fp1,*fp2,*fp3;
char c;
clrscr();
printf("Enter First File");
fp1=fopen("n1.data","w");
while(c=getchat()!=EOF)
putc(c,fp1);
fclose(fp1);
printf("Enter Second File");
fp2=fopen("n2.data","w");
while(c=getchat()!=EOF)
putc(c,fp2);
fclose(fp2);
fp1=fopen("n1.data","r");
fp2=fopen("n2.data","r");
fp3=fopen("n3.data","w");
while((c=getc(fp1))!=EOF)
putc(c,fp3);
fclose(fp1);
while(c=getc(fp2)!=EOF)
putc(c,fp3);
fclose(fp2);
fclose(fp3);
printf("The Merged File is :");
fp3=fopen("n3.data","r");
while((c=getc(fp3))!=EOF)
printf("%c",c);
fclose(fp3);
getch();
}

OUTPUT

Enter First File
Welcome To Loyola's ACS

Enter Second File
Satya rocks here...!!!

The Merged File is
Welcome To Loyola's ACS
Satya rocks here...!!!

65 - 67 PROGRAMS


/*************************************************          
       65.To find the transpose of a matrix using pointers ************************************************ */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j;
int arr[3][3],tra[3][3];

printf("Enter the elements to the matrix ");

for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
   scanf("%d",&arr[i][j]);
   }

for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
  {
*(*(tra+j)+i)=*(*(arr+i)+j);
   }
  }
 printf("The transpose is\n");
for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
  printf("%d\t",*(*(tra+i)+j));
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the matrix 1 2 3 4 5 6 7 8 9
The transpose is
1       4       7
2       5       8
3       6       9

/* ***********************************
           66.To copy one string to another
   *********************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{
clrscr();
 char s[100],t[100];
 int l,c,i;
 printf("Enter the string ");
 scanf("%s",&s);

 l=strlen(s);
 for(i=0;i
 {
*(t+i)=*(s+i);
 }
 printf("\nThe entered string is : %s",s);
 printf("\nThe copied string is : %s");
 for(i=0;i
 printf("%c",*(t+i));

getch();
}

OUTPUT
Enter the string Inspire

The entered string is : Inspire
The copied string is : Inspire

/* *****************************************
      67.To calculate the marks using structures
   **************************************** */
#include<*stdio.h>
#include<*conio.h>

void main()
{
clrscr();
 int i;
 struct student
 {
char name[25];
  int roll;
  int m1;
  int m2;
  int total;
  }s[3];

  for(i=0;i<3;i++)
  {
printf("Enter Name ");
   scanf("%s",&s[i].name);
   printf("Enter Roll Number ");
   scanf("%d",&s[i].roll);
   printf("Enter Marks of 1st subject ");
   scanf("%d",&s[i].m1);
   printf("Enter Marks of 2nd subject ");
   scanf("%d",&s[i].m2);
   s[i].total=s[i].m1+s[i].m2;
  }

  for(i=0;i<3;i++)
  {
printf("\nName %s",s[i].name);
   printf("\nRoll No : %d",s[i].roll);
   printf("\nMarks 1 : %d",s[i].m1);
   printf("\nMarks 2 : %d",s[i].m2);
   printf("\nTotal : %d",s[i].total);
   }

  getch();
}

OUTPUT
Enter Name Garima
Enter Roll Number 4
Enter Marks of 1st subject 95
Enter Marks of 2nd subject 90
Enter Name Prerana
Enter Roll Number 16
Enter Marks of 1st subject 80
Enter Marks of 2nd subject 84
Enter Name Nikhil
Enter Roll Number 29
Enter Marks of 1st subject 70
Enter Marks of 2nd subject 93

Name Garima
Roll No : 4
Marks 1 : 95
Marks 2 : 90
Total : 185
Name Prerana
Roll No : 16
Marks 1 : 80
Marks 2 : 84
Total : 164
Name Nikhil
Roll No : 29
Marks 1 : 70
Marks 2 : 93
Total : 163









61 - 64 PROGRAMS



/* **********************************************
         61.To find the sum of n numbers using recursion
   ********************************************** */
#include<*stdio.h>
#include<*conio.h>

int sum(int);
void main()
{
int n,s;
 clrscr();
 printf("Enter the limit\n");
 scanf("%d",&n);
 s=sum(n);
 printf("The sum of the first %d numbers is %d ",n,s);

 getch();
 }
int sum(int n)
{
if(n==0)
 return(0);
 else
 return(n+sum(n-1));
 }

OUTPUT
Enter the limit
6
The sum of the first 6 numbers is 21

/* ***************************************************
       62.To find the sum of digits of a number using recursion
  *************************************************** */
#include
#include

int digi(int);
void main()
{
int n,s;
 clrscr();
 printf("Enter the number to find the sum of the digits\n");
 scanf("%d",&n);
 s=digi(n);
 printf("The sum of the digits of %d is %d ",n,s);

 getch();
 }
int digi(int n)
{
if(n==0)
 return(0);
 else
 return(n%10+digi(n/10));
 }

OUTPUT
Enter the number to find the sum of the digits
3456
The sum of the digits of 3456 is 18

/* ******************************************** 
         63.To swap two numbers using pointers
   ******************************************** */
#include<*stdio.h>
#include<*conio.h>
void swap(int *, int*);

void main()
{
int a,b;
 clrscr();
 printf("Enter the two numbers\n");
 scanf("%d %d",&a,&b);
 printf("Before Swapping\nA=%d\nB=%d",a,b);
 swap(&a,&b);
 getch();
}
void swap(int *p,int*q)
{
int temp;
 temp=*p;
  *p=*q;
  *q=temp;
 printf("\nAfter Swapping\nA=%d\nB=%d",*p,*q);
  }

OUTPUT
Enter the two numbers
5
10
Before Swapping
A=5
B=10
After Swapping
A=10
B=5

/* *****************************************************
       64.To find the sum of elements of a 1D array using pointers
   **************************************************** */
#include<*stdio.h>
#include<*conio.h>

void main()
{
int arr[20],i,n,s=0;
 clrscr();
 printf("Enter the length of the array\n");
 scanf("%d",&n);

 printf("Enter the array elements\n");
 for(i=0;i
 {
scanf("%d",(arr+i));
  s=s+*(arr+i);
 }
 printf("The sum is : %d",s);
 getch();
 }

OUTPUT
Enter the length of the array
5
Enter the array elements
1 2 3 4 5
The sum is : 15

57 - 60 PROGRAMS



/* *******************************************************
       57.To find the sum of the elements in an array using functions
   ******************************************************* */
#include<*stdio.h>
#include<*conio.h>
int sum(int);

void main()
{
int n,s;
 clrscr();
 printf("Enter the number of elements in the array\n");
 scanf("%d",&n);
 s=sum(n);
 printf("The sum of the elements in the array is %d",s);
 getch();
 }
int sum(int n)
{
int s=0,arr[20],i;
 printf("Enter the array elements");
 for(i=0;i
 scanf("%d",&arr[i]);

 for(i=0;i
  s=s+arr[i];
 return(s);
 }

OUTPUT
Enter the number of elements in the array
5
Enter the array elements 1 2 3 4 5
The sum of the elements in the array is 15

/* ***********************************************
        58.To find the transpose of a matrix using functions
   *********************************************** */
#include<*stdio.h>
#include<*conio.h>
void trans(int[3][3]);

void main()
{
int i,j,arr[3][3];
 clrscr();
 printf("Enter the elements to the array (3x3)\n");
 for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
  scanf("%d",&arr[i][j]);
  }
 trans(arr);

 getch();
 }
void trans(int ar[3][3])
{
int tra[3][3],i,j;
 for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
  tra[i][j]=ar[j][i];
  }
  printf("The transpose is\n");
  for(i=0;i<3;i++)
  {
for(j=0;j<3;j++)
   {
printf("%d\t",tra[i][j]);
   }
printf("\n\n");
  }
 }

OUTPUT
Enter the elements to the array (3x3)
1 2 3 4 5 6 7 8 9
The transpose is
1       4       7

2       5       8

3       6       9

/* **********************************************
           59.To find the length of a string using functions
   ********************************************* */
#include<*stdio.h>
#include<*conio.h>
int len(char[20]);

void main()
{
char s[20];
 int l;
 clrscr();
 printf("Enter the string\n");
 scanf("%s",&s);
 l=len(s);
 printf("The length of the string is %d",l);
 getch();
 }
int len(char st[20])
{
int i=0,l=0;

 while(st[i]!='\0')
  {
l++;
   i++;
   }
 return(l);
 }

OUTPUT
Enter the string
Successful
The length of the string is 10

/* *************************************************
          60.To find the factorial of a number using recursion
   ************************************************* */
#include<*stdio.h>
#include<*conio.h>

int fact(int);
void main()
{
int n,f;
 clrscr();
 printf("Enter the number whose factorial has to be found\n");
 scanf("%d",&n);
 f=fact(n);
 printf("The factorial of %d is %d ",n,f);

 getch();
 }

int fact(int n)
{
if(n==1)
 return(1);
 else
 return(n*fact(n-1));
 }

OUTPUT
Enter the number whose factorial has to be found
5
The factorial of 5 is 120

52 - 56 PROGRAMS



/* ***************************************
          52.To find the length of a string
   *************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{
 clrscr();
 char s[100];
 int l;
 printf("Enter the string ");
 scanf("%s",&s);

 l=strlen(s);

printf("\nThe string length is %d",l);

getch();
}

OUTPUT
Enter the string Memory

The string length is 6

/* ************************************************
          53.To concatenate 2 strings
   *********************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the first string ");
 scanf("%s",&s);
 printf("Enter the second string ");
 scanf("%s",&t);

 strcat(s,t);

 printf("\nThe concatenated string is : %s",s);

getch();
}

OUTPUT
Enter the first string Computer
Enter the second string Applications

The concatenated string is : ComputerApplications


/* *********************************************************
        54.To check if a string is a palindrome or not
   ******************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{
clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the string ");
 scanf("%s",&s);

 strcpy(t,s);
 strrev(s);
 c=strcmp(t,s);

if(c==0)
printf("\nThe string is a palindrome");

getch();
}

OUTPUT
Enter the string ABBA

The string is a palindrome

/* ********************************************************************
                55.To copy one string to another
  ******************************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the string ");
 scanf("%s",&s);

 strcpy(t,s);

 printf("\nThe entered string is : %s",s);
 printf("\nThe copied string is : %s",t);

getch();
}

OUTPUT
Enter the string Hyderabad

The entered string is : Hyderabad
The copied string is : Hyderabad

/* **********************************************************************
   56.To find the sum of the first n natural numbers using functions
  ************************************************************************ */
#include
#include
int sum(int);

void main()
{
int n,s;
 clrscr();
 printf("Enter the limit\n");
 scanf("%d",&n);
 s=sum(n);
 printf("The sum of the first %d natural numbers is %d",n,s);
 getch();
 }
int sum(int n)
{
int s=0;
 for(int i=1;i<=n;i++)
  s=s+i;
 return(s);
 }

OUTPUT
Enter the limit
6
The sum of the first 6 natural numbers is 21

49 - 51 PROGRAMS



/******************************************
    49.To find the sum of 2 matrices
 ***************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j,k;
int arr1[3][3],arr2[3][3],arr3[3][3];

printf("Enter the elements to the first matrix ");

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

printf("Enter the elements to the second matrix ");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  scanf("%d",&arr2[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr3[i][j]=(arr1[i][j]+arr2[i][j]);
   }
  }
 printf("The sum is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr3[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the first matrix 1 2 3 4 5 6 7 8 9
Enter the elements to the second matrix 10 10 10 10 10 10 10 10 10
The sum is
11      12      13
14      15      16
17      18      19

/* *********************************************
     50.To find the product of 2 matrices
   ********************************************* */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j,k,l;
int arr1[3][3],arr2[3][3],arr3[3][3];

printf("Enter the elements to the first matrix ");

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

printf("Enter the elements to the second matrix ");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  scanf("%d",&arr2[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr3[i][j]=0;
   for(k=0;k<3;k++)
   {arr3[i][j]+=(arr1[i][k]*arr2[k][j]);
   }
  }
 }
 printf("The product is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr3[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the first matrix 1 2 3 4 5 6 7 8 9
Enter the elements to the second matrix 1 0 0 0 1 0 0 0 1
The product is
1       2       3
4       5       6
7       8       9

/* **************************************************** 
         51.To find the transpose of a matrix
   **************************************************** */
#include<*stdio.h>
#include*
void main()
{
clrscr();
int i,j;
int arr1[3][3],arr2[3][3];

printf("Enter the elements to the matrix ");

for(i=0;i<3;i++)
 {
for(j=0;j<3;j++)
   scanf("%d",&arr1[i][j]);
   }

for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  {arr2[j][i]=arr1[i][j];
   }
  }
 printf("The transpose is\n");
for(i=0;i<3;i++)
 {for(j=0;j<3;j++)
  printf("%d\t",arr2[i][j]);
  printf("\n");
 }
getch();
}

OUTPUT
Enter the elements to the matrix 1 2 3 4 5 6 7 8 9
The transpose is
1       4       7
2       5       8
3       6       9

46 - 48 PROGRAMS



/*****************************************************
   46.To implement various arithmetic operators using Switch
 **************************************************** */
#include <*stdio.h>
#include <*conio.h>
void main()
{
clrscr();
 int ch;
 float n1,n2,r;
 printf("Enter your choice \n 1. Addition 2. Subtraction 
                           3. Multiplication 4. Division ");
 scanf("%d",&ch);
 printf("Enter the numbers ");
 scanf("%f %f",&n1,&n2);

switch (ch)
{
case 1:
  r=n1+n2;
  printf("The sum of the numbers is : %f",r);
  break;
case 2:
  r=n1-n2;
  printf("The difference of the numbers is : %f",r);
  break;
case 3:
  r=n1*n2;
  printf("The product of the numbers is : %f",r);
  break;
case 4:
  r=n1/n2;
  printf("The quotient is : %f",r);
  break;
default : printf("Wrong input");
}//switch
getch();
}//main

OUTPUT
Enter your choice
 1. Addition 2. Subtraction 3. Multiplication 4. Division 
3
Enter the numbers 4
6
The product of the numbers is : 24.000000


/* *******************************************
         47.To find sum of elements of a 1 D array
   ******************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,sum=0,n;
int arr[100];
printf("Enter the length of the array ");
scanf("%d",&n);
printf("Enter the array elements");

for(i=0;i
{
scanf("%d",&arr[i]);
 sum=sum+arr[i];
 }

printf("\nThe sum of the elements is %d",sum);

getch();
}

OUTPUT
Enter the length of the array 5
Enter the array elements 1 2 3 4 5

The sum of the elements is 15

/* ****************************************
     48.To sort an array is ascending order
   **************************************** */
#include<*stdio.h>
#include<*conio.h>
void main()
{
clrscr();
int i,j,n,temp;
int arr[100];
printf("Enter the length of the array ");
scanf("%d",&n);
printf("Enter the array elements");

for(i=0;i
 scanf("%d",&arr[i]);

for(i=0;i
{
for(j=i+1;j
 {
if(arr[i]>arr[j])
  {
temp=arr[i];
   arr[i]=arr[j];
   arr[j]=temp;
  }
 }
}
printf("\nThe sorted array is ");
for(i=0;i
 printf("%d\t",arr[i]);

getch();
}

OUTPUT
Enter the length of the array 5
Enter the array elements 87 54 14 3 67

The sorted array is 3   14      54      67      87

41 - 45 PROGRAMS


                                                                                                                                               /*****************************************************
    41. To Print Multiplication Table of a Number using for loop
   *************************************************** */

 
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,i;
    clrscr();
    printf("\n Enter n,To Print Multiplication Table of it : ");
    scanf("%d", &n);
    for(i = 1;i <= 10;i++)
    printf("\n %d * %d = %d \n", n, i, n*i);
    getch();
    }

   Output :
   Enter n,To Print Multiplication Table of it : 5
   5 * 1 = 5
   5 * 2 = 10
   5 * 3 = 15
   5 * 4 = 20
   5 * 5 = 25
   5 * 6 = 30
   5 * 7 = 35
   5 * 8 = 40
   5 * 9 = 45
   5 * 10 = 50
                                                                                                  

 *************************************************
     42. To Find Factorial of a Given Number using for loop
    ********************************************** */

  
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,s = 1,i;
    clrscr();
    printf("\n Enter n,To Find Faactorial of it : ");
    scanf("%d", &n);
    for(i = 1;i <=n;i++)
        s = s * i;
    printf("\n\n Factorial of %d is : %d", n, s);
    getch();
    }

   Output :

   Enter n,To Find Factorial of it : 5

   Factorial of 5 is 120

                                                                                                                                                 
/* **********************************************
     43. To Print n fibonacci numbers using for loop
   ********************************************* */

  
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,a = 0,b = 1,c,i;
    clrscr();
    printf("\n Enter n,To Print First n Fibonacci Series Numbers : ");
    scanf("%d", &n);
    printf("\n %d \n", a);
    printf("\n %d \n", b);
    for(i = 2;i < n;i++)
        {
        c = a + b;
        printf("\n %d \n", c);
        a = b;
        b = c;
        }
    getch();
    }

   Output :
 
   Enter n,To print First n Fibonacci Series Numbers : 6
   0
   1
   1
   2
   3
   5
                                                                                                                                        
                                                                                                                                                  /* ****************************************
        44. To Check for a Prime Number or not
    *************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,i,s = 0;
    clrscr();
    printf("\n Enter any Number,To Check for Prime Number : ");
    scanf("%d", &n);
    for(i = 2;i < n;i++)
        if(n % i == 0)
            s++;
    if(s==0)
        printf("\n\n %d is a Prime Number", n);
    else
        printf("\n\n %d is not a Prime Number", n);
    getch();
    }

   Output :
  
   Enter any Number,To Check for Prime Number : 5

   5 is not a Prime Number
                                                                                                                                                  /* **************************************
      45. To Check for a Perfect Number or not
    ************************************** */

 
#include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int n,i,s = 0;
    clrscr();
    printf("\n Enter any Number,To Check for Perfect Number : ");
    scanf("%d", &n);
    for(i = 1;i < n;i++)
        if(n % i == 0)
            s = s + i;
    if(n == s)
        printf("\n\n %d is a Perfect Number", n);
    else
        printf("\n\n %d is not a Perfect Number", n);
    getch();
    }

   Output :

   Enter any Number,To Check for Perfect Number : 6

   6 is a Perfect Number

36 - 40 PROGRAMS


                                                                                                                                              
/* ********************************************
               36. To Find Sum of "n" Natural Numbers
    ********************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,s = 0,i = 1;
    clrscr();
    printf("\n Enter n,To Find Sum of First n Natural Numbers : ");
    scanf("%d", &n);
    while(i <= n)
        {
        s = s + i;
        i++;
        }
    printf("\n\n Sum of first %d Natural Numbers is : %d", n, s);
    getch();
    }

   Output :

   Enter n,To find Sum of First n Natural Numbers : 5
  
   Sum of First 5 NaturalNumbers is : 15
                                                                                                                                            
/* ***********************************************
        37. To Print n fibonacci numbers using While loop
    *********************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,a = 0,b = 1,c,i = 2;
    clrscr();
    printf("\n Enter n,To Print n Fibonacci Series Numbers : ");
    scanf("%d", &n);
    printf("\n\n %d \n", a);
    printf("\n %d \n", b);
    while(i<=n)
        {
        c = a + b;
        printf("\n %d \n", c);
        a = b;
        b = c;
        i++;
        }
    getch();
    }

   Output :

   Enter n,To Print  n Fibonacci Series Numbers : 6
   0
   1
   1
   2
   3
   5
                                                                                                                                                
/* **************************************************
     38. To Find Factorial of a Given Number using while loop
   ************************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,s = 1,i = 1;
    clrscr();
    printf("\n Enter any Number,To Find its Faactorial : ");
    scanf("%d", &n);
    while(i <= n)
        {
        s = s * i;
        i++;
        }
    printf("\n\n Factorial of %d is : %d", n, s);
    getch();
    }

   Output :

   Enter any Number,To Find its Factorial : 5

   Factorial of 5 is 120
                                                                                                                                           
/* *************************************************
39. To Print Multiplication Table of a Number using Do-While
    **************************************************/

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,i = 1;
    clrscr();
    printf("\n Enter any Number,To Print its Multiplication Table : ");
    scanf("%d", &n);
    do
        {
        printf("\n %d * %d = %d \n", n, i, n*i);
        i++;
        }while(i <= 10);
    getch();
    }

   Output :
   Enter any Number,To Print its Multiplication Table : 5
   5 * 1 = 5
   5 * 2 = 10
   5 * 3 = 15
   5 * 4 = 20
   5 * 5 = 25
   5 * 6 = 30
   5 * 7 = 35
   5 * 8 = 40
   5 * 9 = 45
   5 * 10 = 50
                                                                                                                                                
/* ****************************************
         40. To Print All Even Numbers upto n
    ***************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,i = 1;
    clrscr();
    printf("\n Enter n,To Print all Even Numbers upto it : ");
    scanf("%d", &n);
    do
        {
        printf("\n %d \n", 2*i);
        i++;
        }
        while(2*i <= n);
    getch();
    }

   Output :
   Enter n,To Print all Even Numbers upto it : 9
   2
   4
   6
   8

31 - 35 PROGRAMS



                                                                                                                                       
/* ******************************************
            31. To Find Gross Salary of A Worker
    ***************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    float bs,hra,da,gs;
    clrscr();
    printf("\n Enter Basic Salary : Rs. ");
    scanf("%f", &bs);
    if(bs<1500)
        {
        hra = bs * 10 /100;
        da = bs * 90 / 100;
        }
    else
        {
        hra = 500;
        da = bs * 98 / 100;
        }
    gs = bs + hra + da;
    printf("\n\n Gross Salary is : Rs. %f", gs);
    getch();
    }

   Output :

   Enter Basic Salary : Rs. 500

   Gross Salary is : Rs. 1000
                                                                                                                                              
/* ********************************************
                   32. To Print 1-10 using While loop
    ******************************************** */

 
   #include<*stdio.h>
   #include<*conio.h>

   void main()
    {
    int i = 1;
    clrscr();
    while(i <= 10)
        printf("\n %d \n", i++);
    getch();
    }

   Output :

   1
   2
   3
   4
   5
   6
   7
   8
   9
   10
                                                                                                                                              
/* *********************************************
            33. To Find Sum of Digits of a Give Number
    ********************************************* */

    #include<*stdio.h>
   #include<*conio.h>


   void main()
    {
    int n,s = 0,r,x;
    clrscr();
    printf("\n Enter any Number,To Find Sum of Digits : ");
    scanf("%d", &n);
    x = n;
    while(x > 0)
        {
        r = x % 10;
        s = s + r;
        x = x / 10;
        }
    printf("\n\n Sum of Digits of %d is : %d", n, s);
    getch();
    }

   Output :
 
   Enter any Number,To Find Sum of Digits : 45

   Sum of Digits of 45 is : 9
                                                                                                                                            
/* **************************************************
      34. To Check Whether a Number is an Armstrong or not
    ************************************************* */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,s = 0,r,x;
    clrscr();
    printf("\n Enter any Number,To Check for Armstrong or not : ");
    scanf("%d", &n);
    x = n;
    while(x > 0)
        {
        r = x % 10;
        s = s + r*r*r;
        x = x / 10;
        }
    if(s == n)
        printf("\n\n %d is an Armstrong Number", n);
    else
        printf("\n\n %d is not an Armstrong Number", n);
    getch();
    }

   Output :

   Enter any Number,To Check for Armstrong or not : 153

   153 is an Armstrong Number
                                                                                                                                                  
/* **********************************************
   35. To Check Whether a Number is Pallindrome or not
    ********************************************** */

   #include<*stdio.h>
   #include<*conio.h>
   void main()
    {
    int n,s = 0,r,x;
    clrscr();
    printf("\n Enter any Number,To Check for Pallindrome : ");
    scanf("%d", &n);
    x = n;
    while(x > 0)
        {
        r = x % 10;
        s = s * 10 + r;
        x = x / 10;
        }
    if(s == n)
        printf("\n\n %d is a Pallindrome Number", n);
    else
        printf("\n\n %d is not a Pallindrome Number", n);
    getch();
    }

   Output :
   Enter any Number,To Check for Pallindrome : 121
   121 is a Pallindrome Number