C Programming :
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Output
Download
Download
Copy
Checkout all my projects
here
Visit our business portfolio website
here
/*Write a program in C to print 'Hello, World!'*/ #include
int main () { printf ("\nHello, World!"); return 0; }
/*WAP in C to perfrom addition of two integers*/ #include
int main () { int a, b, s; printf ("\nEnter the first integer: "); scanf ("%d", &a); printf ("\nEnter the second integer: "); scanf ("%d", &b); s = a + b; printf ("\nThe result of %d + %d = %d",a,b,s); return 0; }
/*WAP in C to check a (whole) number is even or odd*/ #include
int main () { int n; printf ("\nEnter the number: "); scanf ("%d", &n); if (n%2==0) printf("\n%d is an even number", n); else printf("\n%d is a odd number", n); return 0; }
/*Write a program in C to find the maximum of three integers*/ //Using a fourth variable => Preffered #include
int main () { int a, b, c, max=0; printf ("\nEnter the three numbers: "); scanf ("%d %d %d", &a, &b, &c); if (a>max) max=a; //stores the highest value in max if (b>max) //do not use else if, reason: next comment max=b; if (c>max) //else if => wouldn't check further cond. if satisfied max=c; printf("\n%d is the largest number", max); return 0; }
/*Write a program in C to find the maximum of three integers*/ //Without using a fourth variable => Not preffered #include
int main () { int a, b, c; printf ("\nEnter the first number: "); scanf ("%d", &a); printf ("\nEnter the second number: "); scanf ("%d", &b); printf ("\nEnter the third number: "); scanf ("%d", &c); if (a>b) { if (a>c) printf("\n%d is the largest number", a); else printf("\n%d is the largest number", c); } else { if (b>c) printf("\n%d is the largest number", b); else printf("\n%d is the largest number", c); } return 0; }
/*Write a program in C to print from 1 to n*/ //Using a while (condition) loop #include
int main () { int n, i=1; printf ("\nEnter the limit: "); scanf ("%d", &n); while (i <= n) { printf("\n%d", i); i++; //incrementing value of i by 1 } return 0; }
/*Write a program in C to print grade of students*/ //Switch case => grading, if/else => validations, round() => round off #include
#include
int main () { int result; float m1, m2, m3, resultFloat; printf ("\nEnter the marks of three subjects: "); scanf ("%f%f%f", &m1, &m2, &m3); if ((m1>100 || m2>100 ||m3>100) || (m1<0 || m2<0 || m3<0)) //validates inputs printf ("\nEneter valid marks of each subject (out of 100)"); else { resultFloat = (m1+m2+m3)/3; printf("\nThe average of marks entered is %f",resultFloat); result = round((m1+m2+m3)/3); printf("\nRounding off avg. marks...\nNew avg. marks: %d",result); switch (result) { case 91 ... 100: printf ("\nGrade 'O'"); break; case 81 ... 90: printf ("\nGrade 'E'"); break; case 71 ... 80: printf ("\nGrade 'A'"); break; case 61 ... 70: printf ("\nGrade 'B'"); break; case 51 ... 60: printf ("\nGrade 'C'"); break; case 40 ... 50: printf ("\nGrade 'D'"); break; case 0 ... 39: printf ("\nGrade 'F' (Fail)"); break; default: printf ("\nAn error occured while caculation"); } } return 0; }
/*Write a program in C to print grade of students*/ //if/else if => grading, if/else => validations, round() => round off #include
#include
int main () { int result; float m1, m2, m3, resultFloat; printf ("\nEnter the marks of three subjects: "); scanf ("%f%f%f", &m1, &m2, &m3); if ((m1>100 || m2>100 ||m3>100) || (m1<0 || m2<0 || m3<0)) //validates inputs printf ("\nEneter valid marks of each subject (out of 100)"); else { resultFloat = (m1+m2+m3)/3; printf("\nThe average of marks entered is %f",resultFloat); result = round((m1+m2+m3)/3); printf("\nRounding off avg. marks...\nNew avg. marks: %d",result); if (result >= 91 && result <=100) printf ("\nGrade 'O'"); else if (result >= 81 && result <=90) printf ("\nGrade 'E'"); else if (result >= 71 && result <=80) printf ("\nGrade 'A'"); else if (result >= 61 && result <=70) printf ("\nGrade 'B'"); else if (result >= 51 && result <=60) printf ("\nGrade 'C'"); else if (result >= 40 && result <=50) printf ("\nGrade 'D'"); else if (result >= 0 && result <40) printf ("\nGrade 'F' (Fail)"); else printf ("\nAn error occured while caculation"); } return 0; }
/*WAP in C to check a number is palindrome(madam) or not*/ //125 != 521 => not palindrome, 121=121 => palindrome #include
int main () { int n, m, r, d=0; printf ("\nEnter the number: "); scanf ("%d", &n); m = n; //duplicating the value of n in m while (n!=0) { //these operations inter-change(swap) the positions e.g. 125 as 521. r = n % 10; d = d * 10 + r; n = n / 10; } if (m == d) printf ("\nAs %d = %d. Therefore %d is a palindrome no.", m ,d, m); else printf ("As %d != %d. Therefore %d is not palindrom no.", m ,d, m); return 0; }
/*WAP in C to calculate the factorial of a number*/ #include
int main () { int n, i, f=1; printf ("\nEnter the number to its calculate factorial: "); scanf ("%d", &n); for (i=1; i<=n; i++) //increments loop by i++ i.e. i=i+1 { f = f * i; } printf ("\nFactorial of %d is %d", n, f); return 0; }
/*WAP in C to print the sum of folwoing series*/ //Calculate Sum of Series: 1+2+3+4+5+....n = sum #include
int main () { int n, i, sum=0; printf ("\nEnter the limit of the series to calculate its sum: "); scanf ("%d", &n); for (i=1; i<=n; i++) //increment done after updating sum { sum = sum +i; } printf ("\nSum of the series: %d", sum); return 0; }
/*WAP in C to print the following series and its sum*/ //Print Series & Sum: '1+2+3+4+5+....n = sum' #include
int main () { int n, i, sum=0; printf ("\nEnter the limit of the series: "); scanf ("%d", &n); for (i=1; i<=n; i++) //for calculating sum; { sum = sum +i; } for (i=1; i
/*WAP in C to print the following series and its sum*/ //Print Series & Sum: '1+3+5+7+....n = sum' #include
int main () { int n, i, sum=0; printf ("\nEnter the limit of the series: "); scanf ("%d", &n); for (i=1; i
/*WAP in C to print the following series and its sum*/ //Print Series & Sum: '1+2+4+7+11+....n = sum' #include
int main () { int n, i, k=0, sum=0; printf ("\nEnter the limit of the series: "); scanf ("%d", &n); for (i=1; i
/*Write a program in C to print the following pattern: 1 2 3 4 5 6 7 8 9 10 */ #include
int main () { int n, i, j, k; printf ("\nEnter the total number of lines: "); scanf ("%d", &n); k = 1; for (i=1; i<=n; i++) //outer loop i => maintains line no. { printf ("\n"); for (j=1; j<=i; j++) //nested loop j => nos. in each line { printf ("%d ",k); k++; } } return 0; }
/*Write a program in C to print the following pattern: 1 2 3 3 4 5 4 5 6 7 5 6 7 8 9 */ #include
int main () { int n, i, j, k; printf ("\nEnter the total number of lines: "); scanf ("%d", &n); for (i=1; i<=n; i++) //outer loop i => maintains line no. { k = i; /*starts line with value = current line no., starting of line (k) = line no. (i)*/ printf ("\n"); for (j=1; j<=i; j++) //nested loop j => nos. in each line { printf (" %d ",k); //placed 1 bar space after each no. k++; } } return 0; }
/*Write a program in C to print the following pattern: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 */ #include
int main () { int n, i, j; printf ("\nEnter the total number of lines: "); scanf ("%d", &n); for (i=1; i<=n; i++) //outer loop i => maintains line no. { printf ("\n"); for (j=1; j<=i; j++) //inner loop j => nos. in each line { printf (" %d ",j); //1 bar space } } return 0; }
/*Write a program in C to print the following pattern: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 */ #include
int main () { int n, i, j, k; printf ("\nEnter the total number of lines: "); scanf ("%d", &n); for (i=1; i<=n; i++) //outer for loop i => maintains line no. { printf ("\n"); for (j=1; j<=n-i; j++) //inner for loop j => nos. in each line { printf (" "); //placed 2 bar space after each no. } for (k=1; k<=i; k++) printf ("%d ", k);// } return 0; }
/*Write a program in C to print the following pattern: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 */ #include
int main () { int n, i, j, k, l; printf ("\nEnter the total number of lines: "); scanf ("%d", &n); for (i=1; i<=n; i++) //outer loop i => maintains line no. { printf ("\n"); for (j=1; j<=n-i; j++) //inner loop j => nos. in each line { printf (" "); //placed 2 bar space after each no. } for (k=1; k<=i; k++) printf ("%d ", k); /*Till here left side of the pattern will be printed*/ for (l=i-1; l>=1;l--) //prints the right half of the pattern printf ("%d ", l); } return 0; }
/*WAP in C to raise one number to the power of another*/ #include
#include
int main () { int b, p ,r; printf ("\nEnter the base value: "); scanf ("%d", &b); printf ("\nEnter the power value: "); scanf ("%d", &p); r = pow (b, p); //must include math.h header file printf("\nThe result of %d ^ %d = %d", b, p, r); return 0; }
/*WAP in C to print the following series and its sum*/ //Series: 1+2^2+3^3+4^4+5^5+_ _ _ _n^n = sum #include
#include
int main () { int n, i; unsigned long long int sum = 0; //larger data type than int printf ("\nEnter the limit or last digit (only base) of series: "); scanf ("%d", &n); for (i=1; i<=n; i++) { sum = sum + (unsigned long long int) pow(i, i); } printf ("\n1"); for (i=2; i<=n; i++) //for continuing series after '1 + 2' { printf (" + %d ^ %d", i, i); } printf(" = %llu", sum); return 0; }
/*Write a program in C to print the following series's sum*/ //Series: 1+2^2+3^3+4^4+5^5+_ _ _ _n^n = sum #include
#include
int main () { int n, i; unsigned long long int sum = 0; //larger data type than int printf ("\nEnter the limit or last digit (only base) of series: "); scanf ("%d", &n); for (i=1; i<=n; i++) { sum = sum + (unsigned long long int) pow(i, i); } printf("\nThe sum of the series = %llu", sum); return 0; }
/*WAP in C to print the following series and its sum*/ //Series: 1+2+3^2+4^3+5^4+_ _ _ _n^n-1 = sum #include
#include
int main () { int n, i; unsigned long long int sum = 0; // use a larger data type than int printf ("\nEnter the limit or last digit (only base) of series: "); scanf ("%d", &n); for (i=1; i<=n; i++) { sum = sum + (unsigned long long int) pow(i, i-1); } printf ("\n1 + 2"); for (i=3; i<=n; i++) //for continuing series after '1 + 2' { printf (" + %d ^ %d", i, i-1); } printf(" = %llu", sum); return 0; }
/*Write a program in C to check a number is prime or not*/ //Used tenary conditional operator in C for if else #include
int main () { int n, i, q=0; //q is used as a flag printf ("\nEnter the number: "); scanf ("%d", &n); for (i=2; i
/*Write a program in C to print the following series's sum*/ // Series: 1+(2/1!)+(3/2!)+(4/3!)+_ _ _ _(n/n-1!)=sum #include
int main () { int n, i, j, fact; float term, sum=1.0; printf ("\nEnter the limit or last digit (only numberator's') of series: "); scanf ("%d", &n); for (i=2; i<=n; i++) { fact = 1; //intialising fact here gives correct output for (j=1; j
/*WAP in C to add two integers using a user defined function*/ #include
int Add(int, int); //prtotype declration int main () { int a, b, c; //q is used as a flag printf ("\nEnter two numbers to add: "); scanf ("%d %d", &a, &b); c = Add(a, b); //function calling printf ("\nThe result of %d + %d = %d", a, b, c); return 0; } int Add(int x, int y) //function with parameters, a => x, b => y { int z; z = x + y; return printf ("\nUsing Add() function"), z; }