0% found this document useful (0 votes)
34 views6 pages

C Program

The document contains 10 C programming examples demonstrating basic concepts like input/output using scanf and printf, calculating areas of geometric shapes, distance between points, arithmetic operations, finding the largest of three numbers, character conversion from uppercase to lowercase, swapping values with and without a temporary variable, calculating a bill amount, and calculating simple and compound interest.

Uploaded by

kevingladson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

C Program

The document contains 10 C programming examples demonstrating basic concepts like input/output using scanf and printf, calculating areas of geometric shapes, distance between points, arithmetic operations, finding the largest of three numbers, character conversion from uppercase to lowercase, swapping values with and without a temporary variable, calculating a bill amount, and calculating simple and compound interest.

Uploaded by

kevingladson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Write a program to demonstrate the use of printf and scanf


statements to read and print values of variables of different
datatypes.
#include <stdio.h>
int main ()
{
int a, b, c;
printf ("Enter the first value:");
scanf("%d", &a);
printf("Enter the second value:");
scanf("%d", &b);
c = a + b;
printf("%d + %d = %d\n", a, b, c);
return 0;
}

2.write a program to calculate the area of a triangle.


#include<stdio.h>
int main ()
{
float b , h, area;
b= 5;
h= 13;
area = (b*h) / 2 ;
printf ("\n\n Area of Triangle is: %f", area);
return 0;
}
3. write a program to calculate the distance between the two points.
#include<stdio.h>

#include<math.h>
void main () {
int x1,x2,y1,y2,distance;
printf(“ enter the points :”);
scanf(“%d%d%d%d”,&x1,&x2&,y1,&y2);

Dis=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
Printf(“Distance between the two points :%d\n”,Dis);
}

4. write a program to perform arithmetic operation.


#include <stdio.h>
int main()
{
int a = 9,b = 4, c;

c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);

c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;

printf("Remainder when a divided by b = %d \n",c);

return 0;
}

5. write a program to find the largest of three numbers using ternary


operator.
#include <iostream>

using namespace std;

int main() {
int num1, num2, num3;
cout << "Enter three numbers: ";
cin >> num1 >> num2 >> num3;

int largest = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 > num3) ? num2 :
num3);

cout << "The largest number is: " << largest << endl;

return 0;
}

6.Write a program to read a character in uppercase and print it in lowercase.


#include<stdio.h>
int main()

{
char uppercase,lowercase;
int ascii;
printf(“Enter a character:”);
scanf(“%c”,&uppercase);

ascii=uppercase;
printf(“ASCCII=%d”,ascii);
lowercase=ascii+32;
printf(“The lowercase character is %d”,lowercase);
return 0;

7.Write a program to swap two numbers using temporary variable.


#include<stdio.h>
int main()
{
int num1,num2,temp;
printf(“Enter the first number:”);

scanf(“%d”,&num1);
printf(“Enter the second number:”);
scanf(“%d”,&num2);
temp=num1;
num1=num2;

num2=temp;
printf(“After swapping, the first number is:%d\n”,num1);
printf(“After swapping, the second number is:%d\n”,num2);
return 0;
}

8.Write a program to swap two numbers without using temporary variable.


#include<stdio.h>
int main()
{

int num1, num2;


printf(“Enter the first number:”);
scanf(“%d”,&num1);
printf(“Enter the second number:”);
scanf(“%d”,&num2);

num1=num1+num2;
num2=num1-num2;
num1=num1-num2;
printf(“After swapping, the first number is:%d\n”,num1);
printf(“After swapping, the second number is:%d\n”,num2);
return 0;
}

9.Write a program to calculate the bill amount of an item,given its quantity


sold,value,discount,tax.

#include <stdio.h>
int main() {
float q=5,v=20,d=5,t=5,amt,dis_amt,tax_amt,sub_total,total;
amt=q*v;
dis_amt=(amt*d)/100;

sub_total=amt-dis_amt;
tax_amt=(sub_total*t)/100;
total=sub_total+tax_amt;
printf("\n\n\n******BILL******\n");
printf("Quantity Sold:%f\n",q);

printf("Price per Item:%f\n",v);


printf("Discount:%f\n",d);
printf("Discounted Total:%f\n",sub_total);
printf("Tax:+%f\n",tax_amt);
printf("\n\n------------------\n\n");

printf("Total Amount:%f",total);
return 0;
}

10.Write a program to calculate simple interest and compound interest.

#include <stdio.h>
int main()
{
float p=2000,t=1,r=1;
float si=(p*t*r)/100;
printf("Simple Interest = %f\n",si);
float amt=p*((pow((1+r/100),t)));
float ci=amt-p;

printf(“Compound Interest =%f”,ci);


return 0;
}

You might also like