0% found this document useful (0 votes)
32 views

C Programs (Basics) For Beginners

This document contains a number of C programs and their outputs for begginers and will help them understand the basics of C programming.

Uploaded by

Anonymousdude
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

C Programs (Basics) For Beginners

This document contains a number of C programs and their outputs for begginers and will help them understand the basics of C programming.

Uploaded by

Anonymousdude
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1. Input a number and print if is a positive, negative or zero.

#include<stdio.h>

int main(){

int a;

printf("Enter a number : ");

scanf("%d",&a);

if(a>0){

printf("The number is positive");

else if(a<0){

printf("The number is negative");

else{

printf("The number is zero");

Output:

2.) Input a number and print if it is even or odd.


#include<stdio.h>

int main(){

int a;

printf("Enter a number : ");

scanf("%d",&a);

int c = a%2;

if(c==0){
printf("The number is even");

else{

printf("The number is odd");

Output:

3.) Input the day of a week and print holiday or working day.
#include<stdio.h>

int main(){

int a;

printf("Enter a day of the


week\n1.)sunday\n2.)monday\n3.)tuesday\n4.)wednesday\n5.)thursday\n6.)friday\n7.)saturday\n")
;

scanf("%d",&a);

if(a!=7 or a !=1){

printf("Its is working day");

else{

printf("It is holiday");

Output:
4.) Input any number and check whether the given no is divisible by 3 and 7
or not.
#include<stdio.h>

int main(){

int a,b,c;

printf("Enter a number : ");

scanf("%d",&a);

b = a%3;

c= a%7;

if(b==0 && c==0){

printf("It is divisible by both 3 and 7");

else{

printf("It is not divisible by 3 and 7");

Output:
5.) Input three numbers and display the smallest one.
#include<stdio.h>

int main(){

int a,b,c;

printf("Enter three numbers : ");

scanf("%d,%d,%d",&a,&b,&c);

if(a<b && a<c){

printf("%d is smallest",a);

else if(b<c && b<a){

printf("%d is smallest",b);

else{

printf("%d is smallest",c);

Output:

6.) Input the angles of a triangle and decide it is scalene, isosceles or


equilateral.
#include<stdio.h>

int main(){

int a,b,c;
printf("Enter 3 angles of a triangle : ");

scanf("%d,%d,%d",&a,&b,&c);

if(a==b&&b==c){

printf("It is equilateral");

else if(a==b || b==c || a==c){

printf("It is isoceles");

else{

printf("It is scalene");

Output:

7.) Input the sides of triangle and decide if it is right angled, obtuse or acute.
#include<stdio.h>

int main(){

int a,b,c;

printf("Enter 3 angles of a triangle : ");

scanf("%d,%d,%d",&a,&b,&c);

if (a==90 || b==90 || c==90){

printf("It is right angled triangle");

else if (a>90 || b>90 || c>90){

printf("It is obtuse angled triangle");

}
else{

printf("It is acute angled triangle");

Output:

8.) Input any three numbers and display the middle number.
#include<stdio.h>

int main(){

int a,b,c;

printf("enter three numebers : ");

scanf("%d,%d,%d",&a,&b,&c);

if((a>b &&a<c)||(a<b &&a>c)){

printf("%d is middle number",a);

else if((b>a &&b<c)||(b<a &&b>c)){

printf("%d is middle number",b);

else{

printf("%d is middle number",c);

Output:
9.) Program to display the area of rectangle, circle, triangle using else if
ladder.
#include<stdio.h>

int main(){

int o,r,l,b,h;

printf("1.)Circle\n2.)Rectangle\n3.)Triangle\n");

scanf("%d",&o);

if(o==1){

printf("Enter the radius of the circle : ");

scanf("%d",&r);

int area = 3.14 * (r^2);

printf("The area of the triangle is : %d",area);

else if(o==2){

printf("Enter the length and breadth of the rectangle : ");

scanf("%d,%d",&l,&b);

int area = l*b;

printf("The area of the rectangle is %d",area);

else{

printf("Enter the base and height of the triangle : ");

scanf("%d,%d",&b,&h);

int area = (1/2)*b*h;

printf("The area of the triangle is : %d",area);

}
Output :

10.) Write a c program to test whether a candidate is eligible for job or not.

#include<stdio.h>

int main(){

int a,b;

printf("Do you have a bachelors degree ?\n 1.)Yes\n2.)No\n ");

scanf("%d",&a);
printf("Do you have intermediate degree and minimum 5 years’ experience.?\n 1.)Yes\n2.)No \n");

scanf("%d",&b);

if(a==1 || b==1){

printf("You are qualified for the job");

else{

printf("You are not qualified for the job");

Output:

You might also like