ASSIGNMENT ON C - PROGRAMING.pdf

Full Transcript

❖ PROGRAM – 1 QUESTION : WAP TO PRINT “Hello World”. ALGORITHM – 1. Start 2. Display Hello World 3. Stop SOURCE CODE – #include int main() { Printf(“Hello Wold”); return 0; } OUTPUT – Hello World ❖ PROGRAM – 2 QUESTION...

❖ PROGRAM – 1 QUESTION : WAP TO PRINT “Hello World”. ALGORITHM – 1. Start 2. Display Hello World 3. Stop SOURCE CODE – #include int main() { Printf(“Hello Wold”); return 0; } OUTPUT – Hello World ❖ PROGRAM – 2 QUESTION: WAP TO PRINT ASCII VALUE OF ANY CHARACTER. ALGORITHM – 1. Start 2. Input any character 3. Calculate ASCII value 4. Display ASCII value of the character 5. Stop SOURCE CODE – #include int main() { char c; printf("enter any character : "); scanf("%c",&c); printf("ASCII value of %C is %d",c,c); return 0; } OUTPUT – Enter any character : c ASCII value of c is 9 ❖ PROGRAM – 3 QUESTION : WAP TO PRINT SUM AND AVERAGE OF TWO NUMBERS. ALGORITHM – 1. Start 2. Input any two numbers 3. Calculate the sum of two numbers 4. Calculate the average of two numbers 5. Display the sum and average of those numbers 6. Stop SOURCE CODE – #include int main() { int a,b,sum; float avg; printf("Enter first numbers : "); scanf("%d",&a); printf("Enter second numbers : "); scanf("%d",&b); sum = (a + b); avg = (a+b)/2; printf("Sum = %d\n",sum); printf("Average = %f\n",avg); return 0; } OUTPUT – Enter first numbers : 3 Enter second numbers : 7 Sum = 10 Average = 5.000000 ❖ PROGRAM – 4 QUESTION: WAP TO CALCULATE TOTAL AND PERCENTAGE OF MARKS OF 5 SUBJECT OF A STUDENT. ALGORITHM – 1. Start 2. Input the marks of 5 subjects 3. Calculate the total of marks of 5 subjects 4. Calculate the percentage of marks of 5 subjects 5. Display total and percentage of marks 6. Stop SOURCE CODE – #include int main() { int s1,s2,s3,s4,s5,total; float percent; printf("Enter marks of first subject : "); scanf("%d",&s1); printf("Enter marks of second subject : "); scanf("%d",&s2); printf("Enter marks of third subject : "); scanf("%d",&s3); printf("Enter marks of fourth subject : "); scanf("%d",&s4); printf("Enter marks of fifth subject : "); scanf("%d",&s5); total = s1+s2+s3+s4+s5; percent = total/5; printf("Total of your marks = %d\n",total); printf("Percentage of your marks = %f\n",percent); return 0; } OUTPUT – Enter marks of first subject : 100 Enter marks of second subject : 100 Enter marks of third subject : 100 Enter marks of fourth subject : 100 Enter marks of fifth subject : 100 Total of your marks = 500 Percentage of your marks = 100.000000 ❖ PROGRAM – 5 QUESTION : WAP TO CHECK WHETHER ENTERED NUMBER IS ODD OR EVEN. ALGORITHEM – 1. Start 2. Input any number 3. Use conditional statement (If number % 2 == 0 ) 4. Display number is even 5. Else display number is odd 6. Stop SOURCE CODE – #include int main() { int n; printf("Enter any number : "); scanf("%d",&n); if(n % 2 == 0) { printf("Given number %d is even",n); } else { printf("Given number %d is odd",n); } return 0; } OUTPUT – Enter any number : 56 Given number 56 is even ❖ PROGRAM – 6 QUESTION : WAP TO CHECK WHETHER THE NUMBER IS PRIME OR NOT PRIME. ALGORITHM – 1. Start 2. Input the number 3. Check if the number less than or equal to 1 4. Initialize 5. Loop from 2 to num / 2 6. Check the value of the flag 7. Stop SOURCE CODE – #include int main() { int i, num ,flag = 0; printf("Enter an positive integer : "); scanf("%d",&num); if (num 10,000 BASIC = 1000 DA = 10% OF BASIC HRA = 10% OF BASIC BONUS = 500 IF SALES < 10,000 BASIC = 1000 DA = 5% OF BASIC HRA = 5% OF BASIC BONUS = 200 ALGORITHM – 1. Start 2. Input the sale amount. 3. Set the basic salary to 1000. 4. If sale amount is greater than 10,000 Set DA to 10% of the basic salary. Set HRA to 10 % of the basic salary. Set bonus to 500. 5. Stop SOURCE CODE – #include int main(){ float sales,basic = 1000, da ,hra, bonus, total_salary; printf("Enter the sale amount : "); scanf("%f",&sales); if (sales > 10,000) { da = 0.1* basic; hra = 0.10*basic; bonus = 500; } else { da = 0.5*basic; hra = 0.5*basic; bonus = 200; } total_salary = basic + da + hra + bonus; printf("Total salary: %.2f \n",total_salary); return 0; } OUTPUT – Enter the sale amount : 11000 Total salary: 2200.00 ❖ PROGRAM – 8 QUESTION : WAP TO CHECK LARGEST NUMBER FROM THREE ENTERED NUMBER. ALGORITHM – 1. Start 2. Input number 1 ,2 and 3 3. If num1 >num2 and num1>num3 print num1 4. else if num2>num3 print num2 5. else print num3. 6. End SOURCE CODE – #include int main() { int num1, num2, num3; printf("Enter first number : "); scanf("%d",&num1); printf("Enter second number : "); scanf("%d",&num2); printf("Enter third number : "); scanf("%d",&num3); if(num1 > num2 && num1 > num3) { printf("The largest number is %d.\n", num1); } else if(num2 > num3) { printf("The largest number is %d.\n", num2); } else { printf("The largest number is %d.\n",num3); } return 0 ; } OUTPUT – Enter first number : 79 Enter second number : 100 Enter third number : 800 The largest number is 800 ❖ PROGRAM – 9 QUESTION : WAP TO CHECK ENTERED NUMBER IS POSITIVE , NEGATIVE OR ZERO. ALGORITHM – 1. Start 2. Input any number 3. If number is greater than zero Print number is positive 4. If number is less than zero Print number is negative 5. If number is equal to zero Print number is zero 6. Stop SOURCE CODE – #include int main() { int n; printf("Enter any number : "); scanf("%d",&n); if(n > 0) { printf("The given number %d is positive.",n); } else if (n < 0){ printf("The given number %d is negative",n); } else { printf("The given number %d is zero",n); } return 0; } OUTPUT – Enter any number : 0 The given number 0 is zero Enter any number : -6 The given number -6 is negative ❖ PROGRAM – 10 QUESTION : WAP TO CHECK GRADES OF A STUDENT ACCORDING TO THE MARKS USING IF ELSE IF. ALGORITHM – 1. Start 2. Input your grade 3. If grade >=90 and grade =80 and grade =70 and grade = 30 and grade =90 && marks =80 && marks =60 && marks =30 && marks

Use Quizgecko on...
Browser
Browser