Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

Basic C programming codes

Rating
-
Sold
-
Pages
57
Uploaded on
03-06-2023
Written in
2022/2023

The codes provide you clear cut operation of the key words as well as the output is definite for the given codes. These codes are from basic to advanced level.

Institution
Course

Content preview

COMPUTER SCIENCE
BASIC C PROGRAMMING CODES
1. Write a c program to check whether a number is divisible by 5 and 11 or not.
#include <stdio.h>
int main()
{
int num;
printf("Enter any number: ");
scanf("%d", &num);
if((num % 5 == 0) && (num % 11 == 0))
{
printf("Number is divisible by 5 and 11");
}
else
{
printf("Number is not divisible by 5 and 11");
}

return 0;
}

2.Write a C program to check whether a year is a leap year or not.
#include <stdio.h>
int main()
{
int year;
printf("Enter year : ");
scanf("%d", &year);
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))
{
printf("LEAP YEAR");
}
else
{
printf("Not a Leap YEAR");
}

return 0;
}

,3.Write a c program to check whether a character is an alphabet or not.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("Character is an ALPHABET.");
}
else
{
printf("Character is NOT ALPHABET.");
}
return 0;
}

4.Write a c program to input any alphabet and check whether it is vowel or consonant.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||
ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
printf("'%c' is Vowel.", ch);
}
else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is Consonant.", ch);
}
else
{
printf("'%c' is not an alphabet.", ch);
}

, return 0;
}

5.Write a program to check whether it is an alphabet, digit or special character.
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}
return 0;
}
6.Write a c program to input the basic salary of an employee and calculate its gross
salary according to the following:
Basic Salary <= 10000: HRA = 20%, DA = 80%
Basic Salary <= 20000: HRA = 25%, DA = 90%
Basic Salary >20000: HRA = 30%, DA = 95%
#include <stdio.h>
int main()
{
float basic, gross, da, hra;
printf("Enter basic salary of an employee: ");
scanf("%f", &basic);
if(basic <= 10000)
{
da = basic * 0.8;
hra = basic * 0.2;
}

, else if(basic <= 20000)
{
da = basic * 0.9;
hra = basic * 0.25;
}
else
{
da = basic * 0.95;
hra = basic * 0.3;
}
gross = basic + hra + da;
printf("GROSS SALARY OF EMPLOYEE = %.2f", gross);
return 0;
}


7.Write a c program to get an input values x and y, and print x is greater than y.
#include <stdio.h>
int main()
{
int x, y;
printf(“Enter the value of x and y: \n”);
scanf(“%d%d”, &x,&y);
if (x>y)
{
printf("Variable x is greater than y");
}
return 0;
}

8. Write a c program to check the given number is positive or negative with if…else
statement
#include <stdio.h>
int main()
{
int a;
printf("Enter the number a \n");
scanf("%d", &a);
if (a>=0)
{
printf("The value %d is positive number",a);

Written for

Course

Document information

Uploaded on
June 3, 2023
Number of pages
57
Written in
2022/2023
Type
OTHER
Person
Unknown

Subjects

$8.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shriabishek

Get to know the seller

Seller avatar
shriabishek Sastra college
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions