0% found this document useful (0 votes)
5 views

Programming C

The document contains two C programming assignments submitted by Geo Shaju. The first program counts the occurrence of a specific digit in a given number, while the second program generates and prints a pattern of numbers in decreasing order based on user input. Both programs utilize standard input and output functions in C.

Uploaded by

jio407036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Programming C

The document contains two C programming assignments submitted by Geo Shaju. The first program counts the occurrence of a specific digit in a given number, while the second program generates and prints a pattern of numbers in decreasing order based on user input. Both programs utilize standard input and output functions in C.

Uploaded by

jio407036
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAMMING C

ASSIGNMENT

Submitted by
Geo Shaju
S5B.ComC.A
Roll No:1211
1) Write
a C program to count the occurrence of a
particular DIGIT in a number

#include <stdio.h>

int main() {
int number, digit, count = 0;

// Input the number and the digit to


count
printf("Enter a number: ");
scanf("%d", &number);
printf("Enter the digit to count: ");
scanf("%d", &digit);

// Loop through the digits of the number


while (number != 0) {
if (number % 10 == digit) { // Check if
last digit matches
count++;
}
number /= 10; // Remove the last digit
}

// Output the result


printf("The digit %d occurred %d times.\
n", digit, count);
return 0;
}

2) Write a C program to generate and print


a pattern of numbers using nested for
loops. The program should
take an integer n as input and use for loops
to print the following pattern:For n = 4:

21

321

4321

The pattern should have n rows, and each


row contains numbers in decreasing order,
starting from the row

number.
#include <stdio.h>

int main() {
int n;

// Input the value of n


printf("Enter the number of rows (n): ");
scanf("%d", &n);

// Nested loops to print the pattern


for (int i = 1; i <= n; i++) { // Outer loop
for each row
for (int j = i; j >= 1; j--) { // Inner loop
for numbers in each row, decreasing from i
to 1
printf("%d", j);
}
printf("\n"); // Move to the next line
after printing each row
}

return 0;
}

You might also like