2. Write a C program using an online C compiler (or Dev C++) that implements the following:-
• Declare a 10-element floating-point array; give the array a suitable name.
• Declare an integer variable (of type int); call it i
• Upon declaration, populate the array with 10 floating-point numbers of your choice.
• Prompt the user to enter a value between 0 and 9
• Read a number from the keyboard into i
• Display the ith element of the array
1. Write a C program using an online C compiler that implements the following:-
• Declare a floating-point variable (of type float)
• Declare an integer variable (of type int)
• Prompt the user to enter a floating-point number.
• Read a number from the keyboard into your floating-point variable
• Using casting, write the contents of your floating-point variable into your integer variable • Display the value of your integer variable.
1. In the following program, what would be the final output? Explain in
detail.
void copyarr( char ∗p1 , char p2 [ ] ) {
memcpy ( p2 , p1 , size of ( p1 ) ) ;
memcpy ( p2 , ‘ ‘ABCD’ ’ , 4 ) ;
}
int main ( ) {
char arr1 [ 100 ] ;
char arr2 [ 100 ] ;
printf( ‘ ‘ Enter a string : ’ ’ ) ;
scanf ( ‘ ‘%[ ˆ\n ] s ’ ’ , arr1 ) ;
copyarr ( arr1 , arr2 ) ;
printf ( ‘ ‘ \ n %s ’ ’ , arr2 ) ;
return 0 ;
}
Write a program to enter the numbers till the user wants and at the end it should display the
count of even, odd and prime numbers entered.
write a C code to add two polynomials having n number of unknown variables
outcome of a game of Rock, Paper, Scissors. You do not need to build the actual game; your main() function does not need to be developed player1 and Player2 will each enter Rock, Paper or Scissors.
Standard rules of who won any given match apply: Rock beats
Scissors. Scissors beats Paper. Paper beats Rock. A Draw occurs if
both players enter the same shape
The requirements of the function are as follows:
The function accepts two char arrays as input
The function outputs a single char array
The char arrays passed to the function can contain any series of characters (i.e. it accepts any word)
The function's main role is to determine who won a game of Rock, Paper, Scissors
The output char array of the function can be 1 of 4 words:
“Player1"
This is the output if Player1 won the match
“Player2"
This is output if Player2 won the match
“Draw"
This is the output if both players entered the same shape
Invalid
Write a file copy program that prompts the user to enter the name of a text file to act as the source file and the name of an output file. The program should use the toupper() function from ctype.h to convert all text to uppercase as it’s written to the output file. Use standard I/O and the text mode
Code a C program to read five integer values from data.txt to console; calculate and display the sum and average thereof. Use the following data to create your text file: 6,45,12,67,9
Ben recently joined in Coding club in his college. On the first day, he got an assignment. He needs to display the numbers as shown in the sample output. Help Ben by writing a suitable program for the pattern.
Input Format
Enter the number of rows(N) in a single line.
Constraints
1≤N≤20
Output Format
Pattern as shown in the sample output.
Sample Input 0
5
Sample Output 0
1 2 3 4 5
16 6
15 7
14 8
13 12 11 10 9
Sample Input 1
7
Sample Output 1
1 2 3 4 5 6 7
24 8
23 9
22 10
21 11
20 12
19 18 17 16 15 14 13
In the situation where there are multiple users or a networked computer system, you probably share a printer with other users. When you request to print a file, your request is added to the print buffer. When your request reaches the front of the print buffer, your file is printed. This ensures that only one person at a time has access to the printer and that this access is given on a first-come, first-served basis. Write a C program to implement the above scenario.