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

C Basic Programms

The document contains 13 code snippets demonstrating basic C programming concepts like input/output, arithmetic operations, area calculations, averages, and swapping variables. Specifically, it includes programs to add, subtract, multiply and divide two numbers, calculate the area of rectangles, squares, circles and triangles, find student marks averages, calculate simple interest, and swap variables with and without a third variable.

Uploaded by

aish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

C Basic Programms

The document contains 13 code snippets demonstrating basic C programming concepts like input/output, arithmetic operations, area calculations, averages, and swapping variables. Specifically, it includes programs to add, subtract, multiply and divide two numbers, calculate the area of rectangles, squares, circles and triangles, find student marks averages, calculate simple interest, and swap variables with and without a third variable.

Uploaded by

aish
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Addition two Numbers:


#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
c=a+b;
printf("Sub=%d",c);
}
2.Subtraction of two numbers:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
c=a-b;
printf("Sub=%d",c);
}
3.Multiplication of two Numbers:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
c=a*b;
printf("Mul=%d",c);
}
4.Division of two numbers:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter first number\n");
scanf("%d",&a);
printf("Enter second number\n");
scanf("%d",&b);
c=a\b;
printf("Div=%d",c);
}
5.Area of Rectangle:
int main()
{
int area,h,w;
printf("Enter height of rectangle\n");
scanf("%d",&h);
printf("Enter width of rectangle\n");
scanf("%d",&w);
area=h*w;
printf("Area of rectangle=%d",area);
}
6.Area of square:
int main()
{
int area,side;
printf("Enter side of square\n");
scanf("%d",&h);
area=side*side;
printf("Area of square=%d",area);
}
7.Area of circle:
#include<stdio.h>
int main()
{
float area,r;
printf("Enter radius of circle\n");
scanf("%f",&r);
area=3.14*r*r;
printf("Area of rectangle=%f",area);
}
8.Area of triangle:
#include<stdio.h>
int main()
{
float area,base,height;
printf("Enter base \n");
scanf("%f",&base);
printf("Enter height \n");
scanf("%f",&height);
area=0.5*base*height;
printf("Area of triangle=%f",area);
}
9.Student five subject marks with total and average
#include<stdio.h>
int main()
{
float p,c,m,h,e,avg;
printf("Enter marks in physics \n");
scanf("%f",&p);
printf("Enter marks in chemistry \n");
scanf("%f",&c);
printf("Enter marks in math \n");
scanf("%f",&m);
printf("Enter marks in hindi \n");
scanf("%f",&h);
printf("Enter marks in english \n");
scanf("%f",&e);
avg=(p+c+m+h+e)/5;
printf("Average of result=%f",avg);
}
10. Simple Interest:
#include<stdio.h>
int main()
{
float p,r,t,si;
printf("Enter principle\n");
scanf("%f",&p);
printf("Enter rate of interest \n");
scanf("%f",&r);
printf("Enter time \n");
scanf("%f",&t);
si=(p*r*t)/100;
printf("Simple Interest=%f",si);
}
11. method1: Swapping using third variable
#include<stdio.h>
int main()
{
int a=10,b=20,c;
printf("Before swapping a=%d and b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("After swapping a=%d and b=%d\n",a,b);
}
12. Method2: Swapping using third variable

#include<stdio.h>
int main()
{
int a=10,b=20,c;
printf("Before swapping a=%d and b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("After swapping a=%d and b=%d\n",a,b);
}
13. Method3: Swapping without using third variable
#include<stdio.h>
int main()
{
int a=10,b=20,c;
printf("Before swapping a=%d and b=%d\n",a,b);
c=a+b;
a=c-a;
b=c-b;
printf("After swapping a=%d and b=%d\n",a,b);
}
int main()
{
int a=10,b=20;
printf("Before swapping a=%d and b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swapping a=%d and b=%d\n",a,b);
}

You might also like