You are on page 1of 7

Example 1:

Write a C program that calculates the sum of two input numbers, and display the result.

Algorithm:

Input Enter two numbers (n1,n2)


Process Compute the sum (sum=n1+n2)
Output Display the sum (sum)

Solution:

#include
main ( )
{
int sum, n1,n2;
clrscr ( );
printf (“\n Enter two nos.”);
scanf (“%d%d”, &n1, &n2);
sum=n1+n2;
printf (“\n The sum: %d”, sum);
getch ( );
}

Example 2:

Write a program to calculate the area of a circle and display the result. Use the
formula: A=pi*r2 where Pi (?) is approximately equal to 3.1416.

Algorithm:

Input Enter the radius (r)


Process Compute the Area (A=Pi*r*r)
Output Display the Area (A)

Solution:

#include
#define Pi 3.1416
main ( )
{
int r;
flaot A;
clrscr ( );
printf (“\n Enter the radius:”);
scanf (“%d”, &r);

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
A=Pi*r*r;
printf (“\n The area: %f”,A);
getch ( );
}

Example 3:

Write a program that computes the average of three input quizzes, then display the
result.

Algorithm:

Input Enter three quizzes (q1,q2,q3)


Process Compute the average (ave=(q1+q2+q3/3)
Output Display the average (ave)

Solution:

#include
main ( )
{
int q1,q2,q3;
flaot ave;
clrscr ( );
printf (“\n Enter three quizzes:”);
scanf (“%d%d%d”,&q1,&q2,&q3);
ave= (q1+q2+q3) /3;
printf (“\n The average:%f”,ave);
getch ( );
}

Example 4:

Write a program that converts the input Fahrenheit degree into its Celsius degree
equivalent. Use the formula: C=(5/9) *F-32. Display the result.

Algorithm:

Input Enter the Fahrenheit (f)


Process Compute the Celsius (C=(5.0/9.0)*F-32.0)
Output Display the Celsius

Solution:

#include

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
main ( )
{
flaot c,f;
clrscr ( );
printf (“\n Enter the Fahrenheit:”);
scanf (“%f”, &f);
c= (5.0/9.0)*f-32.0;
printf (“\n the Celsius:%f”,c);
getch ( );
}

Example 4:

The C program which requests the user to enter the length of a side and prints the area of
the square is shown here:
#include
main () {
int a, s;
printf ("Enter length of side: ");
scanf ("%d", &s); //store length in s
a = s * s; //calculate area; store in a
printf ("\nArea of square is %d\n", a);
}

Example 5:

%AGE OF TOTAL MARKS

TO FIND OUT TOTAL MARKS & PERCENTAGE OF THREE SUBJECTS

Void main ()
{
int m1,m2,m3;
float tm,per;
clrscr ();
printf ("Enter M1: ");
scanf ("%d",&m1);
printf ("Enter M2: ");
scanf ("%d",&m2);
printf ("Enter M3: ");
scanf ("%d",&m3);

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
tm=m1+m2+m3;
per=(tm/300*100);
printf ("\nTotal Marks are %.2f",tm);
printf ("\nPercentage is %.2f",per);
getch ();
}

Example 6:

calculate the power in watts

#include
int main()
{
float power,voltage,current;
voltage = current = 0;

printf("Power calculator.\n");
printf("This will calculate the power in watts , ");
printf("when you input the voltage and current.");
printf("Enter the voltage in volts.\n");
scanf("%f",&voltage);
printf("Enter the current in amps.\n");
scanf("%f",¤t);
/*calculate the power*/
power = voltage * current;
printf("The power in watts is %.2f watts\n",power);

getch 0;
}

Example 7:

INCREMENTAL / DECREMENTAL

TO ADD 1 & SUBTRACT 1 FROM VALUE OF A & B

(INCREMENTAL & DECREMENTAL OPERATORS)

void main ()
{
int a,b;
clrscr();
printf ("Enter A: ");
scanf ("%d",&a);
printf ("Enter B: ");

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
scanf ("%d",&b);
a++;
b--;
printf ("\nA is %d",a);
printf ("\nB is %d",b);
getch ();
}

Example 8:

GETCH ( ) FUNCTION
TO ENTER CHARACTER BY USING GETCH ( ) FUNCTION
#include
void main ()
{
char ch;
clrscr ();
printf ("Enter any character: ");
ch=getch();
printf ("You have pressed %c",ch);
getch ();
}

Example 9:
TO FIND OUT QUARDRATIC EQUATION (D=B2-4AC)
void main ()
{
int a,b,c,d;
clrscr ();
printf ("Enter A: ");
scanf ("%d",&a);
printf ("Enter B: ");
scanf ("%d",&b);
printf ("Enter C: ");
scanf ("%d",&c);
d= (b*b)-(4*a*c);
printf ("\nAnswer is %d",d);
getch ();
}

Example 10:

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
PRINT NAME 10 TIMES

#include<stdio.h>
#include<conio.h>
main()
{
for(int a=1;a<=10;a++)
{
printf("Bismah\n"); }
getch();
}

Example 11:

#include<stdio.h>
#include<conio.h>
main()
{
for(int a=1;a>=10;a--)
{
printf("%d\n",a ); }
getch();
}

Example 12:

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int cube,squaret,square;
for(int a=1;a<=10;a++)
{
square=pow(a,2);
cube=pow(a,3);
squaret=sqrt(a);
printf("%d: %d :%d:%d\n",a,square,cube,squaret ); }
getch();
}

This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
This study source was downloaded by 100000805372844 from CourseHero.com on 09-23-2022 08:44:05 GMT -05:00

https://www.coursehero.com/file/92742987/c-programs-exampledoc/
Powered by TCPDF (www.tcpdf.org)

You might also like