#include <stdio.
h>
int main() {
int n;
// Input the number of natural numbers to process
printf("Enter the number of natural numbers: ");
scanf("%d", &n);
// Print the square and cube of the first n natural numbers
for (int i = 1; i <= n; i++) {
printf("Number: %d, Square: %d, Cube: %d\n", i, i * i, i * i * i);
}
return 0;
}
#include <stdio.h>
void main()
{
int i,j,n;
printf("Enter n:");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
}
#include <stdio.h>
int main() {
int num, i;
printf("Enter a number: ");
scanf("%d", &num);
if (num <= 1) {
printf("%d is not a prime number.\n", num);
}
for (i = 2; i < num; i++) {
if (num % i == 0) {
printf("%d is not a prime number.\n", num);
}
}
printf("%d is a prime number.\n", num);
return 0;
}
#include<stdio.h>
int main()
{
int age;
printf("Enter age: ");
scanf("%d", &age);
if (age >=18)
{
printf("Elligible to vote.");
}
else
{
printf("Not elligible to vote.");
}
return 0;
}
#include <stdio.h>
int main() {
const float HRA_PERCENTAGE = 0.10;
const float TA_PERCENTAGE = 0.05;
float basic_pay, hra, ta, total_salary;
printf("Enter the basic pay of the employee: ");
scanf("%f", &basic_pay);
hra = HRA_PERCENTAGE * basic_pay;
ta = TA_PERCENTAGE * basic_pay;
total_salary = basic_pay + hra + ta;
printf("The total salary of the employee is: %.2f\n", total_salary);
return 0;
}
#include <stdio.h>
int main() {
int n, i;
float price, quantity, total = 0.0;
printf("Enter the number of grocery items: ");
scanf("%d", &n);
char item_name[50];
for (i = 1; i <= n; i++) {
printf("\nEnter the name of item %d: ", i);
scanf("%s", item_name);
printf("Enter price of %s: ", item_name);
scanf("%f", &price);
printf("Enter quantity of %s: ", item_name);
scanf("%f", &quantity);
total += price * quantity;
}
printf("\nTotal Grocery Bill To Be Paid: %.2f\n", total);
return 0;
}
PROGRAM:
WITH TEMPORARY VARIABLE:
#include<stdio.h>
void main()
{
int a=10,b=20,temp;
temp=a;
a=b;
b=temp;
printf("After swapping:%d %d",a,b);
}
WITHOUT TEMPORARY VARIABLE:
#include<stdio.h>
void main()
{
int a=10,b=20;
a=a+b;
b=a-b;
a=a-b;
printf("After swapping:%d %d",a,b);
}
OUTPUT:
After swapping: 20 10
PROGRAM:
#include<stdio.h>
void main()
{
float r,area;
printf(“Enter the radius:”)
scanf(“%f”,&r);
area=3.14*r*r;
printf("Area:%f",area);
}
OUTPUT:
Enter the radius:3
Area:28.26
PROGRAM:
#include<stdio.h>
void main()
{
char c;
printf("Enter any char:");
scanf("%c",&c);
printf("\nASCII value of %c is %d",c,c);
}
OUTPUT:
Enter any char:A
ASCII value of A is 95
PROGRAM:
#include<stdio.h>
void main()
{
char a,b;
printf("Enter the character in uppercase:");
scanf("%c",&a);
b=a+32;
printf("The character in lowercase is:%c",b);
}
OUTPUT:
Enter the character in uppercase:M
The character in lowercase is:m
:
#include<stdio.h>
void main()
{
float f,c;
printf("Enter the farenheit:");
scanf("%f",&f);
c=0.56*(f-32);
printf("The value in celcius is:%f",c);
}
OUTPUT:
Enter the farenheit:98.6
The value in celcius is:37.295998
PROGRAM:
#include<stdio.h>
#include<math.h>
void main() {
int x1, y1, x2, y2,x,y,distance;
printf("Enter the coordinates of point 1 (x1 y1): ");
scanf("%d %d", &x1, &y1);
printf("Enter the coordinates of point 2 (x2 y2): ");
scanf("%d %d", &x2, &y2);
x = x2 - x1;
y = y2 - y1;
distance = sqrt(x * x + y * y);
printf("Distance is: %d\n", distance);
}
OUTPUT: