Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

#include<stdio.

h> int main(void) { int my_age; printf("Please enter your age: "); scanf("%d", &my_age); printf("My age is %d \n", my_age); return 0; } 2.#include<stdio.h> int main(void) { char symbol1, symbol2, symbol3; printf("Please enter the first three letters of your name :"); scanf("%c%c%c",&symbol1,&symbol2,&symbol3); printf("My initial is %c%c%c \n",symbol1, symbol2, symbol3); return 0; } Q. Write a program that will ask the user to enter three numbers and then it will display the sum and average of three numbers. #include<stdio.h> int main(void) { double num1,num2,num3,sum,average; printf("Please enter three numbers:"); scanf("%lf%lf%lf",&num1,&num2,&num3); sum = num1+num2+num3; printf("sum of three numbers = %.2f\n",sum); average = sum/3; printf("Average of three numbers = %.2f\n",average); return 0; } Q. Write a program that will calculate the area of a circle. The program will ask the user to enter the radius and then display the output. us pi 3.1417 #include<stdio.h> #define pi 3.1417 int main(void) { double radius, area; printf("Please enter the radius in cms:"); scanf("%lf", &radius); area = pi * radius * radius;

printf("Th area of Circle in cm.sq = %.2f\n", area); return 0; }

#include<stdio.h> int main(void) { printf("StudentID printf("200600173 printf("200600129 printf("200601179 return 0; return 0; }

StudentName test1 test2 test3

Course \n GEEN 2312\n GEEN 2312\n GEEN 2312\n

"); "); "); ");

#include<stdio.h> int main(void) { int x,y,z; printf("Please enter two numbers:"); scanf("%d%d", &x, &y); printf("The value of x = %d\n",x); printf("The value of y = %d\n",y); z = x + y; printf("Sum of two numbers = %d\n", z); return 0; } Arithemtic + * / addition Multiplication Subtraction division

#include<stdio.h> int main(void) { char symbol1,symbol2,symbol3; int dollar,quater,dime,nickel,total_cents,total_dollar; int change; printf("Please enter your 3 initials >"); scanf("%c%c%c",&symbol1,&symbol2,&symbol3); printf("Please enter the coin denomination \n"); printf("dollar coin >"); scanf("%d",&dollar); printf("Quater coin >"); scanf("%d",&quater); printf("Dime coin >"); scanf("%d",&dime); printf("Nickel coin >"); scanf("%d",&nickel); total_cents = 100*dollar + 25*quater+ 10*dime + 5*nickel; total_dollar = total_cents/100; change = total_cents%100; printf("Mr. %c%c%c your change \n",symbol1,symbol2,symbol3 ); printf("Dollars = %d\n", total_dollar); printf("Change = %d\n", change); return 0; } #include<stdio.h> #include<math.h> int main(void) { double num1,answer; printf("Please enter a number>"); scanf("%lf", &num1); answer = sqrt(num1); printf("Square root of %.2f = %.4f\n", num1, answer); return 0; } #include<stdio.h> #include<math.h> int main(void) { double num1,num2,sum,result; printf("Please enter two numbers >"); scanf("%lf%lf", &num1,&num2); sum = num1 + num2; result = sqrt(sum); printf("Result = %.2f\n", result); return 0; } #include<stdio.h> #include<math.h>

int main(void) { double u,v,w,result; printf("Please enter three numbers >"); scanf("%lf%lf%lf", &u,&v, &w); result = sqrt(u + v) * pow(w, 2.0); printf("Result = %.2f\n", result); return 0; } #include<stdio.h> #define pi 3.141 int main(void) { double inner_r,outer_r,density,thickness,quantity; double rim_area, unit_wt, total_wt; printf("Please enter the inner radius in cms"); scanf("%lf", &inner_r); printf("Please enter the outer radius in cms"); scanf("%lf", &outer_r); printf("Please enter the thickness in cms"); scanf("%lf", &thickness); printf("Please enter the density in cubic cms"); scanf("%lf", &density); printf("Please enter the quantity in batch"); scanf("%lf", &quantity); /* Calculating the rim_area*/ rim_area = pi *outer_r*outer_r - pi *inner_r * inner_r; /*Calculating the unit weight*/ unit_wt = rim_area * thickness * density; /*Calculating the total weight of flat washer*/ total_wt = unit_wt * quantity; printf("The total weight of flat washer = %.3f\n grams", total_wt); } return 0;

#include<stdio.h> void draw_circle(void); int main(void) { draw_circle(); return 0;

void draw_circle(void) { printf(" * \n"); printf(" * *\n");

printf("

\n");

#include<stdio.h> void draw_circle(void); void draw_triangle(void); void draw_rectangle(void); int main(void) { draw_circle(); printf("\n"); for spacing draw_triangle(); printf("\n"); draw_rectangle(); return 0; } void draw_triangle(void) { printf(" /\\ \n"); printf(" / \\ \n"); printf(" / \\ \n"); printf(" -----\n"); } void draw_rectangle(void) { printf("************\n"); printf("* *\n"); printf("* *\n"); printf("************\n"); } void draw_circle(void) { printf(" * \n"); printf(" * *\n"); printf(" * \n"); } #include<stdio.h> void display_h(void); void display_c(void); void display_p(void); int main(void) { display_h(); printf("\n"); display_c(); printf("\n"); display_p(); display_h(); printf("\n");

display_p(); return 0; } void display_h(void) { printf("hello \n"); } void display_c(void) { printf("C \n"); } void display_p(void) { printf("programming \n"); } #include<stdio.h> void display_square(int num); int main(void) { int temp; printf("Please enter a number>"); scanf("%d", &temp); display_square(temp); return 0; } void display_square(int num) { printf("********\n"); printf("* *\n"); printf("* %d *\n",num); printf("* *\n"); printf("********\n"); } #include<stdio.h> int sum (int num1, int num2); int main(void) { int x,y,total; printf("Please enter two numbers>"); scanf("%d%d", &x, &y); total = sum(x,y); printf("Sum of two numbers = %d\n", total); return 0; } int sum (int num1, int num2) { int temp; temp = num1 + num2; return(temp); }

You might also like