c Language Nots
c Language Nots
#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; }
#include<stdio.h>
int main()
{
inta,b;
a=9;
b=a+7;
printf("the value of b is:%d",b);
return 0; }
#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; }
#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;
}
#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;
}
#include <stdio.h>
int main() {
int current_year, year_joined, years_of_service;
printf("Enter the current year: ");
scanf("%d", ¤t_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;
}
#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)