char data [ ] = { \'a\', \'b\', \'c\', \'D\', \'E\', \'f\', \'g\', \'h\', \'I\',
ID: 3903906 • Letter: C
Question
char data [ ] =
{ 'a', 'b', 'c', 'D', 'E', 'f', 'g', 'h', 'I', 'J', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z' } ;
write a program to check if the array contains all the letters of the alphabet exactly once. It is called perfect pangram. But If any letter is missing, it is not a pangram.
[ 10 points ]
char data1 [ ] = { 'h', 'e', 'l', 'l', 'o', '1', '2', '+' } ;
write a program to check if data1 array contains only letters and digits
[ 10 points ]
unsigned char data2 [ ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } ;
write a program to shuffle the data randomly. Pretend you are shuffling a pack of cards. Every time you run your program , the data2 shuffled should be different
[ 10 points ]
unsigned char data3 [ ] = { 11, 17, 19, 23, 31, 39, 41, 51, 61, 71, 91 } ;
unsigned char primes [ ] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 , 97 } ;
Using primes array, print all prime numbers in the array data3 .
[ 10 points ]
PreviousNext
Explanation / Answer
#include <stdio.h>
int ind(char ch) {
if(ch >= 'A' && ch <= 'Z') {
ch += 32;
}
return ch - 'a';
}
int main() {
char data[] = { 'a', 'b', 'c', 'D', 'E', 'f', 'g', 'h', 'I', 'J', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z' };
int found[26] = {0};
int i, len=sizeof(data);
int pangram = 1;
for(i = 0; i < len; ++i) {
if(!found[ind(data[i])]) {
found[ind(data[i])] = 1;
} else {
pangram = 0;
break;
}
}
for(i = 0; i < 26; ++i) {
if(!found[i]) {
pangram = 0;
break;
}
}
if(pangram) {
printf("It is a pangram! ");
} else {
printf("It is not a pangram! ");
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.