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

C-Programs

The document contains a series of C programming examples, including programs for displaying a welcome message, calculating the sum of three values, computing simple interest, determining age categories, performing basic arithmetic operations using a switch case, converting Fahrenheit to Celsius, checking if a number is even or odd, and finding the largest number among ten inputs. Each program includes the necessary C code and prompts for user input. The examples illustrate fundamental programming concepts and syntax in C.

Uploaded by

iam7arunprasanth
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)
3 views

C-Programs

The document contains a series of C programming examples, including programs for displaying a welcome message, calculating the sum of three values, computing simple interest, determining age categories, performing basic arithmetic operations using a switch case, converting Fahrenheit to Celsius, checking if a number is even or odd, and finding the largest number among ten inputs. Each program includes the necessary C code and prompts for user input. The examples illustrate fundamental programming concepts and syntax in C.

Uploaded by

iam7arunprasanth
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/ 5

C- PROGRAMS

PROGRAM 1:

Write a program to display Welcome to ‘C’ programming

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“\t\t Welcome to ‘C’ Programming\n”);
getch();
}

PROGRAM 2:

Write a program to get three values and find the sum

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf(“Enter the first value=\n”);
scanf(“%d”,&a);
printf(“Enter the second value=\n”);
scanf(“%d”,&b);
printf(“Enter the third value=\n”);
scanf(“%d”,&c);
d=a+b+c;
printf(“The result =%d”,d);
getch();
}

PROGRAM 3:

Write a program to simple interest

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

1
void main()
{
float si,p,n,r;
clrscr();
printf(“Enter the principal amount=\n”);
scanf(“%f”,&p);
printf(“Enter the number of years=\n”);
scanf(“%f”,&n);
printf(“Enter the rate of interest=\n”);
scanf(“%f”,&r);
si=(p*n*r)/100;
printf(“the simple interest=%f”,si);
getch();
}

PROGRAM 4:

Write a program to get the age by using elseif condition as follows:


<18, print a message “MINOR”
>=18, print a message “MAJOR”
>=60, print a message “OLD PERSON”

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf(“Enter the age=\n”);
scanf(“%d”,&a);
if(a<18)
{
printf(“\n YOU ARE MINOR”);
}
else if(a>=18&&a<=60)
{
printf(“\n YOU ARE MAJOR”);
}
else
printf(“\n YOU ARE OLD PERSON”);
getch();
}

2
PROGRAM 5:

Write a program to add,subtract,multiply,divide two numbers using


switch case.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,ch;
clrscr();
printf(“Enter your choice=\n”);
printf(“\n1.ADDITION”);
printf(“\n2.SUBTRACTION”);
printf(“\n3.MULTIPLY”);
printf(“\n4.DIVIDE”);
printf(“\n5.END”);
printf(“\n\nEnter your choice (1 to 5)=”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“\nEnter the first number =\n”); scanf(“%d”,&a);
printf (“\nEnter the second number =\n”); scanf(“%d”,&b);
c=a+b;
printf(“\nAddition of two numbers=%d”,c);
break;
case 2:
printf(“\nEnter the first number =\n”); scanf(“%d”,&a);
printf (“\nEnter the second number =\n”); scanf(“%d”,&b);
d=a-b;
printf(“\n Subtraction of two numbers=%d”,d);
break;
case 3:
printf(“\nEnter the first number =\n”); scanf(“%d”,&a);
printf (“\nEnter the second number =\n”); scanf(“%d”,&b);
e=a*b;
printf(“\nMultiplication of two numbers=%d”,e);
break;
case 4:
printf(“\nEnter the first number =\n”); scanf(“%d”,&a);
printf (“\nEnter the second number =\n”); scanf(“%d”,&b);
f=a/b;

3
printf(“\nDivision of two numbers=%d”,f);
break;
case 5:
printf(“\nTHANKS”);
break;
}
getch();
}

PROGRAM 6:

Write a program to convert the temperature entered in Fahrenheit to


Celsius [c=f-32.0/1.8]

#include<stdio.h>
#include<conio.h>
void main()
{
float f,c;
clrscr();
printf(“Enter the Fahrenheit value=\n”);
scanf(“%f”,&f);
c=((f-32.0)/1.8);
printf(“\nCelsius=%f”,c);
getch();
}

PROGRAM 7:

Write a program to find whether a number is even or odd.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(“Enter the number=\n”);
scanf(“%d”,&a);
b=(a%2);
if(b==0)
{
printf(“\n%d is Even Number”,a);

4
}
else
{
printf(“\n%d is Odd Number”,a);
}
getch();
}

PROGRAM 8:

Write a program to accept 10 numbers and find the biggest among


them.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10];
int i,j,temp;
clrscr();
printf(”Enter the number=\n”);
for(i=0;i<=9;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<=9;i++)
{
for(j=i+1;j<=10;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[j]=a[i];
a[j]=temp;
}
}
}
printf(“\n The Biggest Number=%d”,temp);
getch();
}

You might also like