CS50 Advanced Test Correctly Solved.
CS50 Advanced Test Correctly Solved. Say "Hello World" - CORRECT ANSWER #include stdio.h int main(void){ printf("Hello, World"); } Take input from user and print it. - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ string fname = get_string("First name?n"); printf("Hello, %sn",fname); } Take two input from user and print it together. - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ string fname = get_string("First name?n"); string lname = get_string("Last name?n"); printf("Hello, %s %sn", fname,lname); } Using "While" Loop print "Hello World" 20 time. - CORRECT ANSWER int main(void){ int i = 0; while (i 20){ printf("Hello, Worldn"); i++; } } Using "For" Loop print "Hello World" 25 time. - CORRECT ANSWER int main(void){ for (int i =0; i25; i++){ printf("Hello ma duden"); } } What are the placeholders for the following data type - char, double, float, int, long, string - CORRECT ANSWER char - %c, double - %f, int - %i, long - %li, string - %s, float - %f Ask user for their age in years, print how many days & weeks they are. - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ int age = get_int("What's your agen"); int days = age * 365; printf("You are atleast %i days old.n", days); int weeks = days /7; printf("You are atleast %i weeks old.n", weeks); int months = age *12; printf("You are atleast %i months old.n", months); } Using Flaot, Ask for price and add tax to it and print it. - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ float price = get_flot("What's the pric?n"); printf("Your total is %f.n", price * 1.0625); } Aks user for a number. Check if it is odd or even - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ int n = get_int("n: "); if (n % 2 == 0){ printf("Evenn"); }else{ printf("Oddn"); } } Ask for two int number, print out which one is bigger. - CORRECT ANSWER #include cs50.h #include stdio.h int main(void){ int x = get_int("x: "); int y = get_int("y: "); if(xy){ printf("X is bigger then Y"); }else if(yx){ printf("Y is bigger than X"); }else{ printf("X is equal to Y");
Geschreven voor
- Instelling
- Harvard University
- Vak
- CS50
Documentinformatie
- Geüpload op
- 26 mei 2024
- Aantal pagina's
- 7
- Geschreven in
- 2023/2024
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
cs50
-
cs50 advanced test correctly solved
Ook beschikbaar in voordeelbundel