Sie sind auf Seite 1von 7

1.

#include<stdio.h>

int main()

int units, taka, value;

printf("Enter total units consumed: ");

scanf("%d",&units);

switch(units)

case 1 ... 200:

printf("Amount to be paid is : %d ",units*6);

break;

case 201 ... 400:

printf("Amount to be paid is : %d ",units*8);

break;

case 401 ... 600:

printf("Amount to be paid is : %d ",units*10);

break;

case 601 ... 100000:

printf("Amount to be paid is : %d ",units*12);

break;

}
}

2.

#include<stdio.h>

#include<stdlib.h>//random number

int main()

const int len = 10;

int marks[len];

for (int i = 0; i<len; i++)

marks[i] = rand()%1000;

printf("%d ",marks[i]);

printf("\n");

float max = marks[0];

for(int i = 0; i < len ; i++)

if (max<marks[i])

max = marks[i];

printf("Maximum number: %.2f\n",max);

float mim = marks[0];


for(int i = 0; i < len ; i++)

if (mim>marks[i])

mim = marks[i];

printf("Minimum number: %.2f\n",mim);

printf("The maximum difference is %.2f\n",max-mim);

3.

#include <stdio.h>

#include <string.h>

int main()

char arr[500];

printf("Enter sentence:");

gets(arr);

char sentences[200][200];

char min[100];

char max[100];

int a = 0, b = 0, c = 0, len;

for(; arr[c]!='\0'; c++)

{
if(arr[c] != ' ' && arr[c] != '\0')

sentences[a][b++] = arr[c];

else

sentences[a][b] = '\0';

a++;

b = 0;

len = a + 1;

strcpy(min, sentences[0]);

strcpy(min, sentences[0]);

for(c = 0; c < len; c++)

if(strlen(min) > strlen(sentences[c]))

strcpy(min, sentences[c]);

if(strlen(max) < strlen(sentences[c]))

strcpy(max, sentences[c]);

}
printf("Smallest word: %d\n", strlen(min));

printf("Largest word: %d", strlen(max));

4.

#include <stdio.h>

int main()

int h, q, m, k, y;

printf("Enter the date (DD MM YYYY)\n");

scanf("%d %d %d",&q,&m,&y);

if (m == 2)

m = 14;

y = y - 1;

if(m == 1)

m = 13;

y = y -1;

y = y / 100;

k = y % 100;

h = q + 26*(m+1)/10 + k + k/4 + 6*(y/100) + y/400;

h = h % 7;

switch(h)

case 0 :
printf("Saturday\n");

break;

case 1 :

printf("Sunday\n");

break;

case 2 :

printf("Monday\n");

break;

case 3 :

printf("Tuesday\n");

break;

case 4 :

printf("Wednesday\n");

break;

case 5 :

printf("Thursday\n");

break;

case 6 :

printf("Friday\n");

break;

5.

#include<stdio.h>

#include<stdlib.h>//random number

int main()

{ int len = 12;


int value[len];

for (int i = 0; i<len; i++)

value[i] = rand()%1000;

printf("%d \n",value[i]);

Peak(value[i]);

int Peak(int value)

int peaks[100];

int r=0;

for(int i = 1; i < 12; i++){

if(value[i] > value[i-1] && value[i] > value[i+1]){

peaks[r] = value[i];

r++;

printf("Peak numbers are ");

for(int i = 0; i<r; i++)

printf("%d ", peaks[i]);

Das könnte Ihnen auch gefallen