0% found this document useful (0 votes)
37 views5 pages

1.patterns 1 1 2 123 1234 12345

The document contains code snippets for 4 different C programs: 1) A program that prints patterns of increasing numbers in loops 2) A program that checks if a number is a Harshad number 3) A program that checks if a number is an Exuberant number 4) A program that finds the first non-repeating character in a string

Uploaded by

veronica
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)
37 views5 pages

1.patterns 1 1 2 123 1234 12345

The document contains code snippets for 4 different C programs: 1) A program that prints patterns of increasing numbers in loops 2) A program that checks if a number is a Harshad number 3) A program that checks if a number is an Exuberant number 4) A program that finds the first non-repeating character in a string

Uploaded by

veronica
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/ 5

1.

PATTERNS

12

123

1234

12345

#include<stdio.h>

int main()

int i, j,n;

scanf("%d",&n);

for(i = 1; i <= n; i++)

for(j = 1; j <= i; j++)

printf("%d ",j);

printf("\n");

return 0;

2.HARSHAD NUMBER
#include<stdio.h>

int main()

//fill the code

int num;

int temp;

scanf("%d",&num);

int sum = 0;

temp = num;

while(temp)

sum += temp % 10;

temp = temp / 10;

int res = num % sum;

if(res == 0)

printf("HARSHAD NUMBER");

else

printf("NOT HARSHAD NUMBER");

return 0;

3.EXUBERANT NUMBER
#include<stdio.h>

int main()

//fill the code

int num;

int temp;

scanf("%d",&num);

int sum = 0;

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

if(num % i == 0)

sum = sum + i;

if(num < sum)

printf("Exuberant Number");

else

printf("Not Exuberant Number");

return 0;

4.premium unique character

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

#define NO_OF_CHARS 256

int *get_char_count(char *str)

int *count = (int *)calloc(sizeof(int), NO_OF_CHARS);

int i;

for (i = 0; *(str+i); i++)

count[*(str+i)]++;

return count;

int first_non_repeating_character(char *str)

int *count = get_char_count(str);

int index = -1, i;

for (i = 0; *(str+i); i++)

if (count[*(str+i)] == 1)

index = i;

break;

}
free(count);

return index;

int main()

char str[NO_OF_CHARS];

scanf("%s",&str);

int index = first_non_repeating_character(str);

if (index == -1)

printf("All characters are repetitive");

else

printf("%c", str[index]);

getchar();

return 0;

You might also like