1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sever21 [200]
3 years ago
6

Write a program to check if an input is a valid hashtag (starts with #, contains only letters, numbers, and underscore, no space

or special characters).
(1) Name your program hashtag.c.
(2) The user input ends with the user pressing the enter key (a new line character).
(3) Library function isalpha(), isdigit(), and isalnum() are not allowed in this program.
(4) Use getchar() to read in the input.
Computers and Technology
1 answer:
adell [148]3 years ago
8 0

Answer:

C code is given below

Explanation:

#include<stdio.h>

int main()

{

  printf("Input:");

  int ch;

  int valid=1; // it is set as 1 initially if anything is wrong it is changed to 0

  ch=getchar();

  if(ch!='#') // it checks if it starts with #

  {

      valid=0;

  }

while((ch = getchar())!= '\n') // this loop runs till line ends

  {

if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')||(ch>='0'&&ch<='9')||(ch=='_')) // if conditions are matched then its okay

{

   

  }

  else // else valid is changed to 0 from 1

  {

     valid=0;

  }

}

if(valid==0) // if anywhere there is anything wrong then it prints not valid

{

  printf("It is not valid hashtag");

  }

  else // else prints valid

  {

      printf("It is a valid hastag");

  }

}

You might be interested in
The Speed of Sound (Java Project. Please make it easy to understand. I'm a beginner at this. I believe we are supposed to use a
Ilya [14]

Answer:

The program of this question can be given as:

Program:

//import pacakge for user input.

import java.util.Scanner;

//define class  

public class SpeedofSound              

{

  public static void main(String a[]) //define main function

  {  

      //define variable.

      String medium;                            

      double distance,time=0;

      //creating Scanner class object for input from user.

      Scanner s=new Scanner(System.in);  

      //print message.

      System.out.printf("Enter medium(air,water or steel) : ");

      medium=s.nextLine();  //taking input.

      //print message.

      System.out.printf("Enter the distance that the sound will travel : ");

      distance=s.nextDouble(); //taking input.

      switch(medium) //checking condtion between range.

      {

          case "air":

                  time=distance/1100;         //apply formula

                  break;

          case "water":

                  time=distance/4900;            //apply formula

                  break;

          case "steel":

                  time=distance/16400;            //apply formula

                  break;

          default:

                  System.out.printf("Sorry, you must enter air,water or steel"); //error for invalid input of medium

                  System.exit(0);

      }

      System.out.printf("It take "+time+" seconds"); //print final answer.

  }

}

Output:

Enter medium(air,water or steel) : air

Enter the distance that the sound will travel : 200

It take 0.18181818181818182 seconds

Explanation:

In this program first, we import packages for user input. Then we declare the class in the class we declare all the variables and then we create the scanner class object. It is used for taking input from the user. Then we use the switch statement It is used for condition. It works between the ranges. In the switch statement, we apply all the formula that is given in the question. and at the last, we print the output using printf function in java.

6 0
4 years ago
All of the following can cause a fatal execution-time error except: Group of answer choices Dereferencing a pointer that has not
7nadin3 [17]

Answer: Dereferencing a variable that is not a pointer

Explanation:

The execution time also refered to as the CPU time pertaining to a given task is the time that is used by the system to execute a task.

Some of the reasons for a fatal execution-time error include:

• Dereferencing a pointer that has not been initialized properly

• Dereferencing a null pointer

• Dereferencing a pointer that has not been assigned to point to a specific address.

It should be noted that dereferencing a variable that is not a pointer doesn't cause a fatal execution-time error.

6 0
3 years ago
Can someone help me with this one
MAVERICK [17]

Answer:

true

Explanation:

it is because when someone feels better about something that means that their self esteem is building up

8 0
4 years ago
Read 2 more answers
PLS ANSWER ASAP!!
cricket20 [7]

Answer:

1. = c

2.= a

3. = b

Explanation:

8 0
4 years ago
Consider the parameter Δ used to define the working-set window inthe working-set model. When Δ is set to a low value, what is th
a_sh-v [17]

Answer:

When Δ is set to large value, then a process's resident set is overestimated and this might prevent many processes from being scheduled even though their required pages are resident

Explanation:

When Δ is set to a small value, then the set of resident pages for a process might be underestimated, allowing a process to be scheduled even though all of its required pages are not resident.

This could result in a large number of page faults. When Δ is set to large value, then a process's resident set is overestimated and this might prevent many processes from being scheduled even though their required pages are resident.

Hoewever, once a process is scheduled, it is unlikely to generate page faults since its resident set has been overestimated.

3 0
4 years ago
Other questions:
  • 1. Consider the following code segment.
    8·1 answer
  • In a spreadsheet, cells B2 through B10 store the cost price of items and cells C2 through C10 store the selling price. If the se
    12·2 answers
  • Which naming scheme identifies the columns of a worksheet?
    12·1 answer
  • A bowl contains 20 candies; 15 are chocolate and 5 are vanilla. You select 5 at random. What is the probability that all 5 are c
    6·2 answers
  • Write multiple if statements: If carYear is before 1967, print "Probably has few safety features." (without quotes). If after 19
    11·1 answer
  • The ____ code sets the style so that the web page element remains constant and does not move.
    11·1 answer
  • To configure a router/modem, what type of IP interface configuration should you apply to the computer you are using to access th
    10·1 answer
  • On a scale of 1-10 how would you rate your pain
    12·1 answer
  • 1- Identify the face expressions is considered....
    10·1 answer
  • Which blu-ray standard defines rewritable disks?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!