0% found this document useful (0 votes)
48 views8 pages

Decision Making 1

The document contains 19 code snippets in C programming language that solve various problems involving conditional statements like if-else. The problems include finding the greatest of two or three numbers, determining if a number is positive or negative, identifying the quadrant of x-y coordinates, checking eligibility for placement based on academics, calculating electricity bill based on units consumed, and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views8 pages

Decision Making 1

The document contains 19 code snippets in C programming language that solve various problems involving conditional statements like if-else. The problems include finding the greatest of two or three numbers, determining if a number is positive or negative, identifying the quadrant of x-y coordinates, checking eligibility for placement based on academics, calculating electricity bill based on units consumed, and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Greatest of 2 num
#include<stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a>b)
printf("%d is greater",a);
else
printf("%d is greater",b);
}
2. Greatest of 3 num
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);

if (a>b && a>c)


printf("%d is greater",a);
else if(b>a && b>c)
printf("%d is greater",b);
else
printf("%d is greater",c);//Fill your code
}
3. positive or negative
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if(a>0)
printf("Positive");
else if(a<0)
printf("Negative");
else
printf("zero is neither possitive nor negative");//fill your code
}
4. quadrants
#include<stdio.h>
int main()
{
int x,y;
scanf("%d%d",&x,&y);
if (x>0 && y>0)
printf("Ist Quadrant");
else if (x<0 && y>0)
printf("IInd Quadrant");
else if (x<0 && y<0)
printf("IIIrd Quadrant");
else if (x>0 && y<0)
printf("IVth Quadrant");
else
printf("Origin");//fill your code
}
5. game with shapes
#include<stdio.h>
int main()
{
int x,r,d;
scanf("%d%d",&r,&x);
d=2*r;
if(d<=x)
printf("circle can be inside a square");
else
printf("circle cannot be inside a Square");
//Fill your code
}
6. boating
#include<stdio.h>
int main()
{
int wh,nA,nC;
wh=600;
nA=7;
nC=4;
int wA=nA*75;
int wC=nC*30;
if(wh>(wA+wC))
printf("Boat is stable");
else
printf("Boat will drow");

}
7. car race
#include<stdio.h>
int main()
{
int A,B,C,car;
scanf("%d%d%d%d",&A,&B,&C,&car);
if(A%car==0)
printf("Car 1 goes into road A");
else if (B%car==0)
printf("Car 1 goes into road B");
else if (C%car==0)
printf("Car 1 goes into road C");
else
printf("No path exist");
}
8. automorphic num
#include<stdio.h>
int main()
{
int a,b;
scanf("%d",&a);
b=a%10;
if(b==0||b==1||b==5||b==6)
printf("Automorphic Number");
else
printf("Not Automorphic Number");

}
9. electricity bill
#include<stdio.h>
#include<math.h>
int main()
{
int a;
float c;
scanf("%d",&a);
if (a<=200)
c=ceil(0.5*a);
else if (200<a && a<=400)
c=ceil(0.65*a+100);
else if (400<a && a<=600)
c=ceil(0.80*a+200);
else
c=ceil(1.25*a+425);

printf("Rs.%d",(int)c);
}
10. ASCII values 1
// C program to check whether a given character is upper case, lower case, number or special
character

#include<stdio.h>
int main()
{
//Fill the code
char ch;
scanf("%c",&ch);
//int cha =(int)ch;
if(ch >= 65 && ch <= 90)
printf("Upper");
else if(ch >= 97 && ch<= 122)
printf("Lower");
else if(ch >= 48 && ch <= 57)
printf("Number");
else
printf("Symbol");

return 0;
}
11. eligibility for placaments
#include<stdio.h>
int main()
{

int a,r;
float cgpa;
char name[100];
scanf("%s%d%f%d",&name,&r,&cgpa,&a);

printf("%s\n", name);
printf("%d\n",r);
if(a==0 && cgpa>=7.0)
printf("Eligible to attend placement");
else if ((a==1||a==2) && cgpa>=7.5)
printf("Eligible to attend placement");
else
printf("Not Eligible to attend placement");
return 0;
}
12. gift for birthday
#include<stdio.h>
int main()
{
int year;
scanf("%d",&year);
if(((year%4==0) && ((year%400==0) || (year%100!=0))))
{
printf("%d is a leap year", year);
}
else {
printf("%d is not a leap year", year);
return 0;
} }
13. car milage
#include<stdio.h>
int main()
{
float milage;
int lit, dist;
scanf("%f%d%d",&milage,&lit,&dist);
if(dist>milage*lit)
{
printf("Cannot reach");
}
else
{
printf("Can reach");
}
}
14. swimming pool
#include<stdio.h>
#include<math.h>
int main()
{
int l,ltrs,y;
scanf("%d%d",&l,&ltrs);
y=pow(l,3);
ltrs=(float)ltrs/1000;

if (y>ltrs)
{ printf("Can store");
}
else
{printf("Cannot store");}

}
15. gardening
#include<stdio.h>
int main()
{
int r,c,t,tt,lbo,lbt,fbo,fbt;
scanf("%d%d%d",&r,&c,&t);
tt=r*c;
lbo=tt-r;
lbt=tt-2*r+1;
fbo=r+r;
fbt=r+1;//6
if(((t>=fbt)&&(t<=fbo))||((t>=lbt)&&(t<=lbo)))
{
printf("It is a mango tree");
}
else
{
printf("It is not a mango tree");
}
}
16. digit to word
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
switch(num)
{
case 0:
printf("Zero");
break;
case 1:
printf("one");
break;
case 2:
printf("Two");
break;
case 3:
printf("three");
break;
case 4:
printf("four");
break;
case 5:
printf("Five");
break;
case 6:
printf("Six");
break;
case 7:
printf("seven");
case 8:
printf("eight");
break;
case 9:
printf("nine");
break;
default:
printf("Invalid input! Please enter week number between 1-7.");
}}

17. cricket
#include<stdio.h>
int main()
{
int balls,runs,rs,bb;
scanf("%d%d%d%d",&balls,&runs,&rs,&bb);
int overs=balls/6;
int of=bb/6;
float Eb=bb%6;
float x=(float)of;
x=x+(Eb/10);
int to=balls/6;
int FBO=bb/6;
float Eo=bb%6;
float BB=FBO+Eo/10;
float crr=rs/BB;
float trr=(float)runs/overs;
printf("%d\n%.1f\n%.1f\n%.1f\n",to,x,crr,trr);
if(crr>trr)
{printf("Eligible to Win");}
else{
printf("Not Eligible to Win");}
}
18. calendar
#include<stdio.h>
int main()
{
int month,year,n;
scanf("%d%d",&month,&year);
n=month;
switch (n)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("Number of days is 31");
break;
case 2:
if(((year%4==0) && ((year%400==0) || (year%100!=0))))
{ printf("Number of days is 29");}
else{printf("Number of days is 28");}
break;
case 4:
case 6:
case 9:
case 11:

printf("Number of days is 30");


break;
default:
printf("invalid input");
}

}
19. ASCII values
#include<stdio.h>
int main()
{
char vowel;
scanf("%c",&vowel);
if(vowel=='A'||vowel=='E'||vowel=='I'||vowel=='O'||vowel=='U'||vowel=='a'||vowel=='e'||
vowel=='i'||vowel=='o'||vowel=='u')
{
printf("ASCII of %c is %d",vowel,(int)vowel);
}
else
{
printf("Not a vowel");
}
}

You might also like