0% found this document useful (0 votes)
29 views4 pages

11 1

The document contains a series of C programs that demonstrate various programming concepts. These include counting uppercase and lowercase letters, checking for Armstrong numbers, converting binary to decimal, calculating average marks, determining even or odd numbers, swapping values, and printing patterns such as triangles and pyramids. Each program includes user input and outputs the results based on the logic implemented.

Uploaded by

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

11 1

The document contains a series of C programs that demonstrate various programming concepts. These include counting uppercase and lowercase letters, checking for Armstrong numbers, converting binary to decimal, calculating average marks, determining even or odd numbers, swapping values, and printing patterns such as triangles and pyramids. Each program includes user input and outputs the results based on the logic implemented.

Uploaded by

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

1)COUNTING

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int upper=0,lower=0;
char ch[100];
printf("Enter the String:\n");
gets(ch);
for(i=0; ch[i]!=0; i++){
if(ch[i]>='A' && ch[i]<='Z'){
upper++;
}
else if(ch[i]>='a' && ch[i]<='z'){
lower++;
}
}
printf("lowercase letters: %d",lower);
printf("\nuppercase letters: %d",upper);
getch();
return 0;
}

2)ARMSTRONG
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
return 0;
}

3)BINARY TO DECIMAL
#include <stdio.h>
#include <conio.h>
void main()
{
// declaration of variables
int num, binary_num, decimal_num = 0, base = 1, rem;
printf (" Enter a binary number with the combination of 0s and 1s \n");
scanf (" %d", &num);

binary_num = num;
while ( num > 0)
{
rem = num % 10;
decimal_num = decimal_num + rem * base;
num = num / 10;
base = base * 2;
}

printf ( " The binary number is %d \t", binary_num);


printf (" \n The decimal number is %d \t", decimal_num);
getch();
}

4)AVERAGE MARKS
#include <stdio.h>
#include <stdlib.h>
int main()
{
int m1,m2,m3;
float avg;
printf("Enter marks for 3 subjects\n");
scanf("%d%d%d",&m1,&m2,&m3);
if(((m1>=0)&&(m1<=100))&&(((m2>=0)&&(m2<=100)))&&((m3>=0)&&(m3<=100)))
{
avg=(m1+m2+m3)/3.0;
printf("Average marks of %d, %d and %d is %0.2f",m1,m2,m3,avg);
}
else
{
printf("Marks must be in between 0 and 100");
}

return 0;
}

5)EVEN OR ODD
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

// true if num is perfectly divisible by 2


if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);

return 0;
}

6)SWAPING
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);

// true if num is perfectly divisible by 2


if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);

return 0;
}

7)Pattern
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
O/P:-
*
* *
* * *
* * * *
* * * * *
8)REVERSE PATTERN
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
9)PYRAMID
#include <stdio.h>
int main() {
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy