Question

In: Computer Science

In C programming language how do you find if all the character on a single line...

In C programming language how do you find if all the character on a single line in a 2 dimensional array are the same?

The program should read line by line to check if all the characters on a line are the same. For this program we want to see if the * character ever shows up on a line where it is the only character on the line. as seen below.

so lets say we have a array with the following data:

Note(this is a 5x7 two dimensional array)

D C D D * D C

D C C C D * *

* * * * * * *

D C C D * D *

* * * * * * *

So i want to return the amount of lines that have the * in every position in that row. So in this array 2 lines have all the same characters which is a * so it should print "The amount of lines where the * character is the only character that appears is 2"

Solutions

Expert Solution

Ans

code:-

#include<stdio.h>

int main(){

int ans=0,j=0;

int r=5,c=7;//size of matrix

char a[5][7]={{'D','C','D','D','*','D','C'},{'D','C','C','C','D','*','*'},{'*','*','*','*','*','*','*'},{'D','C','C','D','*','D','*'},{'*','*','*','*','*','*','*'}};

//for each row

for(int i=0;i<r;i++){j=0;

for( j=0;j<c;j++){//for each col

if(a[i][j]!='*'){//if no *,next row

break;

}

}

if(j==c){//if all *

ans++;

}

}//print the result

printf("The amount of line where the * character is the only character is %d",ans);

}

If any doubt ask in the comments.


Related Solutions

C Programming How do you read in a text file line by line into a an...
C Programming How do you read in a text file line by line into a an array. example, i have the text file containing: line 1: "qwertyuiop" line 2: "asdfghjkl" line 3: "zxcvbnm" Then in the resulting array i get this: array:"qwertyuiopasdfghjklzxcvbnm"
Programming in C language (not C++) Write a function definition called PhoneType that takes one character...
Programming in C language (not C++) Write a function definition called PhoneType that takes one character argument/ parameter called "phone" and returns a double. When the variable argument phone contains the caracter a or A, print the word Apple and return 1099.99. When phone contains the caracter s or S print the word Samsung and return 999.99. When phone contains anything else, return 0.0.
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
Using c programming language How do you put data from a text file into a 2d...
Using c programming language How do you put data from a text file into a 2d array For example a text file with names and age: john 65 sam 34 joe 35 sarah 19 jason 18 max 14 kevin 50 pam 17 bailey 38 one 2d array should have all the names from the file and one 2d array should have all the ages and both arrays should be printed out separately and be 3x3
The following is for C programming language: I want to scan for initials in a line...
The following is for C programming language: I want to scan for initials in a line of text. my line of text is as follows: 12345 3.5000 a j 12346 4.1000 s p The first number represents the student ID, the second number represents the gpa, the third character represents the first initial and the fourth character represents the last initial of the student. My text file contains these values. The following is my code: fscanf(fp, "%d %c %c", &studentID,...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
A certain programming language allows only two-character variable names. The first character must be a letter...
A certain programming language allows only two-character variable names. The first character must be a letter (upper or lower case) and the second character can be a letter (upper or lower case) or a digit. How many possible variable names are there?
In the java programming language. How would you find if THREE (3) numbers in an array...
In the java programming language. How would you find if THREE (3) numbers in an array add up to a certain sum so for example if my array element consists of: INPUT: 200, 10, 50, 20 and my output asks if these elements add to: 270? YES (200+50+70) 260? YES (200+10+50) 30? NO What method would you suggest to look through the elements in an array (which im going to add through a text file) and determine if these sums...
In the java programming language. How would you find if numbers in an array element add...
In the java programming language. How would you find if numbers in an array element add up to a certain sum so for example if my array element consists of: INPUT: 200, 10, 50, 20 and my output asks if these elements add to: 210? YES (200+10) 260? YES (200+10+50) 30? NO What method would you suggest to look through the elements in an array (which im going to add through a text file) and determine if these sums exist...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT