C Questions Answers-C language basic syntax(PartI)


C language basics (PartI)

1. What is the purpose of using stdio.h header file? Check answer 2. The scanf function is used to receive data from keyboard.
a.True b. False Check answer 3. The prinf function is used to print text on the screen.
a.True b. False Check answer 4. Each C program may have many main functions.
a.True b. False Check answer 5. A comment in C language starts with */ and ends with /*.
a.True b. False Check answer 6. Which of the following is not a standard data type?
a.int    b.char    c.float    d.date Check answer 7. In C language, Which one is not the integer value?
a.12    b.'23'    c.10    d.100 Check answer 8. What is the type of each of the following constants?
a.10    b.'2'    c.10.7    d."12" Check answer 9. What is the type of each of the following constant?
a."Dara"    b.'2.9'    c."10.7"    d.13.9f    e.'\a' Check answer 10. Find any errors in the following C program:
void main(){ /* This is the main function*/
printf("Hello")
return 0;
}
Check answer


Comments

Usman comment

 Usman

Hello
Can anyone please help me?
I have a code in C language it has no errors but still it is not running
Please help me


#include <stdio.h>
#include<conio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

#define c 3
#define f 4
#define d 2

FILE *c_file, *f_file, *d_file;

int receipt_no = 0;
int choice;

struct tm *local;
time_t t;
void main_page();

struct order
{
char item_code[5];
char name[50];
double cost;
int quantity;
};


void combo_details(struct order *cd)
{
c_file = fopen("combo.txt", "r");
if (c_file == NULL){
printf("File does not exist");
}
int i = 0;
while(!feof(c_file))
{
fgets(cd[i].item_code, 10, c_file);
strtok(cd[i].item_code, "\n");
fgets(cd[i].name,50,c_file);
strtok(cd[i].name, "\n");
fscanf(c_file, "%lf ", &cd[i].cost);
i++;
}
fclose(c_file);
}

void ac_food_details(struct order *fd)
{
f_file = fopen("ala carte food.txt", "r");
if (f_file == NULL){
printf("File does not exist");
}
int i = 0;
while(!feof(f_file))
{
fgets(fd[i].item_code, 10, c_file);
strtok(fd[i].item_code, "\n");
fgets(fd[i].name,50,c_file);
strtok(fd[i].name, "\n");
fscanf(f_file, "%lf ", &fd[i].cost);
i++;
}
fclose(f_file);
}

void ac_drinks_details(struct order *dd)
{
d_file = fopen("ala carte drinks.txt", "r");
if (d_file == NULL){
printf("File does not exist");
}
int i = 0;
while(!feof(d_file))
{
fgets(dd[i].item_code, 10, d_file);
strtok(dd[i].item_code, "\n");
fgets(dd[i].name,50,d_file);
strtok(dd[i].name, "\n");
fscanf(d_file, "%lf ", &dd[i].cost);
i++;
}
fclose(d_file);
}

void print_menu(struct order *combo, struct order *food, struct order *drinks)
{
printf("==================================================================================\n");
printf("Index\tItem Code\tCombo\t Cost (RM)\n");
printf("==================================================================================\n");

int i;
for(i = 0; i < c; i++)
{
printf("%d\t%-13s\t%-41s\t%.2lf\n", i+1, combo[i].item_code, combo[i].name, combo[i].cost);
}
printf("\n\n");

printf("==================================================================================\n");
printf("Index\tItem Code\tFood\t Cost (RM)\n");
printf("==================================================================================\n");


for(i = 0; i < f; i++)
{
printf("%d\t%-13s\t%-41s\t%.2lf\n", i+1, food[i].item_code, food[i].name, food[i].cost);
}
printf("\n\n");
printf("==================================================================================\n");
printf("Index\tItem Code\tDrinks\t Cost (RM)\n");
printf("==================================================================================\n");


for(i = 0; i < d; i++)
{
printf("%d\t%-13s\t%-41s\t%.2lf\n", i+1, drinks[i].item_code, drinks[i].name, drinks[i].cost);
}
printf("\n---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---x---\n\n");
}

void print_receipt(struct order *list, struct order *combo_name, int l, int k) // printing receipt..
{


double total = 0; // 1st total
double total2 = 0; // total before tax, after discount
double total3 = 0; // total after tax, FINAL TOTAL
double dis = 0; // discount
double tax = 0; // tax
int j;
int gst;
for(j = 0; j < l; j++)
{
total = total + (list[j].cost * list[j].quantity);
}

printf("Input 1 for Staff or 2 for Student: ");
scanf("%d", &gst);

if(gst == 2) // student discount and GST tax
{
dis = (10 * total) / 100;
if(dis > 5)
{
dis = 5;
}
total2 = total - dis;
tax = (6 * total2) / 100;
total3 = total2 + tax;
}
else
{
dis = 0;
total2 = total;
tax = 0;
total3 = total2;
}
printf("\n\n========================================================================\n"); // Printing details here
printf(" Unimas Kiosk \n");
printf(" Purchase Receipt \n");
printf("Receipt No: %d\n", receipt_no+1);
if(gst == 2)
{
printf("Customer Type: Student\n");
}
else{
printf("Customer Type: Staff\n");
}

// Date & Time

t = time(NULL);
local = localtime(&t);
printf("Date: %d/%d/%d\n", local->tm_mday, local->tm_mon+1, local->tm_year+1900);
printf("Time: %d:%d:%d\n\n\n", local->tm_hour, local->tm_min, local->tm_sec);

printf("=========================================================================\n");
printf("Item Code\tItem Type \tQuantity\tPrice(RM)\n");
printf("=========================================================================\n");
int i;
int m =0;
for(i = 0; i < l; i++) // controlling print system by order.
{


if(strcmp(list[i].item_code, "001") == 0)
{

char cmb[10] = "Combo 1";
printf("%-10s\t%-25s\t%4d\t%14.2lf\n", list[i].item_code, cmb, list[i].quantity, (list[i].cost * list[i].quantity));
for(; m < 3; m++)
{
printf(" %-29s\n", combo_name[m].name);
}
continue;
}
else if(strcmp(list[i].item_code, "002") == 0)
{
char cmb[10] = "Combo 2";
printf("%-10s\t%-25s\t%4d\t%14.2lf\n", list[i].item_code, cmb, list[i].quantity, (list[i].cost * list[i].quantity));
for(; m < 2; m++)
{
printf(" %-29s\n", combo_name[m].name);
}
continue;
}
else if(strcmp(list[i].item_code, "003") == 0)
{
char cmb[10] = "Combo 3";
printf("%-10s\t%-25s\t%4d\t%14.2lf\n", list[i].item_code, cmb, list[i].quantity, (list[i].cost * list[i].quantity));
for(; m < 2; m++)
{
printf(" %-29s\n", combo_name[m].name);
}
continue;
}

printf("%-10s\t%-25s\t%4d\t%14.2lf\n", list[i].item_code, list[i].name, list[i].quantity, (list[i].cost * list[i].quantity));
}
printf("-------------------------------------------------------------------------\n");
printf(" RM %.2lf\n", total);
printf(" Discount RM %.2lf\n", dis);
printf(" Total Before GST RM %.2lf\n", total2);
printf(" GST RM %.2lf\n", tax);
printf(" TOTAL RM %.2lf\n", total3);
printf("=========================================================================\n\n");
receipt_no++;
printf("Press enter to go Main Page...");
getch();
main_page();
}

void take_order(struct order *combo, struct order *food, struct order *drinks) // Taking order from user..
{
struct order cfd[c+f+d];
struct order list[c+f+d];
struct order combo_name[c+f+d];
int i;
int j;
for(i = 0; i < c; i++)
{
cfd[i] = combo[i];
//printf("%s\t%s\t%.2lf\n", cfd[i].item_code, cfd[i].name, cfd[i].cost);
}

for(j = 0; j < f; j++)
{
cfd[i] = food[j];
//printf("%s\t%s\t%.2lf\n", cfd[i].item_code, cfd[i].name, cfd[i].cost);
i++;
}
for(j = 0; j < d; j++)
{
cfd[i] = drinks[j];
//printf("%s\t%s\t%.2lf\n", cfd[i].item_code, cfd[i].name, cfd[i].cost);
i++;
}

int c1, c2, c3, c4;


printf("What do you want?\n");
printf("1. Combo\n");
printf("2. Food\n");
printf("3. Drinks\n");
printf("4. Print Receipt\n");
int run = 1;
int l = 0;
int k = 0;
int q;
while (run)
{

printf("\n### Enter your choice: ");
scanf("%d", &c1);
printf("\n");
switch(c1)
{
case 1:
printf("Enter the COMBO index number you want: ");
scanf("%d", &c2);
list[l] = cfd[c2-1];
printf("Quantity: ");
scanf("%d", &q);
list[l].quantity = q;
while(q)
{
if(c2 == 1)
{
printf("Enter 2 FOOD index number: ");
scanf("%d %d", &c3, &c4);
combo_name[k] = cfd[c+c3-1];
//printf("\n%s\n", combo_name[k].item_code);
k++;
combo_name[k] = cfd[c+c4-1];
//printf("\n%s\n", combo_name[k].item_code);
k++;
printf("Enter 1 DRINKS index: ");
scanf("%d", &c3);
combo_name[k] = cfd[c+f+c3-1];
//printf("\n%s\n", combo_name[k].item_code);
k++;
}
else if(c2 == 2)
{
printf("Enter 1 FOOD index: ");
scanf("%d", &c3);
combo_name[k] = cfd[c+c3-1];
k++;
printf("Enter 1 DRINKS index: ");
scanf("%d", &c3);
combo_name[k] = cfd[c+f+c3-1];
k++;
}
else if(c2 == 3)
{
printf("Enter 1 FOOD index: ");
scanf("%d", &c3);
combo_name[k] = cfd[c+c3-1];
k++;
printf("Enter 1 DRINKS index: ");
scanf("%d", &c3);
combo_name[k] = cfd[c+f+c3-1];
k++;
}
q--;
}

break;

case 2:
printf("Enter the FOOD index number you want: ");
scanf("%d", &c2);
list[l] = cfd[c+c2-1];
printf("Quantity: ");
scanf("%d", &q);
list[l].quantity = q;
break;
case 3:
printf("Enter the DRINKS index number you want: ");
scanf("%d", &c2);
list[l] = cfd[c+f+c2-1];
printf("Quantity: ");
scanf("%d", &q);
list[l].quantity = q;
break;
case 4:
if(l == 0)
{
printf("Please order first and then Print Receipt.\n");
getch();
main_page();
}
print_receipt(list, combo_name, l, k);
run = 0;
break;

}
l++;

}

}

void Exit()
{
exit(0);
}

void main_page()
{
struct order combo[c];
struct order ac_food[f];
struct order ac_drinks[d];

combo_details(combo);
ac_food_details(ac_food);
ac_drinks_details(ac_drinks);
system("cls");
printf("----- MAIN PAGE -----\n\n");
printf("\xDB 1. Menu List and Order\n");
printf("\xDB 2. Exit\n\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
print_menu(combo, ac_food, ac_drinks);
take_order(combo, ac_food, ac_drinks);
case 2:
Exit();
}
system("cls");

}





void main()
{
printf("\n\n\t\t \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO FOOD KIOSK IN UNIMAS \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\n\n");
printf("Press any key to continue");
getch();
printf("\n\n\nLoading");
int i;
for (i = 0; i < 6; i++)
{
Sleep(150);
printf(".");
}

int run = 1;

while(run)
{
main_page();
run = 0;

}


}


2016-12-14
assia nidal comment

 assia nidal

Write a complete C program that calculates the areas of shapes. Your program should use at least 3 functions. When the program first starts, it will display a menu for users as follows: Welcome to Shapes Program: 1. Rectangle Area. 2. Triangle Area. 3. Circle Area. 4. Exit ….Enter your Choice (1-4) ? I'm want the solution


2016-04-24
assia nidal comment

 assia nidal

Write a complete C program that calculates the areas of shapes. Your program should use at least 3 functions. When the program first starts, it will display a menu for users as follows: Welcome to Shapes Program: 1. Rectangle Area. 2. Triangle Area. 3. Circle Area. 4. Exit ….Enter your Choice (1-4) ?


2016-04-24
shubham sharma comment

 shubham sharma

Problem : Online Communities - Connectivity

In a social network, online communities refer to the group of people with an interest towards the same topic.

People connect with each other in a social network. A connection between Person I and Person J is represented as C I J. When two persons belonging to different communities connect, the net effect is merger of both communities which I and J belonged to.

Your task is to find out whether two persons are in a same group or not.
Input Format:

Input will consist of three parts, viz.

The total number of people on the social network (N)
Queries
C I J, connect I and J
Q K L, query the community to find out if K and L belong to the same group
-1 will represents the end of input.


2015-07-19
94yashwanth comment

 94yashwanth

To understand better about C language , watch videos , download C source files at www.Fixoncloud.com


2014-02-21
CAPTCHA image



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.