Popc - Sample Programs
Popc - Sample Programs
Popc - Sample Programs
#include<stdio.h>
main()
{
printf(“Hello World”);
}
#include<stdio.h>
main()
{
int a; /* declaration of variable a */
a=10; /* initialization of variable a*/
printf(“The value of a is %d”, a);
}
#include<stdio.h>
main()
{
float a;
a=10.50;
printf(“The value of a is %d”, a);
}
#include<stdio.h>
main()
{
int a=10; /* declaration and initialization are done in same line */
printf(“The value of a is %d”, a);
}
#include<stdio.h>
main()
{
int a=10, b=50 ; /* declaration and initialization are done in same line */
printf(“The value of a is %d %d”, a,b);
}
#include<stdio.h>
main()
{
int a = 10, b = 50, c ; /* declaration and initialization are done in same line */
c = a + b;
printf(“The sum is %d”, c);
}
c = a + b;
printf(“The sum is %d”, c);
}
Similarly write the program for subtraction, multiplication
#include<stdio.h>
main()
{
int a , b, sum,sub,mul ; /* declaration part */
printf(“Enter the values for a and b”);
scanf(“%d %d”, &a, &b); /* scanf is used to read input from user */
sum = a + b;
sub = a - b;
mul = a * b;
printf(“The result of addition is sum is %d”, sum);
printf(“The result of subtraction is %d”, sub);
printf(“The result of multiplication is %d”, mul);
}
#include<stdio.h>
main()
{
float pi = 3.148 , area, radius; /* declaration part */
printf(“Enter the value for radius of a circle”);
scanf(“%f”, &radius);
area = pi * radius * radius;
printf(“the area of a circle is %f”, area);
}
#include<stdio.h>
main()
{
int a,b,temp; /* declaration part */
printf(“Enter the value for a and b”);
scanf(“%d %d”, &a,&b);
printf(“The value of a and b before swapping %d %d”, a, b);
temp = a;
a = b;
b = temp;
printf(“The value of a and b after swapping %d %d”, a, b);
}
#include<stdio.h>
main()
{
float celsius, fahrenheit ; /* declaration part */
printf(“Enter the value for celsius”);
scanf(“%f”, &celsius);
fahrenheit = (1.8 * celsius) + 32;
printf(“The temperature in fahrenheit is %f”, fahrenheit);
}
#include<stdio.h>
main()
{
int length,breadth; /* declaration part */
printf(“Enter the value for length and breadth”);
scanf(“%d %d”, &length,&breadth);
printf(“The area of rectangle is: %d”,(length * breadth));
printf(“The perimeter of rectangle is: %d”, 2 * (length + breadth));
#include<stdio.h>
#include<math.h>
main()
{
int a , res;
printf(“enter the value of a”);
scanf(“%d”,&a);
res = sqrt(a);
printf(“the square root of a is %d”, res);
}
#include<stdio.h>
main()
{
char c;
printf(“enter the character”);
scanf(“%c”, c);
printf(“ASCII value of %c = %d”,c,c);
}
#include<stdio.h>
main()
{
float b,h,area;
printf(“enter the values of b and h”);
scanf(“%f %f”,&b , &h);
aea = (b * h)/2;
printf(“the area of a triangle is %f”, area);
}
#include<stdio.h>
main()
{
int x;
printf(“enter the values of x”);
scanf(“%d”, &x);
printf(“The sin value of x is %d”, sin(x));
printf(“The cos value of x is %d”, cos(x));
printf(“The tan value of x is %d”, tan(x));
}
18. To Round-up and Round-down the value
#include<stdio.h>
main()
{
foat x = 4.7;
printf(“The Round-up value of x is %f”, ceil(x));
printf(“The Round-down value of x is %f”, floor(x));
}
#include<stdio.h>
main()
{
int a, b;
printf(“enter the value of a”);
scanf(“%d”,&a);
printf(“enter the value of b”);
scanf(“%d”,&b);
int avg=(a+b)/2;
printf(“the average of two values is %d”,avg);
}