WHAT'S NEW?
Loading...
Showing posts with label C. Show all posts
Showing posts with label C. Show all posts


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char ch[200];

void print() {
    printf("\nEnter the message: ");
    gets(ch);
}

void ntime() {
    int n, i;
    n = strlen(ch);
    printf("The above message is printed %d times below:", n);
    for (i = 0; i < n; i++)
        printf("\n%s", ch);
    printf("\n");
}

void revo() {
    printf("The message in reverse order is: ");
    printf("%s\n", strrev(ch));
}

void change() {
    int i, j;
    i = strlen(ch);
    for (j = 0; j < i; j++) {
        if (ch[j] >= 'a' && ch[j] <= 'z')
            ch[j] -= 32;
        else if (ch[j] >= 'A' && ch[j] <= 'Z')
            ch[j] += 32;
        else
            continue;
    }
    puts(ch);
}

void block() {
    int i, j, n;
    n = strlen(ch);
    printf("The given message in block staircase pattern is: \n");
    for (i = 0; i < n; i++) {
        for (j = 0; j <= i; j++)
            printf("%c", ch[j]);
        printf("\n");
    }
    printf("\n");
}

void main() {
    int a;
    while (1) {
        printf("\nMENU");
        printf("\n1.Print message no. of time as per its length");
        printf("\n2.Print the message in reverse order");
        printf("\n3.Print the message in block staircase pattern");
        printf("n4.Print the message in capital letters and vice versa");
        printf("\n5.Exit from program");
        printf("\n\nEnter your choice: ");
        scanf("%d", &a);
        switch (a) {
        case 1:
            ntime();
            break;
        case 2:
            revo();
            break;
        case 3:
            block();
            break;
        case 4:
            change();
            break;
        case 5:
            exit(1);
        default:
            printf("Invalid choice\n");
        }
    }
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

void lucky();
float ctof();
float sqr();
long int fact();
int a;
void main() {
    int ch;
    while (1) {
        printf("\nMENU");
        printf("\n1.%cC to %cF conversion\n2.Square root of a number");
        printf("\n3.10 Lucky numbers between two numbers");
        printf("\n4.Factorial of given number");
        printf("\n9.Abandon the program",248,248);
        printf("\n\nEnter your choice: ");
        scanf("%d", &ch);
        switch (ch) {
        case 1:
            printf("Temp in %cF is: %.2f\n", 248, ctof());
            break;
        case 2:
            printf("Square root of the number is: %.2f\n", sqr());
            break;
        case 3:
            lucky();
            break;
        case 4:
            printf("Factorial of %d! is: %ld\n", a, fact());
            break;
        case 9:
            exit(1);
        default:
            printf("Invalid choice\n");
        }
    }
}

float ctof() {
    float fah;
    float cel;
    printf("Enter temp in %cC: ", 248);
    scanf("%f", &cel);
    fah = (9 * cel + 160) / 5;
    return (fah);
}

float sqr() {
    float sqr, no;
    printf("Enter the number: ");
    scanf("%f", &no);
    sqr = sqrt(no);
    return (sqr);
}

long int fact() {
    int i;
    long int pro = 1;
    printf("Enter the number: ");
    scanf("%d", &a);
    for (i = 0; (a - i) > 0; i++)
        pro = pro * (a - i);
    return (pro);
}

void lucky() {
    int b, c, i;
    printf("Enter the two numbers: \n");
    scanf("%d%d", &a, &b);
    printf("\n10 Lucky numbers between %d and %d are: \n", a, b);
    for (i = 0; i < 10;) {
        c = rand();
        if ((c > a && c < b) || (c > b && c < a)) {
            printf("%-5d", c);
            i++;
        }
    }
    printf("\n");
}


#include<stdio.h>
#include<stdlib.h>

void threeno();
int sumno(int);
int sumos(int);
int pro(int);
int a, b, c;

void main() {
    int ch, x;
    while (1) {
        printf("\nMENU");
        printf("\n1.Input three numbers");
        printf("\n2.Summation of the numbers\n3.Sum of squares");
        printf("\n4.Product of the three numbers");
        printf("\n5.Exit from program");
        printf("\n\nEnter your choice: ");
        scanf("%d", &ch);
        switch (ch) {
        case 1:
            threeno();
            break;
        case 2:
            printf("Summation of the numbers is: %d\n", sumno(x));
            break;
        case 3:
            printf("Sum of squares is: %d\n", sumos(x));
            break;
        case 4:
            printf("Product of the numbers is: %d\n", pro(x));
            break;
        case 5:
            exit(1);
        default:
            printf("Invalid choice\n");
        }
    }
}

void threeno() {
    printf("Enter the three numbers: \n");
    scanf("%d%d%d", &a, &b, &c);
}

int sumno(int sum) {
    threeno();
    sum = a + b + c;
    return (sum);
}

int sumos(int sum) {
    threeno();
    sum = a * a + b * b + c * c;
    return (sum);
}

int pro(int pro) {
    threeno();
    pro = a * b * c;
    return (pro);
}

/*Find the sum of two matrices*/
#include<stdio.h>

void main() {
    int i, j;
    int A[3][5] = { { 2, 1, 3, 7, 6 }, { 8, 13, 4, 0, 1 }, { 1, 2, 3, 4, 5 } },
        B[3][5] = { { 0, 1, 2, 3, 4 }, { 9, 1, 2, 6, 7 }, { 4, 0, 3, 7, 1 } },
        C[3][5];
    for (i = 0; i < 3; i++)
        for (j = 0; j < 5; j++)
            C[i][j] = A[i][j] + B[i][j];
    printf("\nThe matrix C is:\n");
    for (i = 0; i < 3; i++) {
        for (j = 0; j < 5; j++)
            printf("%3d  ", C[i][j]);
        printf("\n");
    }
}

/*Program to Print Fibonacci terms*/
#include<stdio.h>

void main() {
    int a, b, c, i, n;
    printf("\nEnter the first two numbers: ");
    scanf("%d %d", &a, &b);
    printf("Enter the value of n: ");
    scanf("%d", &n);
    printf("\nThe %d Fibonacci terms are: ", n);
    printf("%d, %d", a, b);
    for (i = 2; i < n; i++) {
        c = a + b;
        a = b;
        b = c;
        printf(", %d", c);
    }
}


/*Check if a phrase is Palindrome*/
#include<stdio.h>
#include<string.h>

void main() {
    char phr[50], phrs[50];
    int i, j;
    printf("\nEnter the phrase: ");
    gets(phr);
    i = strlen(phr);
    for (j = 0; j < i; j++) {
        phrs[j] = phr[i - 1 - j];
    }
    if (strcmpi(phr, phrs) == 0)
        printf("\nIt is a palindrome");
    else
        printf("\nIt is not a palindrome");
}


/*Convert lowercase letters to uppercase*/
#include<stdio.h>
#include<string.h>

void main() {
    char phr[50];
    int i;
    clrscr();
    printf("\nEnter the phrase in small letter:\n");
    gets(phr);
    for (i = 0; i < 50; i++)
        phr[i] = toupper(phr[i]);
    puts(phr);
}


/*Program to reverse array elements*/
#include<stdio.h>

void main() {
    int A[10], i, temp;
    printf("\nEnter the ten numbers:\n");
    for (i = 0; i < 10; i++)
        scanf("%d", &A[i]);
    for (i = 0; i < 5; i++) {
        temp = A[i];
        A[i] = A[9 - i];
        A[9 - i] = temp;
    }
    printf("\nReverse order is:\n");
    for (i = 0; i < 10; i++)
        printf("\n%d", A[i]);
}


/*Program to interchange array elements*/
#include<stdio.h>

void main() {
    int A[10] = { 21, 3, 61, 80, 9, 73, 0, 5, 1, 2 }, i, B[10];
    for (i = 0; i < 10; i += 2) {
        B[i] = A[i + 1];
        B[i + 1] = A[i];
    }
    printf("\nOriginal array is: ");
    for (i = 0; i < 10; i++)
        printf("%d  ", A[i]);
    printf("\nInterchanged array is: ");
    for (i = 0; i < 10; i++)
        printf("%d  ", B[i]);
}


/*C Program to find deviation from average of a given data*/
#include<stdio.h>
#include<math.h>

void main() {
    int temp[7], i, sum = 0, av;
    float dev;
    printf("\nEnter the seven days temperature:\n");
    for (i = 0; i < 7; i++) {
        scanf("%d", &temp[i]);
        sum += temp[i];
    }
    av = sum / 7;
    for (i = 0; i < 7; i++) {
        dev = av - temp[i];
        dev = fabs(dev);
        printf("deviation= %3.1f\n", fabs(dev));
    }
}


/*C Program to print the sum of digits of a number*/
#include<stdio.h>

void main() {
    int n1, sum = 0;
    long int no;
    printf("Enter the number: ");
    scanf("%ld", &no);
    while (no != 0) {
        n1 = no % 10;
        no = no / 10;
        sum = sum + n1;
    }
    printf("\nSum=%d", sum);
}


/*C Program to give a conditional decision*/
#include<stdio.h>

void main() {
    int cnt = 0, a = 0, b = 0, c = 0, age;
    for (cnt = 0; cnt < 15; cnt++) {
        printf("Enter the age: ");
        scanf("%d", &age);
        if (age <= 15)
            a++;
        else if (age <= 17)
            b++;
        else
            c++;
    }
    printf("\nStill a baby= %d", a);
    printf("\nAttending school= %d", b);
    printf("\nAdult life= %d", c);
}


/*print all three digit Armstrong numbers*/
#include<stdio.h>

void main() {
    int n, n1, n2, n3, n4, t;
    printf("\nThe three digit Armstrong numbers are: ");
    for (n = 100; n <= 999; n++) {
        n1 = n % 10;
        n2 = n / 10;
        n3 = n2 % 10;
        n4 = n2 / 10;
        t = n1 * n1 * n1 + n4 * n4 * n4 + n3 * n3 * n3;
        if (n == t)
            printf("%9d", t);
    }
}

/*to print multiplication table of any given integer number*/
#include<stdio.h>

void main() {
    int a, i, pro;
    printf("\nEnter the number: ");
    scanf("%d", &a);
    for (i = 1; i <= 10; i++) {
        pro = a * i;
        printf("\n%3d X %-3d= %3d", a, i, pro);
    }
}

/*program to print ascii characters for code 32 to 255*/
#include<stdio.h>

void main() {
    int i;
    for (i = 32; i < 255; i++)
        printf("%2c= %d", i, i);
}


/*A menu program to check if the given number is odd or even, to find the sum of N natural numbers and to find the sum of squares of two numbers*/
#include<stdio.h>
#include<stdlib.h>

void main() {
    int ch;
    char y;
    int n, a, sum = 0;
    while (1) {
        printf("\nMENU");
        printf("\n1.To check if the given no is odd or even");
        printf("\n2.To find the sum of N numbers");
        printf("\n3.To find the sum of squares of two numbers");
        printf("\n4.Exit from Program");
        printf("\nEnter the choice: ");
        scanf("%d", &ch);
        switch (ch) {
        case 1:
            printf("\nEnter the no. ");
            scanf("%d", &n);
            if ((n % 2) == 0)
                printf("\nIt is even");
            else
                printf("\nIt is odd");
            break;
        case 2:
            printf("\nEnter the value of N: ");
            scanf("%d", &n);
            for (a = 1; a <= n; a++)
                sum = sum + a;
            printf("\nSum= %d", sum);
            break;
        case 3:
            printf("\nEnter the two numbers: ");
            scanf("%d,%d", &a, &n);
            sum = a * a + n * n;
            printf("\nSum of squares is: %d", sum);
            break;
        case 4:
            exit(1);
        default:
            printf("\nInvalid choice");
        }
    }
}

In Turbo C IDE, when the code written in the editor is ready to compile, go to compile menu in Menu bar of Turbo C IDE and Click compile. Shortcut Key: Alt+F9. If your code is error free then the successful compilation will produce file_name.obj file in the tc\bin directory.

To run the compiled code, the command is: Ctrl+F9. This produces file_name.exe which is an executable file and can execute independently.


Turbo C Compiler is available for download here: Download
1. Unzip the downloaded files
In Windows XP Turbo C Compiler can be used directly after unzipping the .zip file to a location you want.
But in Windows 7 and Windows 8 platform, you need an additional software called DOS Box to be installed in your system before you can use turbo C.
2. Download and install DosBox using the instructions from the following link: How to install DosBox on Windows 8 (x64 or x86)
3. Extract the zip to a simple drive ( In this example I used the F drive)
4. Rename the folder with the installer to “tc”
5. Start DosBox and type the following commands:
mount c: f:\
c:
cd tc
install
6. The installation process will begin. Hit enter.
7. When prompted for the source drive, select C instead of A
8. On the next prompt, select Start installation and leave the installation path to C:\TC
9. After the installation finishes, hit enter and you will return to the mounted C drive on DosBox
10. To start Turbo C++ type the following commands:
mount c: e:\
c:
cd tc
cd bin
tc