Write A Program in C To Check Whether A Entered Number Is Positive, Negative or Zero
Write A Program in C To Check Whether A Entered Number Is Positive, Negative or Zero
#include <stdio.h>
int main(){
int num;
scanf("%d", &num);
if (num >= 0)
else
return 0;
}
2. Write a program in C to add two matrixes of size 3x3.
#include<stdio.h>
int main()
int matA[3][3],matB[3][3],matC[3][3];
int r,c,k;
scanf("%d", &matA[r][c]);
//printing matA
printf(" %d",matA[r][c]);
printf("\n");
//getting matB
scanf("%d", &matB[r][c]);
}
}
//printing matB
printf(" %d",matB[r][c]);
printf("\n");
//adding matA+matB
matC[r][c]=0;
for(k=0; k<3;k++)
printf(" %d",matC[r][c]);
printf("\n");
return 0;
}
3. Write a program to enter a number and check its length.
#include <stdio.h>
int main() {
long long n;
int count = 0;
scanf("%lld", &n);
while (n != 0) {
n /= 10; // n = n/10
++count;
return 0;
}
4. Write a program to take a string and check the number of vowels, consonants, digits and space in
it.
#include <stdio.h>
int main() {
char line[150];
line[i] == 'U') {
++vowels;
} else if ((line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z')) {
++consonant;
++digit;
++space;
return 0;
}
5. Write a program to enter multiple number of strings as the user wishes and arrange them in
dictionary order.
#include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
scanf("%d",&count);
for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
for(i=0;i<=count;i++)
puts(str[i]);
return 0;