Exforsys
+ Reply to Thread
Results 1 to 3 of 3

C programming

This is a discussion on C programming within the C and C++ forums, part of the Programming Talk category; Hello. I need some help, please. Thank you. 1. To mirror the numbers in a two-dimensional array. For instance for ...

  1. #1
    automat is offline Junior Member Array
    Join Date
    Oct 2011
    Answers
    1

    C programming

    Hello.
    I need some help, please.
    Thank you.

    1. To mirror the numbers in a two-dimensional array. For instance for a number, if the number is : 2345, and the number in mirror is 5432.

    #include<stdio.h>
    #include<math.h>
    #define matrix [20][20]
    #define matrix1 [20][20]
    void main()
    {
    int number_lines, number_columns, i, j, ogl, nr;
    printf("\n Give the number of lines : ");
    scanf("%ld", &number_lines);
    printf("\n Give the number of columns : ");
    scanf("%ld", &number_columns);
    printf("\n Give the elements of matrix : ");
    printf("\n");
    for(i=1; i<=number_lines; i++) {
    for(j=1; j<=number_columns; j++) {
    printf("\n Matrix [%d][%d] = ", i, j);
    scanf("%d", &nr);
    matrix1[i][j] = matrix[i][j];
    }
    }
    for(i=1; i<=number_lines; i++) {
    for(j=1; j<=number_columns; j++) {
    ogl = 0;
    while(matrix[i][j] != 0)
    {
    ogl = ogl * 10 + matrix[i][j] % 10;
    matrix[i][j] = matrix[i][j] / 10;
    }
    printf("\n The mirror of matrix[%d][%d] --> %d is %d\n", i, j, matrix1[i][j], ogl);
    }
    }
    }


    2. To carry out a program to display prime numbers from a given range.

    #include<stdio.h>
    void main()
    {
    int a, b, prime, d, i;
    printf("\n Give a = ");
    scanf("%d", &a);
    printf("\n Give b = ");
    scanf("%d", &b);
    if(b<=a)
    printf("\n b must be greather than a.\n");
    prime=1; d=2;
    for(i=a; i<=b; i++)
    {
    while(d<=i/2 && prime)
    {
    if(i%d==0)
    prime=0;
    d++;
    }
    if(prime)
    printf(" %d", i);
    else
    printf("\n No prime in the interval [%d %d].\n", a, b);
    }
    }


  2. #2
    ram31 is offline Junior Member Array
    Join Date
    Nov 2011
    Answers
    1

    Smile simple mirror logic

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    int loop;
    char string[100]="";
    printf("\n Enter the string to mirror:");
    scanf("%[^\n]s",&string);
    loop=strlen(string);
    for(;
    {
    printf("%c", string[loop-1]);
    loop--;
    if(loop==0)
    break;
    }

    }


  3. #3
    venkatjaya is offline Junior Member Array
    Join Date
    Jan 2012
    Answers
    8

    Cool

    The notes on these pages are for the courses in C Programming I used to teach in the Experimental College at the University of Washington in Seattle, WA. Normally these notes accompany fairly traditional classroom lecture presentations, but they are intended to be reasonably complete (more so, for that matter, than the lectures!) and should be usable as standalone tutorials.

    I originally designed the first, Introductory course around The C Programming Language (2nd Edition) by Kernighan and Ritchie, and the notes were designed to complement that text, highlighting important points and explaining subtleties which might be lost on the general reader. Later, I rewrote the notes to stand on their own (in part because, in spite of the first set of notes, too many of my students found K&R a bit too technical for an informal, introductory course). Finally, I occasionally teach an Intermediate course, which covers the topics which tend to be skipped or glossed over in introductory courses (bitwise operators, structures, file I/O, etc.). The Intermediate course has its own set of notes.

    All three sets of notes are available here. If you have a copy of K&R2 and would like a thorough treatment of the language, read K&R and the "Notes to Accompany K&R'' side by side. If you're just getting your feet wet and would like a somewhat simpler introduction, read the "Introductory Class Notes.'' If you have had an introduction to C (either here or elsewhere) and are now looking to fill in some of the missing pieces, read the "Intermediate Class Notes.''

    Of course, just reading a book or these notes won't really teach you C; you will also want to write and run your own programs, for practice and so that the language concepts will make some kind of practical sense. Most of my programming assignments (including review questions) are here as well, along with their solution sets. (No peeking at the answers until you've given the problems your best shot!)

    These notes are arranged for the web in the usual hierarchy by section and subsection. If you want to read through all of them, without keeping track of your own stack to implement a depth-first tree traversal, just follow the "read sequentially'' links at the bottom of each page.

    Depending on your background, you might want to read one or both of the two preliminary handouts: one on programming in general, and one which reviews some math which is relevant to programming. (And there are some other miscellaneous handouts, too.)


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...