Saturday, 11 December 2021

If-else exercise

 1.my method

#include <stdio.h>

int main()
{
    int sub;

    printf("which subject you have passed:\n",sub);
    printf("if you passed in maths & science then press 1\n",sub);
    printf("if you passed in maths then press 2\n",sub);
    printf("if you passed in science then prees 3\n",sub);
    scanf ("%d", &sub);

    if (sub==1)
    {
        printf("congratulations you well be awarded rupees 500 as fellowship!");
    }

    else if (sub==2)
    {
        printf("congratulations you well be awarded rupees 250 as fellowship!");
    }
   
    else if (sub=3)
    {
        printf("congratulations you well be awarded rupees 250 as fellowship!");
    }

    return 0;

}

2.rectified_method

#include <stdio.h>
int main ()
{
  int sub;

  printf ("In which subject you got first devision\n", sub);
  printf ("if you got first devision in maths & science both then press 1\n",sub);
  printf ("if you got first devision in maths then press 2\n",sub);
  printf ("if you got first devision in science then press 3\n",sub);
  scanf ("%d", &sub);
  if (sub==1)
  {
    printf ("congratulation! you have won ₹500 as fellowship.");
  }
 
  else if (sub==2)
  {
    printf ("congratulation! you have won ₹250 as fellowship.");
   
  }

  else if (sub==3)
  {
    printf ("congratulation! you have won ₹200 as fellowship.");

  }

  else
  {
    printf ("sorry! you aren't eligible for the fellowship progamme.");
   

  }

return 0;

}


method:_2
#include <stdio.h>
int main(int argc, char const *argv[])
{
    int sub;
    printf ("Which Subject you have cleared\n", sub);
    printf ("You have clear maths then press 1\n", sub);
    printf ("You have clear science then press 2\n", sub);
    printf ("You have clear both subjects then press 3\n", sub);
    scanf ("%d",&sub);
   
    if (sub==1)
    {
        printf("you won 15 rupee");
    }
   
    else if (sub==2)
    {
        printf("you won 15 rupee");
    }

    else if (sub==3)
    {
        printf("you won 45 rupee");
    }

    else{
        printf ("sorry you won nothing, better luck next time!");
    }  
   
    return 0;
}
method:_3
#include <stdio.h>
int main()
 {  
  int subject;

 printf("Choose the no.1 if you pass the both subjects also get the 45Rs\n");    
 printf("Choose the no.2 if you pass the maths subjects also get the 15Rs\n");    
 printf("Choose the no.3 if you pass the science subjects also get the 15Rs\n");    
 scanf("%d",&subject);    
 
if(subject==1)    
 
 {      
   printf(" YOu are pass in both subject. so, you get the 45Rs\n");    
 }    
 else if(subject==2)      {        
 printf("You are pass the maths subject .so,you get the 15Rs\n");  
   }    
  else if(subject==3)    
 {      
   printf("You are pass the science subject .so,you get the 15Rs\n");    
 }    
 else    
  {        
   printf("You are fail, so better luck next time\n");  
   }      
return 0;
 }

project:_advance calculator
#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");

    int a,b;
    printf ("A: ");
    scanf ("%d",&a);

    printf ("B: ");
    scanf ("%d",&b);
   
    int o;
    printf ("What optation did you want to be performed.\n");
    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);

    if (o==1)      
    {
        printf ("The result is: %d\n", a+b);    
    }
    else if (o==2)
    {
        printf ("The result is: %d\n", a-b);    
    }
    else if (o==3)
    {
        printf ("The result is: %d\n", a*b);  
    }
    else if (o==4)
    {
        printf ("The result is: %d\n", a/b);
    }

    else
    {
        printf("Sorry you have entered a incorrect input.\n");
    }

    printf ("thanks for using NUMBx.");
    return 0;
}
output:_
Enter your name: puru Hello puru! welcome to NUMBx your maths friend toolkit, who is always prepare to solve your mathemetical problems, So let's begin. A:20
B: 5 What optation did you want to be performed. press 1 for addtion. press 2 for substraction. press 3 for multiply. press 4 for divide. 4 The result is: 4

// project:_9 (switch case)
// exercise_voting
#include <stdio.h>
int main()
{
    char name[20];
    printf ("Enter your name: ");
    scanf ("%s",&name);

    int num;
    printf ("Enter your roll number: ");
    scanf ("%d",&num);
    char mail[20];
    printf ("Enter your student mail address: ");
    scanf ("%s",&mail);
   
    printf ("%s welcome, to student councial voting program.
\n",name);
    int class;
    printf("%s Enter your class to check your eligibility
for voting: ");
    scanf ("%d",&class);
   
    if (class==11,12)      
    {
        printf ("%s you can vote for higher sec. student
councial.\n",name);
        printf("whom you want to give your vote.\n");
        int hvote;
        printf ("press 1 for ABVP: \n");
        printf ("press 2 for NSUI: \n");
        printf ("press 3 for NOTA: \n");
        scanf ("%d",&hvote);

        switch (hvote)
        {
        case 1:
            printf ("%s your vote goes to ABVP.\n",name);
            printf ("Thanks for your vote.");
            break;

        case 2:    
            printf ("%s your vote goes to NSUI.\n",name);
            printf ("Thanks for your vote.");
            break;
       
        case 3:
            printf ("%s your vote goes to NOTA.\n",name);
            printf ("Thanks for your vote.");
            break;

        default:
            printf ("%s you have entered a incorrect input.\n",name);
            break;
        }
       

       
    }
    else if (class==5,6,7,8,9)
    {
        printf ("%s you can vote for sec. student councial.\n",name);
        printf("whom you want to give your vote.\n");
        int svote;
        printf ("press 1 for ABVP: \n");
        printf ("press 2 for NSUI: \n");
        printf ("press 3 for NOTA: \n");
        scanf ("%d",&svote);

        switch (svote)
        {
        case 1:
            printf ("%s your vote goes to ABVP.\n",name);
            printf ("Thanks for your vote.");
            break;

        case 2:    
            printf ("%s your vote goes to NSUI.\n",name);
            printf ("Thanks for your vote.");
            break;
       
        case 3:
            printf ("%s your vote goes to NOTA.\n",name);
            printf ("Thanks for your vote.");
            break;

        default:
            printf ("%s you have entered a incorrect input.\n",name);
            break;
        }
       
    }
    return 0;
}
output:_
Enter your name: hemansh Enter your roll number: 12618 Enter your student mail address: hem55@gmail.com hemansh welcome, to student councial voting program. hemansh Enter your class to check your eligibility for voting: 12 hemansh you can vote for higher sec. student councial. whom you want to give your vote. press 1 for ABVP: press 2 for NSUI: press 3 for NOTA: 1 hemansh your vote goes to ABVP. Thanks for your vote.

// project_11(height checkup)
#include <stdio.h>
int main()
{
    char name[20];
    printf ("Enter your name: ");
    scanf ("%s",&name);

    int num;
    printf ("%s Enter your phone number for further notifications: ",name);
    scanf("%d",&num);

    int height;
    printf ("%s enter your haight(in cms): ",name);
    scanf ("%d",&height);

    if (height>150)
    {
        printf ("%s you are taller then avarage,",name);
        printf (" that is great.\n");

    }
    else if (height==150)
    {
        printf ("%s you are of above avarage height.\n",name);
    }

    else
    {
        printf ("%s your height is below avarage height,",name);
        printf (" you need to work on your height growth.\n");

        printf ("%s you should consult our specialist doctor advice.\n",name);
        int input;
        printf ("press 1 for to raise a request to specialist doctor for advice.\n");
        printf ("press 2 for exit.\n");
        scanf ("%d",&input);

        switch (input)
        {
        case 1:
        printf ("%s your request has been submitted, our specialist will contect you soon.\n",name);
            printf ("Thank you %s, we hope that you might our service.\n",name);
            break;
            case 2:
            printf ("%s, we hope that you will be happy with our service.\n",name);
            int rate;
            printf ("%s before leave please rate our servise from 1 to 10: ",name);
            scanf ("%d",&rate);
       
        default:
        printf ("%s, sorry you have entered incorrect input.\n", name);
            break;
        }
   

    }
        printf("%s thanks for using our servise.\n");
        return 0;
}
output:_
Enter your name: prafull prafull Enter your phone number for further notifications: 9057513102 prafull enter your haight(in cms): 128 prafull your height is below avarage height, you need to work on your height growth. prafull you should consult our specialist doctor advice. press 1 for to raise a request to specialist doctor for advice. press 2 for exit. 2 prafull, we hope that you will be happy with our service. prafull before leave please rate our servise from 1 to 10: 9 prafull, sorry you have entered incorrect input. prafull thanks for using our servise.

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.

Recurtions

  //Why are recursions? //We can solve difficult long iteratively can be solved simply recursively. // there are some problems which suite...