Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
97 views

C Program File

The document contains 15 programs written in C language to solve common problems. The programs include calculating simple interest, finding the biggest of three numbers, checking if a number is prime, converting temperatures between Celsius and Fahrenheit scales, and more. For each problem, the C code for the program is provided along with an expected output example.

Uploaded by

ayush
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)
97 views

C Program File

The document contains 15 programs written in C language to solve common problems. The programs include calculating simple interest, finding the biggest of three numbers, checking if a number is prime, converting temperatures between Celsius and Fahrenheit scales, and more. For each problem, the C code for the program is provided along with an expected output example.

Uploaded by

ayush
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/ 30

INDEX

S.NO

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

PROGRAM NAME

SIGN

WRITE A PROGRAM IN C TO FIND SIMPLE INTEREST


WRITE A PROGRAM IN C TO PRINT TABLE OF USER GIVEN
NUMBER
WRITE A PROGRAM IN C TO FIND THE BIGGEST OF THREE
NUMBERS
WRITE A PROGRAM IN C TO CHECK ODD OR EVEN NUMBER
WRITE A PROGRAM IN C TO FIND FACTORIAL OF ENTERED
NUMBER USING RECUSION
WRITE A PROGRAM IN C TO CHECK GIVEN NUMBER IS
ARMSTRONG OR NOT
WRITE A PROGRAM IN C TO CHECK GIVEN NUMBER IS
PERFECT OR NOT
WRITE A PROGRAM IN C TO CHECK GIVEN NUMBER IS PRIME
OR NOT
WRITE A PROGRAM IN C TO CHECK ENTERED YEAR IS LEAP
YEAR OR NOT
WRITE A PROGRAM IN C TO PRINT RIGHT ANGLED PYRAMID
WRITE A PROGRAM IN C TO CONVERT FROM UPPERCASE TO
LOWER CASE
WRITE A PROGRAM IN C FOR ADDITION OF ALL ELEMENTS OF
THE ARRAY
WRITE A PROGRAM IN C TO FIND THE REVERSE OF USER GIVEN
NUMBER
WRITE A PROGRAM IN C TO CONVERT TEMPERATURE FROM
DEGREE CENTIGRADE TO FAHRENHEIT
WRITE A PROGRAM IN C TO PRINT FABINOCCI SERIES

1. WRITE A PROGRAM IN C TO PRINT TABLE OF USER GIVEN NUMBER

#include <stdio.h>
#include<conio.h>
int main()
{
int num, i = 1;
clrscr();
printf("\n Enter any Number:");
scanf("%d", &num);
printf("Multiplication table of %d: \n", num);
while (i <= 10)
{
printf("\n %d x %d = %d", num, i, num * i);
i++;
}
return 0;
getch();
}

OUTPUT:

2. WRITE A PROGRAM IN C TO FIND SIMPLE INTEREST


#include <stdio.h>
#include <conio.h>
main()
{
float p, r, si;
int t;
clrscr();
printf("Enter the values of principal, rate and time\n");
scanf ("%f %f %d", &p, &r, &t);
si = (p * r * t)/ 100.0;
printf ("Amount = Rs. %5.2f\n", p);
printf ("Rate = Rs. %5.2f%\n", r);
printf ("Time = %d years\n", t);
printf ("Simple interest = %5.2f\n", si);
getch();
}

OUTPUT:

3. WRITE A PROGRAM IN C TO FIND THE BIGGEST OF THREE NUMBERS

#include<stdio.h>
#include<conio.h>
main()
{
int a, b, c;
clrscr();
printf("Enter the value for a:\n");
scanf("%d", &a);
printf("Enter the value for b:\n");
scanf("%d", &b);
printf("Enter the value for c:\n");
scanf("%d", &c);
if ((a > b) && (a > c))
{
printf("\n The big one is a= %d", a);
}
else if (b > c)
{
printf("\n The big one is b= %d", b);
}
else
{
printf("\n The big one is c= %d", c);
}
getch();
}

OUTPUT:

4. WRITE A PROGRAM IN C TO CHECK THE ENTERED NUMBER IS PERFECT


NUMBER OR NOT
#include<stdio.h>

#include<conio.h>
main()
{
int n,i=1,sum=0;
clrscr();
printf("Enter a number: ");
scanf("%d",&n);
while(i<n)
{
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);
getch();
}

OUTPUT:

5. WRITE A PROGRAM IN C TO CHECK GIVEN NUMBER IS ARMSTRONG OR


NOT
#include<stdio.h>

#include<conio.h>
main()
{
int num,r,sum=0,temp;
clrscr();
printf("Enter a number: ");
scanf("%d",&num);
temp=num;
while(num!=0)
{
r=num%10;
num=num/10;
sum=sum+(r*r*r);
}
if(sum==temp)
printf("%d is an Armstrong number",temp);
else
printf("%d is not an Armstrong number",temp);
getch();
}

OUTPUT:

6. WRITE A PROGRAM IN C TO CHECK ODD OR EVEN NUMBER


#include<stdio.h>

#include<conio.h>
main()
{
int number;
clrscr();
printf("Enter any integer: ");
scanf("%d",&number);
if(number % 2 ==0)
printf("%d is even number.",number);
else
printf("%d is odd number.",number);
getch();
}

OUTPUT:

7. WRITE A PROGRAM IN C TO FIND FACTORIAL OF NUMBER USING


RECURSION
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int x,n;
clrscr();
printf("nEnter the value of n :");
scanf("%d",&n);
x=fact(n);
printf("n%d",x);
getch();
}
int fact(int n)
{
if(n==0)
return(1);
return(n*fact(n-1));
}

OUTPUT:

8. WRITE A PROGRAM IN C TO FIND ENTERED YEAR IS LEAP YEAR OR NOT


#include<stdio.h>
#include<conio.h>
main()
{
int year;
clrscr();
printf("Enter any year: ");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
getch();
}

OUTPUT:

9. WRITE A PROGRAM IN C TO PRINT RIGHT ANGLED PYRAMID


#include<stdio.h>
#include<conio.h>
main()
{
int i,j,lines;
char ch = '*';
clrscr();
printf("Enter number of lines : ");
scanf("%d",&lines);
for(i=0;i <=lines;i++)
{
printf("\n");
for (j=0;j < i;j++)
printf("%c",ch);
}
getch();
}

OUTPUT:

10.
WRITE A PROGRAM IN C TO CONVERT FROM UPPERCASE TO
LOWER CASE

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char str[20];
int i;
clrscr();
printf("Enter any string->");
scanf("%s",str);
printf("The string is->%s",str);
for(i=0;i<=strlen(str);i++)
{
if(str[i]>=65&&str[i]<=90)
str[i]=str[i]+32;
}
printf("\nThe string in lower case is->%s",str);
getch();
}

OUTPUT:

11. WRITE A PROGRAM IN C FOR ADDITION OF ALL ELEMENTS OF THE


ARRAY

#include<stdio.h>
#include<conio.h>
main()
{
int i,a[50],sum,n;
clrscr();
printf("nEnter no of elements :");
scanf("%d",&n);
printf("nEnter the values :");
for(i=0;i < n;i++)
scanf("%d",&a[i]);
sum=0;
for(i=0;i < n;i++)
sum=sum+a[i];
for(i=0;i < n;i++)
printf("na[%d]=%d",i,a[i]);
printf("nSum=%d",sum);
getch();
}

OUTPUT:

12. WRITE A PROGRAM IN C TO FIND THE REVERSE OF USER GIVEN


NUMBER
#include<stdio.h>
#include<conio.h>
main()
{
int num,rem,rev=0;
clrscr();
printf("nEnter any no to be reversed : ");
scanf("%d",&num);
while(num>=1)
{
rem = num % 10;
rev = rev * 10 + rem;
num = num / 10;
}
printf("nReversed Number : %d",rev);
getch();
}

OUTPUT:

13.
PROGRAM TO CONVERT TEMPERATURE FROM DEGREE
CENTIGRADE TO FAHRENHEIT
#include<stdio.h>
#include<conio.h>
main()
{
float celsius,fahrenheit;
clrscr();
printf("nEnter temp in Celsius : ");
scanf("%f",&celsius);
fahrenheit = (1.8 * celsius) + 32;
printf("nTemperature in Fahrenheit : %f ",fahrenheit);
getch();
}

OUTPUT:

14. WRITE A PROGRAM IN C TO PRINT FIBONACCI SERIES


#include<stdio.h>
#include<conio.h>
main()
{
int k,r;
long int i=0l,j=1,f;
clrscr();
printf("Enter the number range:");
scanf("%d",&r);
printf("FIBONACCI SERIES: ");
printf("%ld %ld",i,j);
for(k=2;k<r;k++)
{
f=i+j;
i=j;
j=f;
printf(" %ld",j);
}
getch();
}

OUTPUT:

15. WRITE A PROGRAM IN C TO CHECK WHETHER ENTERED NUMBER IS


PRIME OR NOT

#include <stdio.h>
#include <conio.h>
main()
{
int n, i, flag=0;
clrscr();
printf("Enter a positive integer: ");
scanf("%d",&n);
for(i=2;i<=n/2;++i)
{
if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
getch();
}

OUTPUT:

You might also like