Saturday, May 7, 2022

Simple Write a program assignment in C language-03

Learning C programming language is mandatory for today’s students [as one programming language], during their academic career. The C language has many mechanisms to deal with decision making, repetitive tasks, such as if, if…else, for, while etc. Here are some of such C codes which may asked in theory/practical exams.

C is a typed language, so no need of code explanation as everything will be cleared by itself by reading the code. If you know C, you know this code. It’s that simple!

The Code::Blocks IDE 20.03+MinGW and Cygwin tool are used to test the code.

Code4a

Write A Program to ask user for base value and then display a factorial number using while loop

 

 

 

//WAP#4a:WAP to ask user for base value &

// then display a factorial number using

// while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num,counter, fact;//declare variables

    counter = 1;

    fact = 1;

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

    while (counter <= num)

    {

        fact = fact * counter;

        counter = counter + 1;

        printf("%d\t",fact);

    }

    printf("\n Factorial of %d is = %d\n",num,fact);

    return 0;

}

//end of program

 

//-------------------------

//output WAP#4a:

 

/*

Enter base value [integer]: 6

1       2       6       24      120     720

 Factorial of 6 is = 720

*/

 

 

 

 

 

Code4b

Write A Program to ask user for base value and then display a factorial number using do…while loop

 

 

 

//WAP#4b:WAP to ask user for base value &

// then display a factorial number using

// do...while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num,counter, fact;//declare variables

    counter = 1;

    fact = 1;

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

   do

    {

        fact = fact * counter;

        counter = counter + 1;

        printf("%d\t",fact);

    } while (counter <= num);

    printf("\n Factorial of %d is = %d\n",num,fact);

    return 0;

}

//end of program

//-------------------------

//output WAP#4b:

 

/*

Enter base value [integer]: 6

1       2       6       24      120     720

 Factorial of 6 is = 720

*/

 

 

 

 

 

Code4c

Write A Program to ask user for base value and then display a factorial number using for loop

 

 

 

 

//WAP#4c:WAP to ask user for base value &

// then display a factorial number using

// for loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num, fact;//declare variables

    fact = 1;

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

    for(int i=1; i<=num; i++)

    {

        fact = fact * i;

        printf("%d\t",fact);

    }

    printf("\n Factorial of %d is = %d\n",num,fact);

    return 0;

}

//end of program

 

//-------------------------

//output WAP#4c:

 

/*

Enter base value [integer]: 6

1       2       6       24      120     720

 Factorial of 6 is = 720

*/

 

 

 

 

 

Code5

Write A Program to display first five numbers with their cubes using do…while loop

 

 

 

//WAP#5:WAP to display first 5 numbers

//with their cubes using do...while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int i;//declare index

    i = 1;

 

    do

    {

        printf("%d\t %d \n",i, i*i*i);

        i = i + 1;

    }while (i <= 5);

 

    return 0;

}

//end of program

 

//---------------------------

//output WAP#5:

 

/*

1        1

2        8

3        27

4        64

5        125

*/

 

 

 

 

 

Code6

Write A Program to display first 10 odd numbers using do…while loop

 

 

 

//WAP#6:WAP to display first 10 odd numbers

//using do...while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int i;//declare index

    i = 1;

 

    do

    {

        if((i%2) != 0)

            printf("%d\n",i);

        i = i + 1;

    }

    while (i <= 20);

 

    return 0;

}

//end of program

*/

//output WAP#6:

 

/*

1

3

5

7

9

11

13

15

17

19

*/

 

 

 

 

 

For such codes click CCode label or check next day post on right-side post history bar.

---till next post, take care and bye-bye. 

Friday, May 6, 2022

Simple Write a program assignment in C language-02

Learning C programming language is mandatory for today’s students [as one programming language], during their academic career. The C language has many mechanisms to deal with decision making, repetitive tasks, such as if, if…else, for, while etc. Here are some of such C codes which may asked in theory/practical exams.

C is a typed language, so no need of code explanation as everything will be cleared by itself by reading the code. If you know C, you know this code. It’s that simple!

The Code::Blocks IDE 20.03+MinGW and Cygwin tool are used to test the code.

Code2a

Write A Program to display first five numbers and their sum using while loop

 

 

//WAP#2a:WAP to display first five numbers

// and their sum using while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

   int i, sum; //declare variables

   i = 1; sum =0; //initialize variables

 

   while (i <= 5)

    {

        printf("%d\n",i);

        sum = sum + i;

        i = i + 1;

    }

    printf("sum is :%d\n",sum);

 

    return 0;

}

//end of program

 

//-------------------------

//output WAP#2a:

 

/*

1

2

3

4

5

sum is :15

*/

 

 

 

 

 

Code3a

Write A Program to ask user to base value and then display a multiplication table using while loop

 

 

//WAP#3a:WAP to ask user for base value &

// then display a multiplication table using

// while loop

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

   int num,counter;//declare variables

   counter = 1;

 

   printf("Enter base value [integer]: ");

   scanf("%d",&num); //get base value

 

   while (counter <= 10)

    {

        printf("%d * %d = %d\n",

               num,counter, num*counter);

        counter = counter + 1;

    }

 

    return 0;

}

//end of program

 

//-----------------------

//output WAP#3a:

 

/*

Enter base value [integer]: 5

5 * 1 = 5

5 * 2 = 10

5 * 3 = 15

5 * 4 = 20

5 * 5 = 25

5 * 6 = 30

5 * 7 = 35

5 * 8 = 40

5 * 9 = 45

5 * 10 = 50

*/

 

 

 

 

 

Code3b

Write A Program to ask base value from user, and then display a multiplication table using for loop in Ascending order

 

 

 

//WAP#3b:WAP to ask user for base value &

// then display a multiplication table using

// for loop in Ascending order.

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num;//declare variable

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

    for (int i=1; i<=10; i++)

    {

        printf("%d * %d = %d\n",

               num,i, num*i);

    }

 

    return 0;

}

//end of program

 

//---------------------

//output WAP#3b:

 

/*

Enter base value [integer]: 6

6 * 1 = 6

6 * 2 = 12

6 * 3 = 18

6 * 4 = 24

6 * 5 = 30

6 * 6 = 36

6 * 7 = 42

6 * 8 = 48

6 * 9 = 54

6 * 10 = 60

 

*/

 

 

 

 

 

Code3c

Write A Program to ask base value from user, and then display a multiplication table using for loop in Descending order

 

 

 

//WAP#3c:WAP to ask user for base value &

// then display a multiplication table using

// for loop in descending order.

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num;//declare variable

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

    for (int i=10; i>=1; i--)

    {

        printf("%d * %d = %d\n",

               num,i, num*i);

    }

 

    return 0;

}

//end of program

*/

//output WAP#3c:

 

/*

Enter base value [integer]: 6

6 * 10 = 60

6 * 9 = 54

6 * 8 = 48

6 * 7 = 42

6 * 6 = 36

6 * 5 = 30

6 * 4 = 24

6 * 3 = 18

6 * 2 = 12

6 * 1 = 6

 

*/

 

 

 

 

 

Code3d

Write A Program to ask base value from user, and then display a multiplication table using do…while loop

 

 

 

//WAP#3d:WAP to ask user for base value &

// then display a multiplication table using

// do...while loop.

/*

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int num,i;//declare variable

    i=1;

 

    printf("Enter base value [integer]: ");

    scanf("%d",&num); //get base value

 

    do

    {

        printf("%d * %d = %d\n",

               num,i, num*i);

        i = i + 1;

    }while(i<=10);

 

    return 0;

}

//end of program

 

//--------------------------

//output WAP#3d:

 

/*

Enter base value [integer]: 6

6 * 1 = 6

6 * 2 = 12

6 * 3 = 18

6 * 4 = 24

6 * 5 = 30

6 * 6 = 36

6 * 7 = 42

6 * 8 = 48

6 * 9 = 54

6 * 10 = 60

 

*/

 

 

 

 

 

For such codes click CCode label or check next day post on right-side post history bar.

---till next post, take care and bye-bye.