[go: up one dir, main page]

0% found this document useful (0 votes)
13 views3 pages

c Language Nots

The document contains a series of C programming examples demonstrating basic programming concepts such as checking if a number is odd or even, calculating factorials, generating multiplication tables, and determining total expenses with discounts. It also includes programs for employee bonus eligibility based on years of service and driver insurance eligibility based on marital status, sex, and age. Each example is presented with code snippets and brief descriptions of their functionality.

Uploaded by

vimalyadevr
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)
13 views3 pages

c Language Nots

The document contains a series of C programming examples demonstrating basic programming concepts such as checking if a number is odd or even, calculating factorials, generating multiplication tables, and determining total expenses with discounts. It also includes programs for employee bonus eligibility based on years of service and driver insurance eligibility based on marital status, sex, and age. Each example is presented with code snippets and brief descriptions of their functionality.

Uploaded by

vimalyadevr
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
You are on page 1/ 3

1) To check wheather it is odd or even

#include <stdio.h>

int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}
return 0; }

2) to find the number by anoyher number:

#include<stdio.h>
int main()
{
inta,b;
a=9;
b=a+7;
printf("the value of b is:%d",b);
return 0; }

3) find the fractorial numbers:

#include<stdio.h>
int main()
{
int num;
int factorial =1;
printf("enter the number:");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
factorial *= i;
}
printf("factorial of %d is %d\n",num,factorial);
return 0; }

4) print the series of values of 3 to 30

#include<stdio.h>
int main()
{
int start =3;
int end=30;
for(int i= start; i<=end; i +=3){
printf("%d",i);
printf("\n");
}
return 0; }
5) to write the 5 tables using while and do while loop :
#include<stdio.h> int main()
{ int
i=1;
printf("multiplication of 5 tables using do while:\n",i);
do{
printf("5 * %d=%d\n",i,5*i);
i++;}
while(i<=10);
return 0;
}

6) While purchasing certain items, a discount of 10% is


offered if the quantity purchased is more than 1000. If
quantity and price per item are input through the keyboard,
write a program to calculate the total expenses.

#include <stdio.h>
int main() {
int quantity;
float price, total;
printf("Enter the quantity: ");
scanf("%d", &quantity);
printf("Enter the price per item: ");
scanf("%f", &price);
total = quantity * price;
if (quantity > 1000) {
total = total * 0.9;
}
printf("Total expenses: %.2f\n", total);
return 0;
}

7) The current year and the year in which the employee


joined the organization are entered through the keyboard.
If the number of years for which the employee has served
the organization is greater than 3 then a bonus of Rs.
2500/- is given to the employee. If the years of service
are not greater than 3, then the program should do nothing.

#include <stdio.h>
int main() {
int current_year, year_joined, years_of_service;
printf("Enter the current year: ");
scanf("%d", &current_year);
printf("Enter the year the employee joined: ");
scanf("%d", &year_joined);
years_of_service = current_year - year_joined;
if (years_of_service > 3) {
printf("The employee is eligible for a bonus of Rs.
2500\n");
} else {
printf("The employee is not eligible for a
bonus.\n"); }
return 0;
}

8) A company insures its drivers in the following cases:


− If the driver is married.
− If the driver is unmarried, male & above 30 years of age.
− If the driver is unmarried, female & above 25 years of
age.

In all other cases the driver is not insured. If the


marital status, sex and age of the driver are the inputs,
write a program to determine whether the driver is to be
insured or not.

#include <stdio.h>
int main() {
char marital_status, sex;
int age;
printf("Enter marital status (m for Married, u for
Unmarried): ");
scanf(" %c", &marital_status);
printf("Enter sex (m for Male, f for Female): ");
scanf(" %c", &sex);
printf("Enter age: ");
scanf("%d", &age);
if (marital_status == 'm' ||
(marital_status == 'u' && sex == 'm' && age > 30)
||
(marital_status == 'u' && sex == 'f' && age > 25))
{
printf("The driver is insured.\n");
} else {
printf("The driver is not insured.\n"); }
return 0;}

9)

You might also like