0% found this document useful (0 votes)
17 views4 pages

Day 1 - Code & Homework

The document outlines a series of basic programming exercises in C, including printing 'Hello World', taking user input for personal details, and implementing a basic calculator. It also covers swapping numbers, calculating areas of geometric shapes, and includes additional tasks like calculating simple interest and checking even or odd numbers. Each program is accompanied by example code and prompts for user interaction.

Uploaded by

ankit56kumar77
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)
17 views4 pages

Day 1 - Code & Homework

The document outlines a series of basic programming exercises in C, including printing 'Hello World', taking user input for personal details, and implementing a basic calculator. It also covers swapping numbers, calculating areas of geometric shapes, and includes additional tasks like calculating simple interest and checking even or odd numbers. Each program is accompanied by example code and prompts for user interaction.

Uploaded by

ankit56kumar77
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

Day 1 – Basics + Operators + I/O (10 Programs) ​


1. Print “Hello World” program

#include <stdio.h>
int main () {
printf("Hello World");
return 0;
}

#include <stdio.h>
void main () {
printf("Hello World");
}

2. Take input and display user details (name, age, marks)

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

char name[30];
int age;
int marks;

printf("Enter your name: ");


scanf("%s", name);
printf("Enter your age: ");
scanf("%d", &age);
printf("Enter your marks: ");
scanf("%d", &marks);

printf("=> Name: %s\n", name);


printf("=> Age: %d\n", age);
printf("=> Marks: %d\n", marks);

return 0;
}

Learn all Programs by Harshit: [Call/WhatsApp: 980 190 7094]


3. Basic Calculator (using operators)

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

int x, y, sum, diff, pro, quo, rem;

printf("Enter two numbers\n");


scanf("%d%d", &x, &y);

sum = x + y;
diff = x - y;
pro = x * y;
quo = x / y;
rem = x % y;

printf("Sum: %d\n", sum);


printf("Difference: %d\n", diff);
printf("Product: %d\n", pro);
printf("Quotient: %d\n", quo);
printf("Remainder: %d\n", rem);

return 0;
}

Learn all Programs by Harshit: [Call/WhatsApp: 980 190 7094]


4. Swap two numbers (without using third variable)

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

int x, y, temp;

printf("Enter two numbers\n");


scanf("%d%d", &x, &y);

printf("X = %d, Y = %d \n\n", x, y);


temp = x;
x = y;
y = temp;
printf("X = %d, Y = %d \n", x, y);

return 0;
}

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

int x, y;

printf("Enter two numbers\n");


scanf("%d%d", &x, &y);

printf("X = %d, Y = %d \n\n", x, y);


x = x + y;
y = x - y;
x = x - y;
printf("X = %d, Y = %d \n", x, y);

return 0;
}

Learn all Programs by Harshit: [Call/WhatsApp: 980 190 7094]


HOME WORK

5. Area of Circle, Rectangle, Triangle

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

int l, b, area;
float radius, areaCircle;
int base, per;
float areaTriangle;

printf("Enter the length: ");


scanf("%d", &l);
printf("Enter the breadth: ");
scanf("%d", &b);
area = l * b;
printf("Area of Rectange: %d\n\n", area);

printf("Enter the radius: ");


scanf("%f", &radius);
areaCircle = 3.14 * radius * radius;
printf("Area of Circle: %.2f\n\n", areaCircle);

printf("Enter the Base: ");


scanf("%d", &base);
printf("Enter the Perpendicular: ");
scanf("%d", &per);
areaTriangle = 0.5 * (l * b);
printf("Area of Triangle: %.2f\n\n", areaTriangle);

return 0;
}

6. Simple Interest Calculator

7. Convert Celsius to Fahrenheit

8. Check Even or Odd number

9. Find largest of two numbers

[Link] sum and average of 3 number

Learn all Programs by Harshit: [Call/WhatsApp: 980 190 7094]

You might also like