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

C Language Code

The document contains 6 C programs that demonstrate basic concepts: 1) A program that takes a name as input and prints a greeting. 2) A program that takes two numbers as input and prints their sum. 3) A program that takes a number as input and prints whether it is even or odd. 4) A program that takes a year as input and prints whether it is a leap year. 5) A program that takes a number and prints its multiplication table up to 10. 6) A program that takes an operator and two numbers as input and prints the calculation result.

Uploaded by

surajsingh00348
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)
35 views4 pages

C Language Code

The document contains 6 C programs that demonstrate basic concepts: 1) A program that takes a name as input and prints a greeting. 2) A program that takes two numbers as input and prints their sum. 3) A program that takes a number as input and prints whether it is even or odd. 4) A program that takes a year as input and prints whether it is a leap year. 5) A program that takes a number and prints its multiplication table up to 10. 6) A program that takes an operator and two numbers as input and prints the calculation result.

Uploaded by

surajsingh00348
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

1.

HELLO

#include <stdio.h>

int main()

char name[50];

printf("Enter name:");

scanf("%s", &name);

printf("Hello %s" , name );

return 0;

2. SUM OF TWO NUMBERS

#include <stdio.h>

int main() {

int number1, number2, sum;

printf("Enter two integers: ");

scanf("%d %d", &number1, &number2);

// calculate the sum

sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);

return 0;

3.SUM OF TWO NUMBERS

#include <stdio.h>

int main() {

int num;

printf("Enter an integer: ");

scanf("%d", &num);
// true if num is perfectly divisible by 2

if(num % 2 == 0)

printf("%d is even.", num);

else

printf("%d is odd.", num);

return 0;

4. LEAP YEAR

#include <stdio.h>

int main() {

int year;

printf("Enter a year: ");

scanf("%d", &year);

// leap year if perfectly divisible by 400

if (year % 400 == 0) {

printf("%d is a leap year.", year);

// not a leap year if divisible by 100

// but not divisible by 400

else if (year % 100 == 0) {

printf("%d is not a leap year.", year);

// leap year if not divisible by 100

// but divisible by 4

else if (year % 4 == 0) {

printf("%d is a leap year.", year);


}

// all other years are not leap years

else {

printf("%d is not a leap year.", year);

return 0;

5. Multiplication Table Up to 10

#include <stdio.h>

int main() {

int n;

printf("Enter an integer: ");

scanf("%d", &n);

for (int i = 1; i <= 10; ++i) {

printf("%d * %d = %d \n", n, i, n * i);

return 0;

6. Simple Calculator using switch Statement


#include <stdio.h>

int main() {

char op;

double first, second;

printf("Enter an operator (+, -, *, /): ");

scanf("%c", &op);

printf("Enter two operands: ");


scanf("%lf %lf", &first, &second);

switch (op) {

case '+':

printf("%.1lf + %.1lf = %.1lf", first, second, first + second);

break;

case '-':

printf("%.1lf - %.1lf = %.1lf", first, second, first - second);

break;

case '*':

printf("%.1lf * %.1lf = %.1lf", first, second, first * second);

break;

case '/':

printf("%.1lf / %.1lf = %.1lf", first, second, first / second);

break;

// operator doesn't match any case constant

default:

printf("Error! operator is not correct");

return 0;

You might also like