Guía Técnica Para La ELab. de Proyectos de Mejora.
eLab1.o C Programming Sessions 1. Input and Output 2. Data types 3. Operators 4. Control and Looping Statements 5. Arrays 6. Strings 7. Functions 8. Structures and Unions 9. Pointers 10.Practice Session SRIVI University Learning Centre eLab - 1.0 PDD JAN 2017 1st Edition
Course: C 11 Subject Code: Q. IO 10 Sneha got a sin solve with the to operation(c+=3 operation lnput decimal places. Source Code #lnclude int main() i lnt a, c; scanf("%d".&a): c = a; printf("\nc=%d". c); c+=a://c=c+a D printf("\nc+= /od", c) c-=a;/rc=c-a prlntf("\nc-=°/od". c) C'=a;//C=C~a printf("\nc*=%d", c) c/=a://c=c/a printf("\nc./=%d", c) c %= at // c = c%a printf("\nc°/o%=%d" retum 0; l Sample Input 3 Sample Outpu c=3 mud, §2Q°$ (J O Result Thus, Program ! v t
gle integer as an input , and her task to perfonn all assignment operations in with the given input . Let us help her to llowing conditions met, To Perform , Assign an input the new the variable and display Using addition assignment c=c+3) Using Subtraction assignment operation Using division assignment operation Using modulus assignment and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 All text in bold corresponds to input and the rest corresponds to output. 2 C); " IO 10 " has been successfully executed
course: C Spbject Code: Q. IO11 Write a program to calculate area of a circle lnput and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output Source Code #include lnt maln() { float radius, area; $C8l'lf("°/of", &radius); area = 3.14 ' radius ‘ radius; printf("\nArea of C|t'C|9Z°/of", area); printf("\nArea of Circle:%.2f"_ area); retum 0; ) Sample Input 2 Sample Output Area of Circle:12.560000 Area of Circle: 1 2.56 Result Thus, Program " IO 11 " has been successfully executed
course: C Spbject Code: Q.lO 12 Write a program to print the ASCII value of a character Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude int main() l char c; scanf("%c", &c); printf("ASC|l value of %c=%d", <:. c); return 0: l Sample Input c
Sample Output ASCII value of c=99 Result Thus, Program " IO 12 " has been successfully executed
course: C Srbject Code: Q.lO 14 Ram was a popular maths teacher, he gave a 4 digit number to his students as a assignment .He has to identify ones portion of given number. Please help his students to identify and display the output: Input and Output Format: Input can be an integer Explanation : Let us say ram given number is 1234 and his student need to identify ones portion is 4 Source Code #|nciude int main() { int num.digit_At_ones_p|acce; scant("°/ed". &num); dlg|t_At_ones_placce=num%10; printf("\nThe Digit at ones place of %d is:%d", num,digit_At_ones_p|acce): retum 0: l Sample Input 72 Sample Output The Digit at ones place of 72 is:2 Result Thus, Program " IO 14 " has been successfully executed
course: C Subject Code: Q. I015 write a program to swap two numbers using a temporary variable Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude lnt maln() l lnt x, y, temp; scanf("%d°/>d". &x, &y)l printf("Before swapping:%d %d",x,y); temp = x: x = y: y = temp: printf("\nAfter swapping:%d %d",x,y); retum 0; l Sample Input 5 4 Sample Output Before swapplng:5 4 After swapping:4 5 Result Thus, Program " IO 15 " has been successfully executed
course: C Spbject Code: Q. IO 16 Write a program to swap two numbers without using a temporary variable Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude int maln() l int a,b; scanf("%d°/>d",&a,&b); printf("Before swapping:%d %d",a,b); 8 = a+b; b = H “D: a = a - bi printf("\nAfter swapping:%d %d",a,b); retum 0; ) Sample Input 5 4 Sample Output Before swapplng:5 4 After swapping:4 5 Result Thus, Program " IO 16 " has been successfully executed
course: C Stibject Code: Q. IO 18 Write a program to convert Fahrenheit into celsius Input and Output Format: Refer sample input and output for formatting specification All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #include lnt maln() l float th,cl: scanf("%t"',&th)1 cl =(th - 32)/ 1.8; printf("°/<>O.2tC",cl); retum 0: l Sample Input 0 Sample Output -17.780 Result Thus, Program " IO 18 " has been successfully executed
course: C Srbject Code:
Q. IO 19 Heera is a cute little gal of age 5 years old, she had one piggybank to save money (coins). Her piggy bank got full and she was excited to her savings money. So, she classified the coins of its followings types , Rs.1O coins, Rs. 5 Coins , Rs .2 Coins, Rs. 1 Coins. Now Please help her to calculate the total amount she saved? Input : total number of coins collected on every classified type respectively( Rs..10 Coins, Rs. 5 Coins, Rs. 2 coins, Rs.1 Coins) Source Code #|nclude lnt maln() l lnt num_1O,num_5,num_2,num_11 float total; scanf("%d",&num_10): scanf("°/<>d‘.&num_5); scanf("%d".&num_2); scanf("%d".&num_1); total=num_10'10+num_5'5+num_2'2+num_1'1; printf("\nTota| amount In the piggybank=%0.2f“,total); retum 0: l Sample Input 10 23 43 6 Sample Output Total amount In the piggybank=307.00 Result Thus, Program " IO 19 " has been successfully executed
course: C Srbject Code: Q. IO 20 Carmel is an shopkeeper help him to generate the bill amount of an item given its quantity sold ,value ,discount (In %) and tax(ln %) Input and Output Format: Refer sample input and output for formatting specification. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude Int main() i float total_amount, amount, sub_total, discount_amount, tax_amount, quantity, value, discount. tax; scanf ('%f". &quantity) ; $C&l'lf("°/of", &value); scanf("%f", &discount); scanf ('°/of‘. &tax) ; amount = quantity " value: discount_amount = (amount' discount)/100.0; sub_total =amount - discount_amount; tax_amount= (sub_total’tax) /100.0; total_amount =sub_total+ tax_amount: printf ("\nBill") ; printf("\nQuantltySold:%f", quantity); printf("\nPrice per item:%f", value); printf ("\nAmount:%f‘. amount): printf ("\nDiscount:-%f‘_ discount_amoun'l) ; printf ("\nDlscounted Tota|:%l", sub_tota|) ;
printf ("\nTax:+%f", tax_amount); printf ("\nTotal Amount:°/>f"‘, total_amount); retum O; l Sample Input 20 300 10 12 Sample Output Bill QuantitySold:20.000000 Price per item:300.000000 Amount:6000.000000 Discount:-600.000000 Discounted Total:5400.000000 Tax:+648.000000 Total Amount:6048.000000 Result Thus, Program " IO 20 " has been successfully executed
course: C Spbject Code: Q. IO 21 Write a program to convert a floating point number into corresponding integer Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #include Int main()( float f_num; lnt l_num; scanf("%f",&f_num); l_num = (lnt)f_num; printf("\nThe integer variant of %0.2f is=%d",f_num,i_num): retum 0: l Sample Input 12.01 Sample Output The integer variant of 12.01 ls=12 Result Thus, Program " IO 21 " has been successfully executed
Course: C H Q. IO 22 Subject Code Given an input as integer to the machme he need to get the output of correspondmg floatmg pomt number wlth five dlgrt after decumal points. Please help h|m to wr|te the program that satlsfy the output Input and Output Format Refer sample lnput and output for formatting specificatron All text |n bold corresponds to mput and the rest corresponds to output Source Code #include Int main()( float F_num;
int |_num; scanf("%d".&i_num); F_num = (f|oat)i_num; printf("\n%0.5f'.F_num) printf("\n%d".i_num); retum 0: l Sample Input 12 Sample Output 12.00000 12 Result Thus, Program “ IO 22 " has been successfully executed
Course: C Srbject Code: Q. IO 23 Mr.Ftight is an english teacher , he got task to to calculate a students result based on input of two examinations ,one sport event , and three activities conducted . Please help him to find the result of every individual section according to weightage(Glven below) provided by principal that results to exam _percent, sports percent,activities percent and finally total percent that sums all individual result with following conditions met Weightage : ACTlV|TlES_WElGHTAGE- 30 SPORTS_WElGHTAGE- 20 EXAMS_WElGHTAGE -50 Total : EXAMS_TOTAL out of 200 ACTlVlTlES_TOTALout of 60 SPORTS_TOTAL out of 50 lnput: Two scores obtained in two examination (out of 100) The score obtained in sports events (out of 50) The score obtained in three activities (out of 20) Explanation :To calculate exam percent=(Addion of two exam marks) * (Weightage of Exam) / (Total_score based on no of exam inputs) Source Code #lnclude #deflne ACTlVlTlES_WElGHTAGE 30 #define SPOFtTS_WElGHTAGE 20 #define EXAMS_WElGHTAGE 50 #deflne EXAMS_TOTAL 200 #deflne ACTlVlTlES_TOTAL 60 #define SPOFtTS_TOTAL 50 lnt main() l lnt exam_scorel. activities_scorel,sports_score; lnt exam_score2. activlties_score2.actlvitles_score3I float exam_total. actlvitles_total; float total _percent. exam_percent,sports_percent. activities_percent: scanf("%d %d", &exam__scorel, &exam__score2); scant("%d",8.sports_score); scanf("°/ed %d %d",&activities_scorel,&activities_score2,&actIvitles_score3)1 exam_total = exam_scorel + exam_score2: activitles_total = (actlvlties_scorel + activlties_score2 + activities_sc0re3); exam _percent = (tloat)exam_total ‘ EXAMS_WElGHTAGE I EXAMS_TOTAL; sports _percent = (float)sports_score ' SPORTS_WElGHTAGE / SPORTS_TOTAL; actlvitles_percent = (tloat)activltles_totaI ’ ACTIVITIES_WElGHTAGE/ACTIVITIES_TOTAL: total _percent = exam _percent + sports _percent + actlvlties_percent; printf("\nResult") ; printf("\nTotal Percent in examination:%0.2f', exam _percent);
printf("\nTotal Percent In activitles:%0.2f“. activlties_percent)2 printf(“\nTotal Percent In sports:%O.2t", sports _percent); printf("\nTotal Percentage:%0.2t", total _percent); retum 0: l Sample Input 7889 34 191817 Sample Output Result Total Percent in examlnatlon:41.75 Total Percent in activlties:27.00 Total Percent in sports:13.6O Total Percenlage:82.35 Result Thus, Program " IO 23 " has been successfully executed
course: C frbject Code: Q. IO 24 Selva Mary from SRM Public school is studying 3r grade in school, her maths mam gave her a problem to convert the decimal number in octal and hexadecimal . Since her mam gave so much problems to solves.She went to his brother who is computer programmer and requested to create a program that converts automatically given integer to decimal, octal and hexadecimal equivalent. Let us help an programmer to do program? Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #include int main()( lnt decimal: scanf("%d".&decimal); printf("\nDecimal value:%d\nOctal value:°/<>o\nHexadecimal va|ue:°/>x". decimal. decimal. decimal); retum 0: l Sample Input 25 Sample Output Decimal V8|U9I25 Octal value:31 Hexadecimal value:19 Result Thus, Program " IO 24 " has been successfully executed
course: C Spbject Code: Q. IO 25 Write a program that prints a floating point value in ex within 6 columns Tries to print number right justified to Rounds to 0 digit places Prints the number in expone output for formatting specification. All float values are rest corresponds to output.
Source Code #lnclude int main() l int a=l .integer; float decimal: scanf("°/<>d",&integer); scanf("°/<>f".&decimal); printf("\n4 digit integer right justified to 6 column:%4d", integer); printf("\n4 digit integer right justified to 3 column:%3d", integer): // Rounds to two digit places ponentiai format with the following specifications Prints the number right justified 3 digits but the number is not right adjusted because there are only 4 numbers ntial notati0n(scientific notation) input and Output Format: Refer sample input and displayed correct to 2 decimal places. Ali text in bold corresponds to input and the printf("\nFl0ating point number rounded to 0 digits:%.f".987.6543); printf("\nFloating point number rounded to 2 digits:%.2t"‘,decimal); printf("\nFIoating point number rounded to 4 digits:%.4f",decimal); // Rounds to 0 digit places printt("\nFioating point number rounded to 8 digits:%.8f",decimal); // Prints the number in exponential notation(scientific notation) printf("\nFloating point number in exponential form:°/oe".987.6543) retum 0: ) . Sample Input 9876 987. 6543 Sample Output 4 digit integer right justified to 6 coiumn:9876 4 digit Integer right justified to 3 coiumn:9876 Floating point number rounded to 0 digits:988 Floating point number rounded to 2 diglts:987.65 Floating point number rounded to 4 digits:987.6543 Floating point number rounded to 8 digits:98'/165429688 Floating point number In exponential form:9.876543e+02 Result Thus, Program " IO 25 " has been successfully execu ted
course: C Srbject Code: Q. IO 26 Write a program to read 10 integers. Display these numbers by printing three numbers in a line separated by commas Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #include int maln()( rm a,b_c,d,e,t.g,h,i.]; scanf("%d %d %d %d °/od %d %d %d %d °/>d", &a,&b,&c,&d,&e.&f,&g.&h,&l,&i); printf("\n%d.%d,%d\n%d.%d.°/<>d\n%d,°/<>d.%d\n%d", a,b.c.d,e,f.g.h,i.j): retum O: l Sample Input
1 2 3 4 s s 7 a 9 10 Sample Output 1,2,3 4,5,6 7.a,s 10 Result Thus, Program " IO 26 " has been successfully executed
Course: C 11 Q. IO 28 Subject Code Write a program to pr|nt the count of even numbers between 1 and 200 and pnnt their sum Input and Output Format Refer sample |nput and output for formatting specrfrcatron All float values are displayed correct to 2 decrmal places All text In bold corresponds to mput and the rest corresponds to output Source Code #include rm maln() l lnt a=0.i; for(i=0;i<=200;i=i+2) at-=|; printf("%d",a); retum O: l Sample Input 0 Sample Output 0 Result Thus, Program " IO 28 " has been successfully executed
Course: C 11 Subject Code: Q. IO 29 Write a program specification. All output. Source Code #lnclude int maln() l char ch[10]; int l,count=0; scanl("%s",ch); for(i=O;ch[i]l='\0‘;i++) l lf(ch[|]=='a‘ || ¢n[|]==' ll ¢hlil=='u') ( count++: l l
printf("\nVowe|s=°/ od retum 0: l Sample Input srmunlversity Sample Output Vowels=4 Result Thus, Program " to count numbers of vowels in a text Input and Output Format: Refer sample input and output for formatting float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to e’ || ch[l]=='l' ;| ch[l]=='o' ",COl.lflt]§ IO 29 " has been successfully executed
course: C fiibject Code: Q. I03 Write a program to calculate the perimeter of a tnangle using Heros formula Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude #lnclude Int main()( float a,b,c; float s,area; scanf('%f%f%f" .&a. &b_&c); s = (a+b+c)/2; area = sqrt(s'[s-a)"(s-b)’(s-c)); printf("perlmeter of triangle ls:%f"_.area); return 0: l Sample Input 2 3 4 Sample Output perimeter of triangle is:2.904737 Result Thus, Program " IO 3 " has been successfully executed
course: C Srbject Code: Q. IO 30 Write a program to read the address of a user .Display the result by breaking it into multiple lines Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude //#lnc|ude Int maln()
l lnt hno; long Int pin: char area[20]; SC8fif("°/oC|'. &hn0)2 scanf("%s", area); scanf("°/old", &pln): printf("Address"); printf("\nHouse Number:%d", hn0)I printf("\nArea:%s". area): printf("\nPln Code:%|d", pin); retum 0; l Sample Input 3489 SRMChennai 603203 Sample Output Addl'9SS House Number:3489 Area:SRMChennal Pin Code:603203 Result Thus, Program " IO 30 " has been successfully executed
course: C Srbject Code: Q. IO 31 Pranav intelligent in playing riddle with numbers so, he gave his sister a puzzle to solve in which she need to solve by adding the left side integral part of two decimal numbers. Explanation: Raju gave his sister two decimal numbers : 23.44 and 33.22 , His sister need to identify the left side integral part of given numbers are 23 and 33 . Finally the added output value is 56. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #|nclude lnt main() l float a_b; lnt sum: scanf("%f", &a); scanf("%f", &b): sum = (int) a+b; printf("\nsum:%d".sum); retum 0; l Sample Input 12.22 11.22 Sample Output sum:23 Result Thus, Program " IO 31 " has been successfully executed
course: C Srbject Code: Q. I0 32 Manav had a play with his friend gourav, he gave a number that to read a floating point number and asked him to display the right most digit integral part of the number. Please help gourav to display the right most integral part of the number. Explanation : If the input is given 124.34, then the output to be displayed is 4 (i.e) Before decimal the integral part is 124 , in that last digit is 4. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #Include lnt main() l float a; lnt num, digit; scanf("%t", Sta); num = (lnt)a; digit = num%10; printf("Rightmost integer digit of %t=%d”,a,digit); retum 0; l Sample Input 233.444 Sample Output Ftightmost lnteger digit of 233.444000=3 Result Thus, Program " IO 32 " has been successfully executed
course: C Srbject Code: Q. IO 33 Raj deposit $10000 into a bank account paying 7% simple interest per year. He left the money in for 5 years. Find the interest earned and the amount at the end of those 5 years by Raj? Help him to find the interest and amount resided in bank after 5 years? STEP 1: Find an interest by using the formula l=P<=i<=t, where I is interest, P is total principal, i is rate of interest per year, and t is total time in years. STEP 2: Find an amount by using the formula A=P+l. Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude #lnclude int maln() l float p. r, t. interestamount; scanf("%f%f%f",&p,&r.&t); lnterest=(p'r*t)/100; amount=lnterest+p; printf("\nlnterest=%0.2f"_interest)2 printf("\nAmount=%0.2f",amount); retum 0; l
Sample Input 10000 7 5 Sample Output |nterest=3500.00 Amount=13500.00 Result Thus, Program " IO 33 " has been successfully executed
course: C Srbject Code: Q. IO 34 Help Raja to calculate a first salary that he got from the organization , he was confused with an salary credited in hs account . He asked his friend ritu to identify how salary pay got calculated by giving the format of salary . His basic pay (to be entered by user) and Ritu developed a software to calculate the salary pay,with format given as below HFlA=80% of the basic pay, dA=40% of basic pay . bonus = 25 % of hra input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output Source Code #inciude #detine HRA 0.80 #define TA 0.40 int maln() i float basic. sal; scanf("°/<>f".&basic); sai = basic + (HRA ' basic) + (TA ’ basic); printf("Totai Saiary=%f‘,sai): retum O: l Sample Input 50000 Sample Output Total Salary=1 1oooo.oooooo Result Thus, Program " IO 34" has been successfully executed
course: C Spbject Code: Q. IO 35 Write a program to display a grocery bill of the product purchased in the small market by John by getting following input from the user Get the product name Get the price of the pr0duct(Price per Unit) Get the quantity of the product purchased lnput and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #|nclude int ma|n()( char prod_name[10]: Int qty;
float prod _price,tot _prlce: scanf("%s",prod_name); scanf("°/t>f",&prod_price); scanf("%d".&qty); tot _prIce=qty'prod _pricel printf("\nProduct Details"); printf("\n%s",prod_name)I printf("\n%f‘,prod_price); printf("\n°/<>d".qty); printf("\nB||l:%0.2f",tot_prlce); retum 0; l Sample Input soap 33.00 2 Sample Output Product Details soap 33.000000 2 Bill 266.00 Result Thus, Program " IO 35 " has been successfully executed
course: C Spbject Code: Q.lO4 Given two cities at geographic coordinates (xA,yA) and (xB,yB), and calculate the distance between from city A to city B? Note: Use the distance between points formula Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #lnclude #lnclude lnt maln() t lnt x1. y1, x2, y2: float dist; scanf("%d%d".&x1 .&y1 ); scanf("%d%d",&x2,&y2); dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2)); printf("\nThe distance between two points ls:%0.2f units",dist); retum O; l Sample Input 1233 134 Sample Output The distance between two points is:29.02 unlts Result Thus, Program " IO 4 " has been successfully executed
course: C Srbject Code:
Q. I05 Write a program to scan the given input and perform unary prefix increment and decrement operators. Condition : Variable name to be used: Preadd, Presub, Posadd, Possub Source Code #include int ma|n() l int num,posadd,possub,preadd,presub; scanf("°/od'.&num)l posadd=num++; possub=num--; preadd=++num; presub=--num; printf("\nThe Value of num=%d".num); printf("\nThe Value of num++=°/>d", posadd); printf("\nThe new Value of num=%d"_preadd): printf("\nThe Value of num=%d",preadd); printf("\nThe Value of num~-=°/>d".possub); printf("\nThe new Value of num=°/odipresub); retum O: l Sample Input 2 Sample Output The Value of num=2 The Value of num++=2 The new Value of num=3 The Value of num=3 The Value of num--=3 The new Value of num=2 Result Thus, Program " IO 5 " has been successfully executed
course: C Spbject Code: Q. I08 Write a program to find the largest of three numbers using ternary operator Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code # include rm main() i int a, b, c. big; scanf("°/<>d %d %d", &a, &b, &c) 1 big=(a>b)?((a>c)?a:c):((b>c) ?b:c): printf('“\nThe biggest number ls:%d“, big) ; return 0; l Sample Input 4 5 6 Sample Output The biggest number ls:6 Result Thus, Program " IO 8 " has been successfully executed
Course: C Spbject Code: Q. I09 Let us help Raje to perform basic bitwise operation by providing three inputs given to the program with the following conditions are met, Bitwise And Bitwise OR Bit Wise Not complement of Positive number complement of negative number Right shift by 0 of given number Right shift by 1 of given number Left shift by 0 of given number Left shift by 1 of given number Input and Output Format: Refer sample input and output for formatting specification. All float values are displayed correct to 2 decimal places. All text in bold corresponds to input and the rest corresponds to output. Source Code #IncIude int main() ( int a, b,c; scanf("%d°/<>d%d",&a.&b,&c): printf("Bitwise And of °/<>d and %d=%d\n", a.b.a&b): printf("Bitwlse OR of %d and %d=%d\n“.a.b, alb); printf("Bit Wise Not of %d and %d=%d\n", a,b,a'\b); printf("complement of °/od=°/od\l‘\",8,'-3)} printf("compIement of -%d=%d\n'.b.~-b); printf("Rlght shift by 0 of %d=%d\n".c,c>>0); printf("R|ght shift by 1 of °/<>d=%d\n".c.c>>1); printf("Left shift by 0 of %d=%d\n",c,c<<0); printf("Left shift by 1 if %d=°/od\n".c,c<<1); retum 0: l Sample Input 23 4 4 Sample Output Bitwise And of 23 and 4=4 Bitwise OR of 23 and 4=23 Bit Wise Not of 23 and 4=19 complement of 23=-24 complement of -4=3 Right shift by 0 of 4=4 Right shift by 1 of 4=2 Left shift by 0 of 4=4 Left shift by 1 if 4=8 Result Thus, Program " IO 9 " has been successfully executed
course: C Subject Code: Q. Hello Welcome to SRM University On Syams First class of Type-writing the teacher told him to write the word Hello Welcome to SRM University! Please help him to print hello world the give text Source Code #include lnt maln() l printf("He||o Welcome to SRM University"); return 0;
l Sample Input 0 Sample Output Hello Welcome to SRM University Result Thus, Program " Hello Welcome to SRM University" has been successfully executed
course: C ?:.|bject Code: Q. Addition of numbers(lnteger data type) Jennys home work for first day is to find addition of two numbers, help jenny to solve the problem Source Code #include Int main() l int a, b, c; scanf("%d°/<>d", &a, &b); C = EH-bl printf("The addition of two number is:°/<>d",c); return 0; ) Sample Input 6 2 Sample Output The addition of two number is:8 Result Thus, Program "Addition of numbers(lnteger data type)" has been successfully executed
course: C Srbject Code: Q. DT-6:Division of numbers Harinis home work for fourth day is to divide two numbers, help Harini to solve the problem Source Code #include lnt main() ( int a. b, c; scanf("%d %d“.&a.&b): c = a/b; prlntf("The Division of two number is:%d",c); return 0; l Sample Input 7 2 Sample Output The Division of two number is:3 Result Thus, Program " DT-6:Division of numbers" has been successfully executed
course: C Srbject Code:
Q. Float Division of numbers Harinis home work for fourth day is to divide two numbers, help Harini to solve the problem Source Code #include int main() l float a,b,c; SC8l'lf("°/of %f'.&a,&b): c = a/b; prlntf("The Division of two number is:%f"__c); return 0; l Sample Input 7.2 3.4 Sample Output The Division of two number is:2.117647 Result Thus, Program " Float Division of numbers" has been successfully executed
course: C frbject Code: Q. Module of numbers Harinis home work for filth day is to find reminder of two numbers, help Harini to solve the problem Source Code #incIude int main() l int a. b, c; scanf("%d%d", &a,&b); c=a%b; printf("The modulo of two number is:%d",c); return 0; ) Sample Input 6 2 Sample Output The modulo of two number ls:0 Result Thus, Program " Module of numbers" has been successfully executed
Subject Code: Course: C H Q. Multiplication of numbers Harinis home work for third day is to multiplication oi two numbers, help Harini to solve the problem Source Code #include int main() i float d_.e,i; scanf("%i‘°/of",&d,&e); f=d'e; printf("\nThe Multiplication of two number is:%f",f);
print1("\nThe Multiplication oi two number is:%.2f",f); return 0; l Sample Input 7.2 1.5 Sample Output The Multiplication of two number is:10.799999 The Multiplication of two number is:10.80 Result Thus, Program " Multiplication of numbers " has been successfully executed
course: C Srbject Code: Q. Addition of two numbers Harinis home work for the second day is to subtract two numbers, help Harini to solve the problem Source Code #include lnt main() l int a. b, c; float d.e,l; //printf("Enter two numbers to add\n"); scanf("%d°/<>d",&a,&b); scanf("%f%f".&d.&e)I C = a+b: f=d+e; printf("The Addition of two number ls:%d\n',c); printf("The Addition of two number is:%.2t',t); return O; l Sample Input 4 4 5.5 6.4 Sample Output The Addition of two number ls:8 The Addition of two number ls:11.90 Result Thus, Program "Addition of two numbers " has been successfully executed
course: C fubject Code: Q. Modulo of numbers(lnteger data type) Jennys home work for Fifth day is to find modulo of two numbers, help jenny to solve the problem Source Code #include Int main() l int a, b, c; scanf("%d°/<=d".&a,&b); c = a°/obi printf("The reminder of two number is:%d".c); return 0;
) Sample Input 6 2 Sample Output The reminder of two number is:0 Result Thus, Program " Modulo of numbers(Integer data type)" has been successfully executed
Subject Code: Course: C H m Q. Display your na Write a program to g Source Code #incIude mt main() { char a[20]; scanf("%s",a); printf("Your name |s:%s return 0; l Sample Input SRMUniversity Sample Output Your name is:SRMUnive Result Thus, Program "Dis e eta string and print it. =3); rsity play your name" has been successfully executed
Course: C 11 Subject Code: Q. DT-10: Floa Write a C prog Source Code #include int main() { int a.b; float x.y; scanf("%f",&x)I scanf("%f",&y); a = (int)(x+O.5); b = (int)(y+0.5)2 printf("Value ls:%d",a): .. .%d..’b printf( \nValue ls. retum 0; l
Sample Input 4.6 5.8 Sample Outpu Value is:5 Value is:6 Result Thus, Program t to Integer t ram to convert integer to float number. ); " DT-10: Float to Integer" has been successfully executed
course: C Srbject Code: Q. DT-11:Celsius To Farenheit Mercy and her friends went a trip to hill station during winter. It is raining heavily so they cant go outside. mercy felt very bored and decided to ask puzzle to her friends. She gave them the temperature in Celsius format and asked them to convert it to Fahrenheit. Source Code #include float temp_f; /’ degrees tahrenheit '/ float temp_c; /’ degrees centigrade ‘/ char line_text[50]: /' a llne of input ’/ int main() { fgets(line_text, sizeof(line_text). stdin); sscanf(llne_text, '°/of", &temp_c): temp_f = ((9.0 / 5.0) ' temp_c) + 32.0; printf("°/of degrees Fahrenheit", temp_f); return(0): l Sample Input 45.0 Sample Output 1 13.000000 degrees Fahrenheit Result Thus, Program " DT-11:CeIsius To Farenheit " has been successfully executed
course: C Srbject Code: Q. DT12: Print date/month/Year Write a C program to print your name, date of birth. and mobile number. Source Code #include lnt maIn() t char a[20], b[20]I int date,year.code.number: scanf('%s",a); scanf("°/>s".b): scanf("%d",&date); scanf(“%d",&year); scanf("%d",&code): scanf("%d',&number); printf("Name:%s",a);
printf("\nDOB:°/<>s %d %d",b,date_year); printf("\nMobile:%d-%d",code.number); return 0; l Sample Input SRMUniverslty March 23 1 991 99 1 234567890 Sample Output Name:SRMUniversity DOB:March 23 1991 Mobi|e:99-1234567890 Result Thus, Program " DT12: Print date/month/Year" has been successfully executed
course: C Srbject Code: Q. DT14: Print Details John joined in his new college in chennai. The College is rated as one of the best private university in India. On first day of his college, John teacher have asked his personal details for data purposes. Kindly help john to perform the task using coding. Refer same input and output for details Source Code #lnclude int maln() l char name[2O]: int age,yearI float percentage; scanf("%s", name); scanf("%d",&age): scanf("%f",&percentage): scanf(”%d",&year); printf("Name:%s",name)I printf("\nAge:%d",age); printf("\nPercentage 1°/<>f',percentage); printf("\nYear of Passlng:%d"_year); return 0; l Sample Input john 21 79.9 2017 Sample Output Namezjohn Age:21 Percentage:79.900002 Year of Passlng:2017 Result Thus, Program " DT14: Print Details" has been successfully executed
course: C Srbject Code: Q. Conversion on specific Write a C program to convert specified days into years, weeks and days. Source Code #include rm ma|n() { Int days, years, weeks: scanf("%d",&days): // Converts days to years. weeks and days years = days/365; weeks = (days % 365)/7; days = days- ((years'365) + (weeks'7)); printf("Years:%d\n", years); printf("Weeks:%d\n", weeks); printf("Days:%d", days); return 0: l Sample Input 3456 Sample Output Years:9 Weeks:24 Days:3 Result Thus, Program "Conversion on specific " has been successfully executed
course: C Spbject Code: Q. Age Calculator Declare me as an integer. Get two integer values as mentioned in sample input and output Declare average as a float and assign it the average of me and you. Then using one printf for each line, print the following. The numbers are printed using the values of the variables. The last line starts on a tab position Source Code #lnclude lnt maln() l int a,b; float c: scanf("%d °/<>d",8-a_&b); c=(a+b)/2: printf("l am:%d\nYou are:°/<>d\nWe are around:%f'_a.b,c); return 0; l Sample Input 40 20 Sample Output I am:40 You are:20 We are around:30.000000 Result Thus, Program " Age Calculator " has been successfully executed
course: C ?:.|bject Code: Q. Cube of a Number Write a C program to find the cube of a number Source Code #include int main() { Int a; scanf("%d“,&a); printf("%d'.a’a'a)I return 0; l Sample Input 2 Sample Output 3 Result Thus, Program "Cube of a Number" has been successfully executed
course: C Spbject Code: Q. Square of a Number Write a C program to find the square of a number Source Code #include int main() { Int a; scanf("%d“,&a); printf("%d'.a’a); return 0; l Sample Input 2 Sample Output 4 Result Thus, Program "Square of a Number" has been successfully executed
course: C Spbject Code: Q. Subtraction of numbers(lnteger data type) Jennys home work for Second day is to find subtraction of two numbers, help jenny to solve the problem Source Code #include int main() ( int d,e.f; scanf("%d %d",&d.&e); f=d-e: printf("\nThe Subtraction of two number ls:°/<>d"_t): return 0; l Sample Input 6 2
Sample Output The Subtraction of two number Is:4 Result Thus, Program "Subtraction of numbers(|nteger data type) " has been successfully executed
course: C fiibject Code: Q. Multiplication of numbers(lnteger data type) Jennys home work for Third day is to find Multiplication of two numbers, help jenny to solve the problem Source Code #include int main() l int d.e.f; scanf("%d%d",&d,&e); f=d"e; printf("\nThe Multiplication of two number is:%d",f); return 0; l Sample Input 6 2 Sample Output The Multiplication of two number is:12 Result Thus, Program " Multiplication of numbers(lnteger data type) " has been successfully executed
course: C Spbject Code: Q. Division of numbers(lnteger data type) Jennys home work for Fourth day is to find Division of two numbers, help jenny to solve the problem Source Code #include Int main() ( int a. b, c; scanf("%d°/<>d", &a, &b); c=a/b; prIntf("The division of two number ls:%d",c); return 0; l Sample Input 6 2 Sample Output The division of two number is:3 Result Thus, Program "Division of numbers(lnteger data type)" has been successfully executed
course: C Stibject Code:
Q. Substraction of numbers Harinis home work for second day is to subtract two numbers, help Harini to solve the problem Source Code #include int main() t float d.e,f; scanf("%f %f“,&d.&e)I f=d-e; printf("\nThe Subtraction of two number Is:%f",t); printf("\nThe Subtraction of two number is:°/<>.2t\n".t); return 0; ) Sample Input 7.2 1.5 Sample Output The Subtraction of two number ls:5.70000O The Subtraction of two number is:5.70 Result Thus, Program " Substraction of numbers " has been successfully executed
course: C Srbject Code: Q. Alice in Wonderland Alice was bored that day,so she was sitting on the riverbank .Sudden|y she notices a talking, White Rabbit with a pocket watch .lt ran fast,and she followed it, down a rabbit hole .She fell into the hole and found a magical wonderland with dark trees, beautiful flowers.She found many ways numbered from 1,2,3, ...... ..18.she was confused which is the right way that will lead her to her home. She found a cute bird, standing in one of the tree. Alice asked the bird the way to go back to her home.The bird said a two digit number( say 23 ) and asked her to find the sum of its digits (2+3=5) and that numbered way will lead her to her home.Alice was already confused, so pls help Alice in finding the route to her home.... lnput Format: Input consists of an integer corresponding to the 2-digit number. Output Format: Output consists of an integer corresponding to the sum of its digits. Refer sample input and output for formatting specifications Source Code #lnclude Int maln() l lnt a,b.c.d; scanf("%d".&a)1 b=a/10; c=a°/010; d=b+C: if(a>99) printf("\nnot a 2 digit number\n"); else printf("\nA|ice must go in path-%d".d); retum 0: l Sample Input 23 Sample Output
Alice must go in path-5 Result Thus, Program " Alice in Wonderland " has been successfully executed
course: C Spbject Code: Q. Average Scale A grocer has a scale of Rs. S1,Rs . S2, Rs. S3 ,Rs. S4 and Rs. S5 for 5 consecutive months. How much sale must he have in the sixth month so that he gets an average sale for Rs.X? Write a C program to compute the sale in the 6th Format: Input format: Input consists of 5 integers and 1 float. The five integers corresponds to s1 ,s2,s3,s4,s5. The float input corresponds to x. Source Code #include int maln()( float a,b_.c; scanf("°/<>f",&a); $C8flf("°/of", &b); c=a-((b'a)/100); printf("The selllng price of the cycle ls Rs=%.2f\n",c); retum 0: l Sample Input 1400 15 Sample Output The selling price of the cycle is Rs=1 190.00 Result Thus, Program " Average Scale " has been successfully executed
Course: C Srbject Code: Q. AVERAGE SALE A grocer has a sale of Rs. s1, Rs. s2, Rs. s3, Rs. s4 and Rs. s5 for 5 consecutive months. How much sale must he have in the sixth month so that he gets an average sale of Rs. x? Write a C program to compute the sale in the 6th month. lnput Format: Input consists of 5 integers and 1 float. The five integers correspond to s1, s2, s3, s4 and s5. The float input corresponds to x. Output Format: Refer sample input and output for formatting specifications. The float values are displayed correct to 2 decimal places Source Code #lnclude int maln() l Int s.a,b,c,d,e; float x,f; scanf("%d',&a); scanf(”°/>d",&b); scanf("%cl",&c); scanf("%d",&d); scanf("°/ed".&e); scanf("%f",&x): s=(a+b+c+d+e); f=(6'x)-s; printf("The required sale in the sixth month is %.2f", f); retum O;
l Sample Input 64:-as 6927 sass 7230 6562 7000.0 Sample Output The required sale in the sixth month ls 7991.00 Result Thus, Program " AVERAGE SALE" has been successfully executed
course: C Silbject Code: Q. Calculating SP A man buys a cycle for Rs. a and sells it at a loss of b%. What is the selling price of the cycle? Write a C program to compute the selling price. input Format: The first input is an integer which corresponds to a. The second input is an integer which corresponds to b. Source Code #include lnt maln()( float a.b.c; scanf("°/cf",&a); scanfU%zfL&by c=a—((b'a)/100); printf(“The selling price of the cycle is Rs=%.2f".c); retum O: ) Sample Input 1400 15 Sample Output The selling price of the cycle ls Fts=1 190.00 Result Thus, Program " Calculating SP" has been successfully executed
course: C Srbject Code: Q. Calculating Gain Percentage Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells the scooter for Rs. C , what is his gain %? Write a C program to compute the gain %. Input Format: The first input is an integer which corresponds to A. The second input is an integer which corresponds to B. The third input is a float which corresponds to selling price Source Code #lnclude lnt main()( float a.b,c.d,e; scant("%f",&a); scanf("°/of", &b); scant("%t",&c); d=8+bI e=((c-d)rd)'100; printt("The gain percentage is=%.2t".e): retum 0: ) Sample Input 4700 aoo 5800
Sample Output The gain percentage is=5.45 Result Thus, Program " Calculating Gain Percentage" has been successfully executed
course: C Srbject Code: Q. Calculating Percentage SRM University buys an old scooter for Rs. A and Spends Rs. B on its repairs. if he sells the scooter for Rs.C , what is his gain %? Write C program to compute the gain %? Input format: The first input is an integer which corresponds to A . The second input is an integer which corresponds to B. The third input is a float which corresponds to gain % Source Code #include int main()( float a,b,c,d,e: scanf("°/<>f",&a); scanf("%f", &b); scanf("%f",&c): d=a-Pb: e=((c~d)/d)'100; printf("The gain percentage is=%.2f".e); retum O: ) Sample Input 4700 aoo saoo Sample Output The gain percentage is=5.45 Result Thus, Program " Calculating Percentage" has been successfully executed
course: C Subject Code: Q. Calculating SP A man buys a cycle for Rs. A and sells its a loss of B% . What is the selling price of the cycle? Write a C program to compute the selling price Input format: The first input is an integer which corresponds to A . The second input is an integer which corresponds to B. Source Code #include lnt maln()( float a,b.c; scanf("°/cf",&a); scanf("°/cf", &b); c=a-((b'a)/100); printf("The selling price of the cycle ls Fls=°/c.2f',c); retum 0; ) Sample Input 1400 15 Sample Output The selling price of the cycle ls Rs=1 190.00 Result Thus, Program " Calculating SP" has been successfully executed
course: C Srbject Code: Q. Computing X The cost prince of n articles is the same as the selling price of X articles . If the profit is p% then what is the value of x? lnput format: The first input is an integer which corresponds to n the second is an integer which corresponds to p Output Formt: Refer sample Input and output for formatting Specifications The float values are displayed correct to 2 decimal places. Source Code #lncIude int maln()( float a.b,x; float c,d; scanf("°/of", &a); scanf("%t",&b); c=(b'0.01); d=C+1 I X=a."d; printf("The value of X ls=%.2f".x): retum 0; l Sample Input 12.5 14.5 Sample Output The value of x ls=10.92 Result Thus, Program " Computing X " has been successfully executed
Course: C Srbject Code: Q. FENCING THE GROUND The college ground is rectangular in shape. The Management decides to build a fence around the ground. ln order to help the construction workers to build a straight fence, they planned to place a thick rope around the ground. They wanted to buy only the exact length of the rope that is needed. They also wanted to cover the entire ground with a thick carpet during rainy season. They wanted to buy only the exact quantity of carpet that is needed. They requested your help. Can you please help them by writing a C program to tind the exact length of the rope and the exact quantity of carper that is required? Input Format: Input consists of 2 integers. The first integer corresponds to the length of the ground and the second integer corresponds to the breadth of the ground. Source Code #|nclude Int main() ( int Length,Width,|en,quan; scanf("°/<>d".&Length); scant("%d'.&W|dth); len=2’(Length+Width); quan=Length'Wldth; printi("Required length is %clm".len); printf("\nRequired quantity of carpet is %dsqm".quan): retum 0:
l Sample Input so 20 Sample Output Required length is 140m Required quantity of carpet is 1000sqm Result Thus, Program " FENCING THE GROUND" has been successfully executed
course: C Srbject Code: Q. Finding bitwise AND of two numbers Write a program to find the bitwise AND of two decimal numbers. An AND gate reads 2 input either 0 or 1 and outputs 1 ifi both the inputs are 1. Similarly write a program to read two decimal numbers and finds AND of two numbers . EXAMPLE : (3)10 = (011)2 (5)10 = (101)2 AND of 3 and 4 is : (1)10 = (001)2 Source Code #include lnt main() l lnt a,b.c; scanf('%d",&a): scanf("%d'.&b)1 c=a&b: printf("Bitwise AND of °/od and %d is:%d".a__b,c); retum 0: l Sample Input 12 23 Sample Output Bitwise AND of 12 and 23 is:4 Result Thus, Program " Finding bitwise AND of two numbers" has been successfully executed
course: C Spbject Code: Q. Finding bitwise EXOR of two numbers Write a program to find the bitwise EXOR of two decimal numbers. An EXOR gate reads 2 input either 0 or 1 and outputs 0 if both the inputs are same and outputs 1 if both the inputs are different. Similarly write a program to read two decimal numbers and finds EXOR of two numbers. EXAMPLE 1 (3) 10 = (011) 2 (5) 10 = (101) 2 EXOR of 3 and 4 is : (6) 10 = (110) 2 Source Code #include lnt main() l lnt a,b.c; scanf("%d".&a); scanf("%d".&b)l c=a"b; printf("Bitwise EX-OR of %d and %d is=°/<>d".a,b.c): retum 0: l Sample Input 12
23 Sample Output Bitwise EX-OR of 12 and 23 is=27 Result Thus, Program " Finding bitwise EXOR of two numbers" has been successfully executed
course: C Srbject Code: Q. Finding OR of two numbers Write a program to find the bitwise OR of two decimal numbers. An OR gate reads 2 input either 0 or 1 and outputs 0 iff both the inputs are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of two numbers . EXAMPLE : (3) 10 = (011) 2 (5) 10 = (101) 2 OR 013 and 4 is : (7) 10 = (111) 2 Source Code #include lnt main() l int a,b.c; scanf("%d".&a); scanf("°/<>d".&b): c=alb; printf("Bltwlse OR of %d and %d is:%d",a,b.c); retum O: l Sample Input 12 23 Sample Output Bitwise OR of 12 and 23 is:31 Result Thus, Program " Finding OR of two numbers " has been successfully executed
course: C Srbject Code: Q. Finding OR of two numbers Write a program to find the bitwise OR of two decimal numbers. An OR gate reads 2 input either 0 or 1 and outputs 0 iff both the inputs are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of two numbers . EXAMPLE : (3) 10 = (011) 2 (5) 10 = (101) 2 OR 013 and 4 is : (7) 10 = (111) 2 Source Code #include lnt main() l lnt a,b.c; scant("%d".&a); scanf("%d".&b)l C=alb: printf("Bitwise OR of %d and %d is=%d".a.b.c): retum 0: l Sample Input 12 23 Sample Output Bitwise on of 12 and 23 is=31 Result
Thus, Program " Finding OR of two numbers " has been successfully executed
Course: C Spbject Code: Q. Find Mode Write a program to find the mode of a given list of integers. Mode of a number is defined as the number which is most frequently occurred. For example. L = {1,2,2,3} // Here mode is 2(most frequently occurred) lt is possible that multiple answers are possible for a list. In that case pnnt all possible answers in non-increasing order lnput' First Line of input contains an lnte er t re resent‘ th . . g p ing e number of test cases, Where first line of each test case has an integers N - number of integers in list, Next line contains N integers. Output: print all the possible modes in non-increasing order. Constraints: 1<=t<=100 1<=N<100000 1<=a[i]<=1000000 Source Code #lnclude #deflne max(a. b) (((a) >= (b)) ‘? (a) : (b)) lnt maln()( int t, n, no, i; scanf("%d", &t); whlle(t-- && scanf("%d", &n)){ int h[1000001] = {O}, m1 = 1. m2 = 0; while(n-- && scanf("%d", &no)) h[no]++, m1 = max(m1_ no); for(i = 1; I <= m1: l++) m2 = max(m2, h[l]); for(i = m1; i >= 1; i--) if(h[l] == m2) printf("%d I); printf("\n'); l return 0; l Sample Input 25122226122334 Sample Output 2 32 Result Thus, Program "Find Mode " has been successfully executed
course: C Spbject Code: Q. Find Remainder Write a program to find the remainder when two given numbers are divided. Input The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two Integers A and B. Output Find remainder when A is divided by B. Constraints 1 ? T’? 10001 ?A,B ? 10000 Source Code #include maln() l int t: scanf("%d".&t); while(t--) l int a,b.c; scanf("%d °/od“, &a,&b); c=a%b2
printt("Remainder is %d\n",c); l l Sample Input 3 1 2 100 200 10 40 Sample Output Remainder is 1 Remainder ls 100 Remainder is 10 Result Thus, Program "Find Remainder " has been successfully executed
course: C Sjibject Code: Q. FOUR SEASONERS Dinesh also joined the group of 3 idiots and now their group is called Four Seasoners. Meanwhile, Binoy has moved to a new house in the same locality. Now the houses of Ajay, Binoy and Chandru are in the located in the shape of a triangle. Dinesh also has moved to a house in the same locality. When Ajay asked Dinesh about the location of his house , Dinesh said that his house is equidistant from the houses of the other 3. Though Ajay was good in Mathematics, he was puzzled. Can you please help Ajay out? Given the 3 vertices {(x1,y1), (x2,y2) and (x3,y3)} of a triangle, write a C program to determine the point which is equidistant from all the 3 vertices. Input Format: Input consists of 6 integers. The first integer corresponds to x1 . The second integer corresponds to y1. The third and fourth integers correspond to x2 and y2 respectively. The fifth and sixth integers correspond to x3 and y3 respectively. Source Code #lnclude lnt maln() l int X1 ,X2.X3,Y1 .Y2.Y3; float a_b; scanf("%d",&X1); scanf("%d"_&Y1); scanf("%d".&X2); scanf("%d".&Y2); scanf("%d".&X3); scanf("%d".&Y3): a=(X1+X2+X3)/3.0: b=(Y1+Y2+Y3)/3.0: printf("Dlnesh house is located at (%.1f.%.1f)\n".a.b); retum 0; l Sample Input 2 4 10 15 5 8 Sample Output Dinesh house is located at (S.7,9.0) Result Thus, Program " FOUR SEASONERS " has been successfully executed
Q Grade The Steel A certain grad one condition ‘ of steel is graded according to the following conditions. Hardness must be greater than 50 Carbon content must be less than 0.7. Tensile strength must be greater than 5600. The grades are as follows: Grade is 10 if all three conditions are met Grade is 9 if course: C Subject Code: e conditions (i) and (ii) are met. Grade is 8 if conditions (ii) and (m) are met. Grade is 7 if conditions (i) and (m) are met Grade is 6 if only is met. Grade is 5 if none of three conditions are met. Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel. Source Code #include maln() l lnt t: scanf("%d",&t); while(t--) t Int hardness, ts, float carbon: .. % scanf( °/od %f grade; d‘, &hardness,&carbon,&ts); if ((hardness>50) && (carbon<0.7) && (ts>5600)) printf("Grade 1O\n"); else if ((hardness>50) && (carbon<0.7)) printf(“Grade 9\n"); else if ((carbon<0.7) && (ts>5600)) printf("Grade 8\n"); else if ((hardness>50) && (ts>5600)) printf("Grade 7\n"); else if ((hardness>50) || (carbon<0.7) || (ts>5600)) printf("Grade 6\n"); else printf("Grade 5\n"); l l Sample Input 2 53 0.7 5602 55 0 5499 Sample Outpu Grade 10 Grade 9 Result Thus, Program t " Grade The Steel " has been successfully executed
course: C Srbject Code: Q. Greedy puppy Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master. He believes that some day he will find a treasure and have loads of bones. And finally he found something interesting. A wooden chest containing N coins! But as you should remember, Tuzik is just a little dog, and so he cant open it by himself. Actually, the only thing he can really do is barking. He can use his barking to attract nearby people and seek their help. He can set the loudness of his barking very precisely, and therefore you can assume that he can choose to call any number of people, from a minimum of 1, to a maximum of K. When people come and open the chest they divide all the coins between them in such a way that everyone will get the same amount of coins and this amount is maximal possible. If some coins are not used they will leave it on the ground and Tuzik will take them after they go away. Since Tuzik is clearly not a fool, he understands that his profit depends on the number of people he will call. While Tuzik works on his barking, you have to find the maximum possible number of coins he can get. Input The first line of the input contains an integer T denoting the number of test cases. Each of next T lines contains 2 space-separated integers: N and K, for this test case. Output For each test case output one integer - the maximum possible number of coins Tuzik can get. Constraints 1 ? T ? 50 1 ? N, K ? 105 In the first example he should call two people. Each of them will take 2 coins and they will leave 1 coin for Tuzik. ln the second example he should call 3 people Source Code #include int main() ( lnt t,m,n; scanf("%d",&t); while(t--) ( int ma = 0; scanf("°/<>d%d"_.&m,8.n); int ii for(i=2;i<=n;i++) lt([m°/oi )> ma)ma = m%l; printf("%d\n",ma): l retum 0: l Sample Input 2 52 113 Sample Output 1 2 Result Thus, Program " Greedy puppy " has been successfully executed
course: C Spbject Code: Q. Multiplication for a child
Jeyanthi daughter name is Han'ni, she was studying 1st Standard in a school. Harinis home work for the third day is to Multiplication of two numbers, help Harini to solve the problem. Source Code #include Int maln() l float a,b.c; scant("%f", &a); scanf("%f“, &b): c=a’b; printf("multipIication of the two numbers is °/».2f",c); retum O; ) Sample Input 12 10 Sample Output multiplication of the two numbers is 120.00 Result Thus, Program "Multiplication for a child” has been successfully executed
course: C Subject Code: Q. PLACING THE FLAG POST The shape of the college ground is Square. For the Independence day Flag Hoisting Function, it has been decided to place the flag post at the exact center of the ground. Can you please help them in placing the flag post at the exact center? Given the coordinates of the left bottom vertex of the square ground and the length of the side, you need to write a program to determine the coordinates of the centre of the ground. [Assumption Length of the side is always even] Input Format: input consists of 3 integers. The first integer corresponds to the x-coordinate of the left bottom vertex. The second integer corresponds to the y-coordinate of the left bottom vertex. The third integer corresponds to the length of the square. Source Code #include int main()( int x,y,l; scanf("%d",&x]; scanf("%d",&y); scanf("%d".&l): x=x+(l/'2); Y=y+(|/'2); printf("centre of the ground is at(%d.%d)",x,y); retum 0: l Sample Input 4 0 a Sample Output centre of the ground is at(8,4) Result Thus, Program " PLACING THE FLAG POST " has been successfully executed
course: C Spbject Code:
Q. Pogo Stick Jump Raju lives in a colony. On his 9th birthday, his father gift him a Pogo Stick. He is so excited to play with pogo stick. The pogo stick moves one unit per jump. He wanders around his house jumping with pogo sticks. He wants to show the pogo stick to his friends and decide to go using pogo sticks. Write a program to find number of jumps needed to reach his friends house. Assume that Rajus house is in the location (3,4). Input and Output Format: Input consists of two integers x, y. The x and y corresponds to x and y coordinates of his friends house. Output is an integer - the number of jumps he needs to reach his friends house. Source Code #lnclude #include int maln() f lnt x1 =3,y1 =4,x2.y2; float power.power1.power2,sqr; scanf("%d",&x2); scanf("%d",&y2); power1=pow((x2-x1 ),2); power2=pow((y2-y1),2); power=p0wer1 +power2; sqr=sqrt(power); printf("Raju needs %.0f jumps",sqr): retum 0: l Sample Input 5 6 Sample Output Raju needs 3 jumps Result Thus, Program " Pogo Stick Jump " has been successfully executed
course: C Srbject Code: Q. PROFIT CALCULATOR Each Sunday, a newspaper agency sells x copies of a certain newspaper for Rs.a per copy. The cost to the agency of each newspaper is Rs.b . The agency pays a fixed cost for storage, delivery and so on of Fts.100 per Sunday. The newspaper agency wants to calculate the profit obtained on Sundays. Can you please help them out by writing a C program to compute the profit given x, a and b. Input Format: Input consists of 3 integers x, a and b. X is the number of copies sold, a is the cost per copy and b is the cost the agency spends per copy. Source Code #|nclude lnt main() l lnt c0ples,cost.spent,profitjinalprofit; scanf("%d",&copies); scanf("%d".&cost): scanf("%d",&spent); profit=((copies'cost)-(copies’spent)); finalproflt=(profit)-100; printf("The profit obtained is Rs=°/>d\n".fina|proflt); it(finalprofit==-100)
printf("invalid input"): retum O: l Sample Input 1000 2 1 Sample Output The profit obtained is Rs=9OO Result Thus, Program “ PROFIT CALCULATOR " has been successfully executed
Course: C Srbject Code: Q. Radius of a Circle Madhan is handling mathematics to 8th grade. He taught area and perimeter of geometric shapes to his students. He thought to give a test based on triangle and circles.The task is to calculate radius of the circle that is inscribed in triangle given the three sides of the triangle. He has set 20 questions and he is tired of preparing answer keys.Write a program to find the radius of the circle inscribed in a triangle. Input and Output Format : Input consists of three integers a, b and c. The three integer corresponds to three sides of a triangle Source Code #lnclude #include int maln() ( int a.b,c; float s,rsq,r; scanf("°/od\n“,&a); scanf("%d\n",&b)I scant("%d".&c); s=(a+b+c)!2; rsq=((s-a)'(s-b)'(s-c)/s); r=sqrt(rsq); printf("The radius of the clrcle is=%.2f\n",r); retum 0; ) Sample Input 3 4 5 Sample Output The radius of the circle is=1.00 Result Thus, Program " Radius of a Circle" has been successfully executed
course: C Szibject Code: Q. Scanning Int and string by retailer Haris retail shop he need a software to get the name of the product and cost of the product and generate a bill for that one product which consist of name of the product and cost of that product. Source Code #include Int maln() l char ch[20];
lnt a; scanf("°/<>s".ch); scanf("%d",&a)I printf("PRODUCT NAME:°/<>s"_ch): printt("\nCOST:%d",a): retum O; l Sample Input soap 121 Sample Output PRODUCT NAME:soap COSTI121 Result Thus, Program "Scanning Int and string by retailer" has been successfully executed
course: C Srbject Code: Q. Splitting into Teams During the Physical Education hour, PT sir has decided to conduct some team games. He wants to split the students in the class into equal sized teams. In some cases, there may be some students who are left out from teams and he wanted to use the left out students to assist him in conducting the team games. For instance, if there are 50 students in the class and if the class has to be divided into 7 equal sized teams, 7 students will be there in each team and 1 student will be left out. PT sir asks your help to automate this team splitting task. Can you please help him out? Input Format: Input consists of 2 integers. The first integer corresponds to the number of students in the class and the second integer corresponds to the number of teams. Source Code #include Int main() l Int students.teams.team,left: scanf("°/<>d".&students); scanf("%d'.&teams); feam=students1‘teams; left=students°/>teams: printf("The number of students in each team is °/od and left out is %d".team.left); retum 0: l Sample Input 60 8 Sample Output The number of students in each team is 7 and left out is 4 Result Thus, Program " Splitting into Teams" has been successfully executed
81 Q Finding St A certain grad one condition ‘ of steel is graded according to the following conditions. Hardness must be greater than 50 Carbon content must be less
than 0.7. Tensile strength must be greater than 5600. The grades are as follows: Grade is 10 if all three conditions are met Grade is 9 if course: C Srbject Cod . ' ' ee e conditions (i) and (ii) are met. Grade is 8 if conditions (ii) and (m) are met. Grade is 7 if conditions (i) and (m) are met Grade is 6 if only is I Grade met. Grade is 5 if none of three conditions are met. Write a program, if the user gives values of hardness, carbon content and tensile strength of the steel under consideration and display the grade of the steel. Source Code #include maln() l lnt t: scanf("%d",&t); while(t--) l Int hardness, ts, float carbon: .. % scanf( %d %f grade; d‘, &hardness,&carbon,&ts); ll ((hardness>50) && (carbon<0.7) && (ts>5600)) printf("Grade 1O\n"); else if ((hardness>50) && (carbon<0.7)) printf(“Grade 9\n"); else if ((carbon<0.7) && (ts>5600)) printf("Grade 8\n"); else if ((hardness>50) && (ts>5600)) printf("Grade 7\n"); else if ((hardness>50) || (carbon<0.7) || (ts>5600)) printf("Grade 6\n"); else printf("Grade 5\n"); l l Sample Input 2 53 0.7 5602 55 0 5499 Sample Outpu Grade 10 Grade 9 Result Thus, Program t " Finding Steel Grade" has been successfully executed
course: C Spbject Code: Q. Summing the N series You are given a sequence whose nth nth term is Tn=n2<(n<=1)2Tn<=n2<=(n<=1)2 You have to evaluate the series Sn=T1+T2+T3+
<=+TnSn=T1+T2+T3+<=+Tn Find Snmod(109+7)Snmod(109+7). Input Format The first line of input contains TT, the number of test cases. Each test case consists of one line containing a single integer nn. Output Format For each test case, print the required answer in a line. Constraints 1<=T<=101<=T<=10 1<=n<=1O"161<=n<=10"16 Source Code #inc|ude #lnclude #include #include #lnclude int main() { int cases; scanf("°/ed‘. &cases); lnt i; for (i=O:i
course: C Srbject Code: Q. Sum of palindromic numbers A number is called palindromic if its decimal representation is a palindrome. You are given a range, described by a pair of integers L and R. Find the sum of all palindromic numbers lying in the range [L, R], inclusive of both the extrema. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a pair of space separated integers L and R denoting the range for which you are required to find the sum of the palindromic numbers. Output For each test case, output a single line containing the sum of all the palindromic numbers in the given range. Constraints 1<=T<=100 Subtask 1 (34 points) : 1<=L<=R<=f03 Subtask 2 (66 points) : 1<=L<=Fk=105 Explanation Example case 1. The palindromic numbers between 1 and 10 are all numbers except the number 10. Their sum is 45. Source Code #lnclude lnt maln() l int t; scanf("%d",&t): while(l--) l lnt a,b;
scanf("%d °/<>d",&a,&b); int i; long int s=0; for(i=a;i<=b;i++) l lnt reverse=0, rem,temp=i; whl|e(templ=0) { rem=temp%1O; reverse=reverse' 1 0+ rem; temp/=10; l if(reverse==i) s+=l1 } printf("sum ls °/>ld\n",s); l return 0; l Sample Input 2 1 10 123 150 Sample Output sum is 45 sum ls 272 Result Thus, Program " Sum of palindromic numbers " has been successfully executed
course: C Srbject Code Q. THREE IDIOTS Ajay, Binoy and Chandru were very close fnends at school They were very good |n Mathematlcs and they were the pet students of Emily Mam. Therr gang was known as 3-ldlots Ajay, Bmoy and Chandru l|ve |n the same localrty A new student Dmesh |o|ns the|r class and he wanted to be fnends w|th them He asked Bmoy about has house address Bmoy wanted to test Dmeshs mathematlcal skrlls Binoy told Dinesh that h|s house |s at the m|dpo|nt of the l|ne ]Oll‘lIt'lg Ajays house and Chandrus house Dmesh was puzzled Can you help Dinesh out’? Gwen the coordlnates of the 2 end pomts of a lme (x1,y1) and (x2 y2), wr|te a C program to fmd the mldpomt of the line. Input Format Input consusts of 4 mtegers The flrst Integer corresponds to x1 The second Integer corresponds to y1 The thrrd and fourth integers correspond to x2 and y2 respectlvely Source Code #|nclude rm maln() f lnt X1 ,X2,Y1 .Y2; float m1.m2,m3; scanf("%d',&X1); scanf("%d",&Y1 ); scanf("°/<>d",&X2); scanf("%d".&Y2); m1=(X1+X2)/2.0; m3=Y1+Y2; m2=m3/2; printf("\nBinoys house ls located at(°/> 1f /0 1f) mf m2) retum 0:
l Sample Input 24 1015 Sample Output Binoys house is located at(6 0 9 5) Result Thus, Program " THREE IDlOTS" has been successfully executed
course: C Srbject Code: Q. Lucy Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new computer on her birthday it she solves the question asked by him. He asks Lucy to find whether the year on which she had born is leap year or not. Help her to solve this puzzle so that she celebrates her birthday happily. If her birth year is 2016 and it is a leap year display 2016 is a leap year.? Else display 2016 is not a leap year and check with other leap year conditions Source Code #lnclude lnt maln() l Int year; //printf("Enter a year to check if it is a leap year\n'); scanf("%d', &year); If ( year%40O == 0) prlntf(“%d is a leap year‘. year); else it ( year‘/@100 == 0) printi("%d is not a leap year", year); else ii ( year%4 == 0 ) printf("°/>d is a leap year‘. year); else printf("%d is not a leap year", year); retum O: l Sample Input 1900 Sample Output 1900 is not a leap year Result Thus, Program " Lucy " has been successfully executed
Course: C Spbject Code: Q. Biased Chandan Chandan is an extremely biased person, and he dislikes people who fail to solve all the problems in the interview he takes for hiring people. There are n people on a day who came to be interviewed by Chandan. Chandan rates every candidate from 0 to 10. He has to output the total ratings of all the people who came in a day. But, heres the problem: Chandan gets extremely frustrated when someone ends up scoring a 0 in the interview. So in frustration he ends up removing the candidate who scored that 0, and also removes the candidate who came before him. If there is no candidate before the one who scores a 0, he does nothing.Youve to find the summation of all the ratings in a day for Chandan. Input constraints: The first line of input
will contain an integer n. The next n lines will contain an integer, where the ith integer represents the rating of the ith person. Output constraints: Print the required sum. Constraints: 1 <= n <= 5 ‘ 103 0 <= Value of ratings <=1 0 Source Code #incIude int maln() i int n,i,sum=O: scanf("%d".&n)1 int a[n]: for(i=0;i1)( for(i=1;i
course: C Srbject Code: Q. Doll Show In London, Every year during Dasara there will be a very grand doll show. People try to invent new new dolls of different varieties. The best sold dolls creator will be awarded with cash prize . So people broke their head to create dolls innovativeiy .Knowing this competition, Mr. LokPaul tried to create a doll which sings only when a even number is pressed and the number should not be zero and greater than 100. So write a C program to help mr. Lokpaul to win. Input format: lnput consists of 1 integer which corresponds to Number pressed by the user to the doll. Output format : Display whether the doll will a sing or not. Output consists of the string "Doll will sing" or "Invalid number" Refer sample input and output for further formatting specifications. Source Code #lnclude Int main()( lnt x; char a[20]='Doll will sing'.b[20]="lnvalld Number"; scanf("%d",&x); if(x<100 && x%2==0 && xl=0) {
prinlf("%s\n",a); I else { pl’ll‘llT("°/o$\l'l",D)§ ) return 0; } Sample Input 56 Sample Output Doll will sing Result Thus, Program " Doll Show " has been successfully executed
Course: C ?;.lb]8Cl Code: Q. Leap year Raghuraman is the worrisome as well as caring father of his only daughter bharani ,together they live a calm and content life. Over the years as Bharani grows up , Raghuramam got more and more attached to his daughter bharani. As bijarani is very intelligent and bright in her studies. She got a good placement offer in canada. Raghuraman was shocked.Although the thought of being separated from his dead daughter is heartbreaking. Raghuraman wearily accepts. Bharani promises her that she will come home once every leap year. Raghuraman was waiting for his daughter arrival. He doesnt know which is leap year. So write a C program to help Flaghumaran to find a whether the year is a leap year. Input format: Input consists of single integer which corresponds to a year Output format 1 Displays whether the given year is a leap year or not. Refer sample input and output for further formatting specifications. Source Code #lnclude int maln() t Int a: //printf("Enter a year to check if it is a leap year\n"); scanf('°/ad", &a); if ((a%4==0)&&((a%100l=0)][(a%400==0))) l printf("Leap Year"); } else l printf("Not a Leap year"); } retum O: l Sample Input 2004 Sample Output Leap Year Result Thus, Program "Leap year " has been successfully executed
course: C Spbject Code: Q. Approximate Value Phineas and Ferb who live in the fictional town of danville ,think and do innovatively on weekends. Every day the boys embark on some grand new project, which annoys their controlling sister candace, who tries to bust them. One sunday they were both sitting under a tree in their back yard. They decide to invent a machine which would allow us to enter 2 numbers it would say whether one of the entered number is an appropriate value of the other number entered. They decide to insert a program code in the machine. A number is said to be an approximate value of the other if they differ by utmost 0.5. So write a C program to find whether the given number is approximate number of other. Input Format: Input consists of two float type numbers Output format: Displays whether the number is approximate or not. Source Code #lnclude Int maln()( int x.y,c; scanf("%d°/od',&x_&y): if(y>X) I c=y-x; I else I c=x-y; 1 lf(c<=0.5) { printf("ApproxImate number"); ) GISG I prinlf("Not an Approximate number"); 1 return 0; ) Sample Input 14 14.3 Sample Output Approximate number Result Thus, Program " Approximate Value " has been successfully executed
course: C Srbject Code: Q. A Task A task is given to 3 persons to complete it within a particular time. If the person exceeds the time limit he will be disqualified . Only those who complete it within the given time limit is qualified. Among the qualified persons. the person who complete the task first will be rewarded. Write C program to find the person who is rewarded.Write a C program to find the person who is rewarded. Input Format: First Input corresponds to the time limit for the task in hours . Second, third and fourth input corresponds to the number of hours taken by the first, second and third persons respectively to complete the task. Output