// besically switch case statement is a conviniance stuff for user.
// syntex for switch case statement is that
/*
{ int a;
switch (a){
case 3;
printf ("valuec is 2");
case 4;
printf ("value id 4")
..
..
default:
printf ("noting matched")
}
rules for a switch case statement
1. The switch expression must be an integer or character.
2. The case also must be an integer or character.
3. break isn't a must.
4. The case must come inside the switch.
5. break ke bad wala switch statement execute nhi hota break is used to
terminate code.
6. switch ke ander bhi switch statement dala ja sakta he.
*/
#include <stdio.h>
int main ()
{
int age;
printf ("enter your age:\n");
scanf ("%d", & age);
int marks;
printf ("enter your marks:\n");
scanf ("%d", & marks);
switch (age)
{
case 3:
printf("your age is 3\n");
switch (marks)
{
case 9:
printf ("your marks are 9\n");
break;
default:
printf ("your marks aren't 9\n");
break;
}
break;
case 13:
printf("your age is 13\n");
break;
case 23:
printf ("your age is 23\n");
break;
default:
printf ("age isn't 3,13 & 23");
break;
}
return 0;
}
additional:_2
#include <stdio.h>
void main()
{
char name;
int code;
printf("enter the code\n");
printf("enter 1 to print your first name:\n");
printf("enter 2 to print your last name:\n");
scanf ("%d",&code);
switch (code)
{
case 1:
printf ("my first name is hemansh\n");
break;
case 2:
printf ("my last name is mishra\n");
break;
default:
break;
}
return 0;
}
// pw course fee assitent program
/*#include <stdio.h>
int main()
{
int num;
char name;
printf ("enter your name\n");
scanf ("%c", &name);
printf ("enter the class course of which you want to buy:\n");
scanf ("%d", &num);
switch (num)
{
case 10:
printf ("Fee of your course is ₹2499/-\n");
break;
case 11:
printf ("Fee of your course is ₹3499/-\n");
break;
case 12:
printf ("Fee of your course is ₹4499/-\n");
break;
default:
printf ("no course is available for you.\n");
break;
return 0;
}
}*/
//modified form of this is below.
// project:_16 (pw home page with switch statement)
#include<stdio.h>
int main()
{
char name[20];
int num;
char mail[20];
int class;
printf ("Please enter your name: \n");
scanf ("%s", &name);
printf ("Please enter your contect number: \n");
scanf ("%d", &num);
printf ("Please enter your contect EMAIL ID: \n");
scanf ("%s", &mail);
printf ("enter the class of whose course you want: \n");
scanf ("%d", &class);
printf ("%s, you have entered %dth as your class, ",name,class);
switch (class)
{
case 10:
printf ("fee for class %dth course is ₹2499 only.\n", class);
break;
case 11:
printf ("fee for class %dth course is ₹3499 only.\n", class);
break;
case 12:
printf ("fee for class %dth course is ₹4499 only.\n", class);
break;
default:
printf (" sorry! %s there is no course available for class %dth at this time.\n", name,class);
printf ("we will notify you when course will available for class %dth.\n", class);
break;
}
}
output:_
Please enter your name:
prafull
Please enter your contect number:
9057513102
Please enter your contect EMAIL ID:
prafull07@gmail.com
enter the class of whose course you want:
10
prafull, you have entered 10th as your class, fee for class 10th course is ₹2499 only.
// exercise:_1 (claculator)
#include <stdio.h>
int main()
{
char name[20];
printf ("Enter your name: ");
scanf ("%s", &name);
printf ("Hello %s! welcome to NUMBx your maths friend toolkit,\n");
printf ("who is always prepare to solve your mathemetical problems,\n");
printf ("So let's begin.\n");
float a,b;
printf ("a: ");
scanf ("%f", &a);
printf ("b: ");
scanf ("%f", &b);
int o;
printf ("press 1 for addtion.\n");
printf ("press 2 for substraction.\n");
printf ("press 3 for multiply.\n");
printf ("press 4 for divide.\n");
scanf ("%d", &o);
switch (o)
{
case 1:
printf ("The result is: %.2f\n", a+b);
break;
case 2:
printf ("The result is: %.2f\n", a-b);
break;
case 3:
printf ("The result is: %.2f\n", a*b);
break;
case 4:
printf ("The result is: %.2f\n", a/b);
break;
default:
printf ("sorry! you have entered wrong input.\n");
break;
}
printf ("thanks for using NUMBx.");
return 0;
}
output:_
Enter your name: prafull
Hello prafull! welcome to NUMBx your maths friend toolkit,
who is always prepare to solve your mathemetical problems,
So let's begin.
a: 203
b: 10.15
press 1 for addtion.
press 2 for substraction.
press 3 for multiply.
press 4 for divide.
4
The result is: 20.00
thanks for using NUMBx.
No comments:
Post a Comment
here we are to help you.you can watch videos and get information about :- (1) scientific facts (2) education (3) gaming (4) music (5) lyrics (6) cartoons and many more.So keep watching keep learning, thank you.